Skip to content

Commit be795ff

Browse files
authored
ci: document releases and group release notes by label (#6178)
Signed-off-by: mday-io <mdaytn@gmail.com>
1 parent ce229ae commit be795ff

5 files changed

Lines changed: 332 additions & 0 deletions

File tree

‎.github/RELEASING.md‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Releasing SQLMesh
2+
3+
This guide is for maintainers with write access to `SQLMesh/sqlmesh`. It covers the three things the project publishes:
4+
5+
| Package | Registry | How a release starts |
6+
|---|---|---|
7+
| `sqlmesh` (Python) | PyPI | Push a `v*.*.*` tag |
8+
| SQLMesh VS Code extension | VS Code Marketplace and Open VSX | Run the **Release VSCode Extension** workflow |
9+
| `@tobikodata/sqlmesh-common` | npm | Run the **Release web common code** workflow |
10+
11+
## Release the Python Package
12+
13+
The [`Release`](workflows/release.yaml) workflow runs when a tag that matches `v*.*.*` is pushed. The package version comes from the tag through `setuptools_scm`, so you don't edit a version number in the code.
14+
15+
The workflow does four things:
16+
17+
1. Builds the web UI and bundles it into the package.
18+
2. Publishes `sqlmesh` to PyPI with `make publish`.
19+
3. Publishes the test package to the private `tobiko-private` registry with `make publish-tests`.
20+
4. Creates a GitHub release with notes generated from the pull requests merged since the previous tag.
21+
22+
Each step publishes immediately and there's no approval gate. Check `main` before you tag.
23+
24+
### Steps
25+
26+
1. Pick the commit to release. It must be on `main`, and every required check must pass on it. Check the latest **pr.yaml** run for that commit on the [Actions page](https://github.com/SQLMesh/sqlmesh/actions/workflows/pr.yaml).
27+
2. Pick the version. Fetch the tags, then find the highest released version and increment it:
28+
29+
```bash
30+
git fetch <sqlmesh-remote> main --tags
31+
git tag --list 'v[0-9]*' --sort=-v:refname | head -1
32+
```
33+
34+
Replace `<sqlmesh-remote>` with your remote for `SQLMesh/sqlmesh`.
35+
36+
3. Tag the commit and push the tag. Set `VERSION` to the version from step 2, for example `v0.236.5`:
37+
38+
```bash
39+
VERSION=v0.236.5
40+
git tag "$VERSION" <commit-sha>
41+
git push <sqlmesh-remote> "$VERSION"
42+
```
43+
44+
Push only the tag, not a branch.
45+
46+
4. Watch the [Release](https://github.com/SQLMesh/sqlmesh/actions/workflows/release.yaml) run until it finishes.
47+
5. Check that the new version is on [PyPI](https://pypi.org/project/sqlmesh/#history).
48+
6. Edit the generated release on the [Releases page](https://github.com/SQLMesh/sqlmesh/releases). Under **Breaking changes**, add a short upgrade note for each entry. Say what users will see after upgrading, such as a migration or a metadata-only change in `sqlmesh plan`.
49+
50+
If the workflow fails after the PyPI step, don't delete or reuse the tag. PyPI doesn't accept the same version twice. Fix the cause and release the next version.
51+
52+
### Release Notes
53+
54+
GitHub builds the notes from merged pull request titles and groups them by label, as configured in [`.github/release.yml`](release.yml). The [PR Labels](workflows/pr-labels.yaml) workflow applies the labels from each pull request's title (`type(scope): description`), and adds `migration` to pull requests that add a state migration. See [Pull Request Titles](../CONTRIBUTING.md#pull-request-titles) in `CONTRIBUTING.md`.
55+
56+
- A `!` in the title, such as `fix!:` or `feat!:`, puts the pull request under **Breaking changes**.
57+
- A pull request that adds a state migration goes under **State migrations**.
58+
- CI, test and Dependabot pull requests are left out. Add the `skip-changelog` label to leave out any other pull request.
59+
60+
Each pull request appears in only one section: the first one in this list that matches its labels. A breaking change that also adds a state migration is listed under **Breaking changes**, so its upgrade note in step 6 should say to run `sqlmesh migrate`.
61+
62+
To move a pull request to another section, change its title. The workflow resets the type labels from the title.
63+
64+
## Release the VS Code Extension
65+
66+
The [Release VSCode Extension](workflows/release_extension.yaml) workflow publishes to the VS Code Marketplace and to Open VSX.
67+
68+
1. On the workflow's page, choose **Run workflow**.
69+
2. Select the `main` branch. The workflow stops if you run it from any other branch.
70+
3. Enter the version without a `v`, for example `0.0.8`.
71+
72+
The workflow sets the version only in its own build. It doesn't commit it, so `vscode/extension/package.json` keeps its old version. Check the [Marketplace listing](https://marketplace.visualstudio.com/items?itemName=tobikodata.sqlmesh) for the latest published version and enter a higher one.
73+
74+
## Release the Shared Web Package
75+
76+
The [Release web common code](workflows/release_shared_js.yaml) workflow publishes `@tobikodata/sqlmesh-common` from `web/common` to npm. Run it the same way as the extension workflow: from `main`, with a version that has no `v`. It also doesn't commit the version, so check [npm](https://www.npmjs.com/package/@tobikodata/sqlmesh-common) for the latest published version first.

‎.github/dependabot.yml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ updates:
44
directory: '/'
55
schedule:
66
interval: 'weekly'
7+
commit-message:
8+
prefix: 'chore'
9+
include: 'scope'
710
groups:
811
# Storybook add-ons declare a peer dependency on the matching `storybook`
912
# release, so they have to move together. Bump them in a single PR.
@@ -32,10 +35,16 @@ updates:
3235
directory: '/'
3336
schedule:
3437
interval: 'weekly'
38+
commit-message:
39+
prefix: 'chore'
40+
include: 'scope'
3541
- package-ecosystem: 'pip'
3642
directory: '/docs'
3743
schedule:
3844
interval: 'weekly'
45+
commit-message:
46+
prefix: 'chore'
47+
include: 'scope'
3948
groups:
4049
# The docs toolchain (MkDocs, its theme and plugins, pdoc, Pygments) is
4150
# built and verified as a whole, so bump it in a single PR.

‎.github/release.yml‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Groups the notes that GitHub generates for each release (see
2+
# `generate_release_notes` in workflows/release.yaml) by PR label.
3+
# Labels are applied automatically by workflows/pr-labels.yaml. `Feature`, `Bug`
4+
# and `Documentation` are the repo's existing labels, so keep their capitalization.
5+
# A PR is listed under the first category whose labels it matches.
6+
# .github/RELEASING.md refers to these section titles, so keep the two in sync.
7+
changelog:
8+
exclude:
9+
labels:
10+
- skip-changelog
11+
- ci
12+
- test
13+
- dependencies
14+
categories:
15+
- title: Breaking changes
16+
labels:
17+
- breaking-change
18+
- title: State migrations (run `sqlmesh migrate` after upgrading)
19+
labels:
20+
- migration
21+
- title: Features
22+
labels:
23+
- Feature
24+
- title: Performance
25+
labels:
26+
- performance
27+
- title: Bug fixes
28+
labels:
29+
- Bug
30+
- title: Documentation
31+
labels:
32+
- Documentation
33+
- title: Maintenance
34+
labels:
35+
- maintenance
36+
- title: Other changes
37+
labels:
38+
- "*"

‎.github/workflows/pr-labels.yaml‎

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
name: PR Labels
2+
# Checks the PR title format and applies the labels that .github/release.yml
3+
# uses to group release notes.
4+
#
5+
# pull_request_target is used so that labels can be applied to PRs from forks.
6+
# This workflow never checks out or runs code from the PR.
7+
on:
8+
pull_request_target:
9+
types: [opened, edited, reopened, synchronize]
10+
11+
permissions:
12+
contents: read
13+
issues: write
14+
pull-requests: write
15+
16+
concurrency:
17+
group: pr-labels-${{ github.event.pull_request.number }}
18+
# Queue rather than cancel, so a run is never stopped part-way through
19+
# changing labels.
20+
cancel-in-progress: false
21+
22+
jobs:
23+
title:
24+
name: Check title and label by type
25+
# Runs on pushes too: GitHub keeps only one pending run per concurrency
26+
# group, so a push can replace a queued run for a title edit.
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/github-script@v8
30+
with:
31+
script: |
32+
const issue_number = context.payload.pull_request.number;
33+
const { owner, repo } = context.repo;
34+
// Read the current title. The event payload keeps the title from when the
35+
// run started, so a re-run of an old run would otherwise apply old labels.
36+
const { data: pr } = await github.rest.pulls.get({ owner, repo, pull_number: issue_number });
37+
const title = pr.title;
38+
39+
// Creates the label if it doesn't exist. A 422 means another run created
40+
// it first, which is fine.
41+
async function ensureLabel(name, color) {
42+
try {
43+
await github.rest.issues.getLabel({ owner, repo, name });
44+
} catch (e) {
45+
if (e.status !== 404) throw e;
46+
try {
47+
await github.rest.issues.createLabel({ owner, repo, name, color });
48+
} catch (e2) {
49+
if (e2.status !== 422) throw e2;
50+
}
51+
}
52+
}
53+
54+
const typeLabels = new Map([
55+
['feat', 'Feature'],
56+
['fix', 'Bug'],
57+
['perf', 'performance'],
58+
['docs', 'Documentation'],
59+
['refactor', 'maintenance'],
60+
['chore', 'maintenance'],
61+
['build', 'maintenance'],
62+
['revert', null],
63+
['ci', 'ci'],
64+
['test', 'test'],
65+
]);
66+
// Scopes for internal-only work, which release notes leave out
67+
// (e.g. "fix(ci): ..." is labelled ci, not bug).
68+
const scopeLabels = new Map([['ci', 'ci'], ['test', 'test'], ['tests', 'test']]);
69+
// Labels this job owns. The title is the source of truth for them:
70+
// any that don't match the current title are removed. Feature, Bug and
71+
// Documentation are the repo's existing labels. GitHub label names are
72+
// case-insensitive, so labels are compared in lowercase.
73+
const colors = new Map([
74+
['breaking-change', 'b60205'],
75+
['Feature', '0e8a16'],
76+
['Bug', 'd73a4a'],
77+
['performance', 'fbca04'],
78+
['Documentation', '0075ca'],
79+
['maintenance', 'c5def5'],
80+
['ci', 'ededed'],
81+
['test', 'ededed'],
82+
]);
83+
84+
const owned = new Set([...colors.keys()].map((n) => n.toLowerCase()));
85+
86+
let wanted;
87+
if (/^Revert "/.test(title)) {
88+
// Title generated by GitHub's "Revert" button.
89+
wanted = new Set();
90+
} else {
91+
// The type is matched in any case, so "Fix: ..." is labelled like "fix: ...".
92+
const m = /^([A-Za-z]+)(?:\(([^)]+)\))?(!)?: \S/.exec(title);
93+
if (!m || !typeLabels.has(m[1].toLowerCase())) {
94+
core.setFailed(
95+
`PR title "${title}" must look like "type(scope): description" or ` +
96+
`"type: description", where type is one of: ` +
97+
`${[...typeLabels.keys()].join(', ')}. Add "!" after the type or scope ` +
98+
`for a breaking change, e.g. "feat(plan)!: ...". See CONTRIBUTING.md.`
99+
);
100+
return;
101+
}
102+
const [, rawType, scope, bang] = m;
103+
const type = rawType.toLowerCase();
104+
wanted = new Set();
105+
if (bang) {
106+
// Breaking changes always appear in the release notes, so they
107+
// never get the ci/test labels that exclude a PR.
108+
wanted.add('breaking-change');
109+
const label = typeLabels.get(type);
110+
if (label && label !== 'ci' && label !== 'test') wanted.add(label);
111+
} else {
112+
const label = (scope && scopeLabels.get(scope.toLowerCase())) || typeLabels.get(type);
113+
if (label) wanted.add(label);
114+
}
115+
}
116+
117+
const { data: live } = await github.rest.issues.listLabelsOnIssue({
118+
owner, repo, issue_number, per_page: 100,
119+
});
120+
const current = live.map((l) => l.name);
121+
const currentLower = current.map((n) => n.toLowerCase());
122+
const wantedLower = new Set([...wanted].map((n) => n.toLowerCase()));
123+
124+
for (const name of current) {
125+
const lower = name.toLowerCase();
126+
if (!owned.has(lower) || wantedLower.has(lower)) continue;
127+
try {
128+
await github.rest.issues.removeLabel({ owner, repo, issue_number, name });
129+
} catch (e) {
130+
if (e.status !== 404) throw e;
131+
}
132+
}
133+
134+
const toAdd = [...wanted].filter((name) => !currentLower.includes(name.toLowerCase()));
135+
for (const name of toAdd) {
136+
await ensureLabel(name, colors.get(name));
137+
}
138+
if (toAdd.length) {
139+
await github.rest.issues.addLabels({ owner, repo, issue_number, labels: toAdd });
140+
}
141+
142+
migrations:
143+
name: Label new state migrations
144+
runs-on: ubuntu-latest
145+
steps:
146+
- uses: actions/github-script@v8
147+
with:
148+
script: |
149+
const issue_number = context.payload.pull_request.number;
150+
const { owner, repo } = context.repo;
151+
const files = await github.paginate(github.rest.pulls.listFiles, {
152+
owner, repo, pull_number: issue_number, per_page: 100,
153+
});
154+
const added = files.some(
155+
(f) => f.status === 'added' && /^sqlmesh\/migrations\/v\d+_.*\.py$/.test(f.filename)
156+
);
157+
// Read live labels: a queued run's event payload can be out of date.
158+
const { data: live } = await github.rest.issues.listLabelsOnIssue({
159+
owner, repo, issue_number, per_page: 100,
160+
});
161+
const labels = live.map((l) => l.name);
162+
if (!added) {
163+
// The PR no longer adds a migration, e.g. the file was removed.
164+
if (labels.includes('migration')) {
165+
try {
166+
await github.rest.issues.removeLabel({ owner, repo, issue_number, name: 'migration' });
167+
} catch (e) {
168+
if (e.status !== 404) throw e;
169+
}
170+
}
171+
return;
172+
}
173+
if (labels.includes('migration')) return;
174+
try {
175+
await github.rest.issues.getLabel({ owner, repo, name: 'migration' });
176+
} catch (e) {
177+
if (e.status !== 404) throw e;
178+
try {
179+
await github.rest.issues.createLabel({ owner, repo, name: 'migration', color: '5319e7' });
180+
} catch (e2) {
181+
// Another run created it first.
182+
if (e2.status !== 422) throw e2;
183+
}
184+
}
185+
await github.rest.issues.addLabels({ owner, repo, issue_number, labels: ['migration'] });

‎CONTRIBUTING.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,30 @@ Optionally, `make install-pre-commit` installs git hooks so ruff and mypy run on
8787
- Include a DCO sign-off on all commits (`git commit -s`)
8888
- Be responsive to review feedback from maintainers
8989

90+
### Pull Request Titles
91+
92+
Pull requests are squash-merged, so the title becomes the commit message and the
93+
entry in the release notes. Titles must follow this format, which CI checks:
94+
95+
```
96+
type(scope): description
97+
```
98+
99+
- `type` is one of `feat`, `fix`, `perf`, `docs`, `refactor`, `chore`, `build`, `revert`, `ci` or `test`. Lowercase is preferred, but `Fix:` is treated like `fix:`.
100+
- `scope` is optional and names the area changed, e.g. `snowflake`, `plan`, `dbt` or `vscode`.
101+
- Add `!` after the type or scope for a breaking change, e.g. `feat(plan)!: drop support for X`.
102+
- Write the description for users: say what changed for them, not how the code changed.
103+
104+
Titles created by GitHub's "Revert" button (`Revert "..."`) are also accepted. If the
105+
title check fails, edit the title. Editing it runs the check again.
106+
107+
Release notes are grouped using labels that are applied automatically from the title
108+
and the files changed. The title decides the `Feature`, `Bug`, `performance`,
109+
`Documentation`, `maintenance`, `ci`, `test` and `breaking-change` labels, so to
110+
recategorize a PR, change its title rather than its labels. Use `ci` or `test` as the type
111+
or scope for internal-only changes (e.g. `fix(ci): ...`) so they are left out of the
112+
release notes. A maintainer can add the `skip-changelog` label to leave out any other PR.
113+
90114
## Licensing
91115

92116
Code contributions are licensed under the [Apache License 2.0](LICENSE). Documentation contributions are licensed under [Creative Commons Attribution 4.0 International (CC-BY-4.0)](https://creativecommons.org/licenses/by/4.0/). See the LICENSE file and the [technical charter](sqlmesh-technical-charter.pdf) for details.

0 commit comments

Comments
 (0)