From 45eec7f441c0d73a2a3276c2b9e5bd31a93e148b Mon Sep 17 00:00:00 2001 From: Valentin Millet Date: Wed, 25 Nov 2026 16:01:38 +0100 Subject: [PATCH] Release workflow: a dry run shows what changes and builds nothing --- .claude/skills/release-packaging/SKILL.md | 2 +- .github/workflows/release.yml | 32 +++++-- .github/workflows/website.yml | 7 +- docs/architecture.md | 3 +- docs/releasing.md | 15 ++-- package.json | 2 +- scripts/release-preview.mjs | 103 ++++++++++++++++++++++ scripts/release-preview.test.mjs | 65 ++++++++++++++ 8 files changed, 212 insertions(+), 17 deletions(-) create mode 100644 scripts/release-preview.mjs create mode 100644 scripts/release-preview.test.mjs diff --git a/.claude/skills/release-packaging/SKILL.md b/.claude/skills/release-packaging/SKILL.md index e9af3f67..705ca847 100644 --- a/.claude/skills/release-packaging/SKILL.md +++ b/.claude/skills/release-packaging/SKILL.md @@ -7,7 +7,7 @@ description: Use when building the desktop executable/installer, preparing a ver - Local build: `cargo build -p app --release` → `target/release/devnotes`. Packages: `cargo install --locked cargo-packager@0.11.8 cargo-generate-rpm@0.21.1`, then `cargo packager -p app --release -f nsis` (Windows) or `-f deb,appimage` and `cargo generate-rpm -p crates/app` (Linux); it builds nothing. Configuration: `[package.metadata.packager]` and `[package.metadata.generate-rpm]` in `crates/app/Cargo.toml`; the CI steps are `.github/actions/package`. - Signatures: minisign, by `cargo-packager` with `CARGO_PACKAGER_SIGN_PRIVATE_KEY[_PASSWORD]` (the release secrets `TAURI_SIGNING_PRIVATE_KEY[_PASSWORD]`, the same key since before 1.0.0, D26). The updater installs the NSIS installer and the AppImage only; `latest.json` is `scripts/latest-json.mjs`, each platform with its `format`. `packages.yml` proves install and update 1.0.0 → 1.0.1 on both OSes, an altered package refused, with a key made for the run. -- Release is a `workflow_dispatch` (`.github/workflows/release.yml`), steps in `docs/releasing.md`: bump `[workspace.package] version` in the root `Cargo.toml` and `Cargo.lock` (`cargo update --workspace`) — the only two files that carry it, checked by `scripts/version.mjs` — merge to `main`, CI green, Actions → Release with `dry_run`, read the notes, run again. +- Release is a `workflow_dispatch` (`.github/workflows/release.yml`), steps in `docs/releasing.md`: bump `[workspace.package] version` in the root `Cargo.toml` and `Cargo.lock` (`cargo update --workspace`) — the only two files that carry it, checked by `scripts/version.mjs` — merge to `main`, CI green, Actions → Release with `dry_run` (a minute: it shows what would change and builds nothing), read the summary, run again. - Release notes come from PR labels; PR bodies need `Closes #N`. The newest `CHANGELOG.md` section is generated; do not hand-edit it. - A version on its own branch (`dev/x.y.z`): PRs are squashed into it, `main` is merged into it to catch up, and it reaches `main` by a merge commit (`git merge --no-ff`), never a squash — the notes read what that merge brings. From the branch, `node scripts/release-notes.mjs generate --version x.y.z` prints what the version holds so far and writes nothing. - Never commit signing keys (`*.key`, `*.pfx`, `.tauri/` are ignored). Never trigger a release, tag or push unless the user asks. diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 67c5a6ba..bf7d3793 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,5 +1,8 @@ name: Release +# `website.yml` reads it: a dry run published nothing the site could name. +run-name: ${{ inputs.dry_run && 'Release (dry run)' || 'Release' }} + # One button. The version is already in the root Cargo.toml — a human bumps it, and this # workflow draws a changelog section, a commit, a tag, the bundles and the release from it. # @@ -12,7 +15,7 @@ on: workflow_dispatch: inputs: dry_run: - description: 'Run everything except the commit, the tag and the publication.' + description: 'Show what the release would change, and stop there: nothing is built.' type: boolean default: false @@ -135,6 +138,17 @@ jobs: exit 1 fi + # Nothing tries the key before the tag: without it the packages are built unsigned, and + # `publish` refuses them once the tag is out. Only whether it is set is read here. + - name: The signing key must be set + env: + KEY_SET: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY != '' }} + run: | + if [ "$KEY_SET" != true ]; then + echo "::error::the secret TAURI_SIGNING_PRIVATE_KEY is not set: no package could be signed" + exit 1 + fi + # For Prettier, which reformats the written file: an unformatted CHANGELOG.md would # break `npm run lint` on somebody else's next push. - run: npm ci @@ -182,16 +196,22 @@ jobs: git push --atomic origin HEAD:main "refs/tags/$TAG" echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" - - name: Preview only + - name: Show what the release would change if: ${{ inputs.dry_run }} - run: echo "::notice::dry run — nothing was committed, tagged or published" + env: + GH_TOKEN: ${{ github.token }} + VERSION: ${{ steps.version.outputs.version }} + run: | + node scripts/release-preview.mjs --version "$VERSION" --repo "$GITHUB_REPOSITORY" \ + --prompt "$RUNNER_TEMP/prompt-notes.md" >> "$GITHUB_STEP_SUMMARY" + echo "::notice::dry run — nothing was committed, tagged, built or published" - # In a dry run too: the packages and their signatures by the real key are what a dry run - # proves, without publishing them. Its binary carries the changelog as it was, without the - # section `prepare` did not commit. + # Not in a dry run: the packages, their signatures and an update are what `packages.yml` proves, + # on the pull requests that touch them. release-build: name: Package ${{ matrix.target }} needs: prepare + if: ${{ !inputs.dry_run }} environment: release runs-on: ${{ matrix.os }} timeout-minutes: 60 diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml index 0ea63b73..6d97f99c 100644 --- a/.github/workflows/website.yml +++ b/.github/workflows/website.yml @@ -37,8 +37,11 @@ permissions: jobs: publish: name: Build and publish - # A release that failed published no file the site could name. - if: github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' + # A release that failed, or was only a dry run, published no file the site could name. + if: >- + github.event_name != 'workflow_run' || + (github.event.workflow_run.conclusion == 'success' && + github.event.workflow_run.display_title != 'Release (dry run)') runs-on: ubuntu-22.04 timeout-minutes: 20 steps: diff --git a/docs/architecture.md b/docs/architecture.md index 80436114..fa3455c2 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -6224,7 +6224,8 @@ key can produce an installable update. It is the key the Tauri releases were sig ## Releasing -One button: **Actions → Release → Run workflow**, with a `dry_run` checkbox. `release.yml` +One button: **Actions → Release → Run workflow**, with a `dry_run` checkbox, which stops after +`prepare` and shows what the release would change (`scripts/release-preview.mjs`). `release.yml` carries the whole path — `prepare`, `release-build`, `publish` — and `ci.yml` is only CI. **Two platforms, deliberately: Windows and Linux.** The release matrix builds diff --git a/docs/releasing.md b/docs/releasing.md index afb8484a..a7d042ad 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -18,10 +18,11 @@ state to clean up if it stops. says the same for `app`. It checks that **before the tag exists**, so a mismatch costs a re-run rather than a deleted tag. -2. **Actions → Release → Run workflow, with `dry_run` checked.** It prints the notes it - would write to the run summary, builds and signs the packages (kept as the run's - artifacts), and changes nothing. Read the notes: this is the only moment where a misfiled - entry is free to fix. +2. **Actions → Release → Run workflow, with `dry_run` checked.** In about a minute, the run's + summary shows what the release would change and with what: the version and the commit it + leaves from, the diff of `CHANGELOG.md`, the commit and the tag, the files, the notes of the + update prompt, and the pull request behind each entry. It builds nothing and changes nothing. + Read it: this is the only moment where a misfiled entry is free to fix. 3. **Run it again unchecked.** It writes the `CHANGELOG.md` section, commits it, tags, builds the packages and publishes the release. @@ -29,7 +30,7 @@ state to clean up if it stops. 4. **Nothing to do for the website.** `website.yml` runs when the release run completes and publishes the site again: its download page offers the files of the latest release, whose version, sizes and SHA-256 `website/scripts/fetch-release.mjs` reads at build time. A dry run - publishes nothing new: the latest release is still the same. → "The website" in + does not start it. → "The website" in `docs/architecture.md`. ## A version on a branch of its own @@ -157,4 +158,6 @@ release is published last. A failure before the tag leaves nothing to undo but a commit. A failure after the tag is the awkward one: delete the tag and the draft release, then run -again. This is what the dry run exists to avoid. +again. The dry run builds nothing, so what keeps it from happening is CI, green on the commit; +`packages.yml`, on every pull request that touches packaging (packages, signatures and an update, +with a key made for the run); and `prepare`, which refuses a release whose signing key is not set. diff --git a/package.json b/package.json index a6bf32f1..e4aad995 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ }, "private": true, "scripts": { - "test:scripts": "node --test scripts/release-notes.test.mjs scripts/version.test.mjs scripts/latest-json.test.mjs", + "test:scripts": "node --test scripts/release-notes.test.mjs scripts/release-preview.test.mjs scripts/version.test.mjs scripts/latest-json.test.mjs", "lint": "prettier --check .", "format": "prettier --write .", "prettier": "node scripts/prettier.mjs" diff --git a/scripts/release-preview.mjs b/scripts/release-preview.mjs new file mode 100644 index 00000000..3a904b05 --- /dev/null +++ b/scripts/release-preview.mjs @@ -0,0 +1,103 @@ +#!/usr/bin/env node +// What a release would change, for a dry run to show: nothing here writes to the repository. +// `node scripts/release-preview.mjs --version x.y.z --prompt --repo `, once +// `release-notes.mjs generate --write` has written the section into CHANGELOG.md. + +import { execFileSync } from 'node:child_process'; +import { readFileSync } from 'node:fs'; +import { parseArgs } from 'node:util'; +import { pathToFileURL } from 'node:url'; + +/** The last release's files, under the new version. */ +export function renamed(files, previous, version) { + return files.map((file) => file.replaceAll(previous, version)); +} + +/** Longer than any run of backticks in `text`, so that a diff holding a fence closes nothing. */ +function fenced(text, language) { + const longest = Math.max(0, ...[...text.matchAll(/`+/g)].map(([run]) => run.length)); + const fence = '`'.repeat(Math.max(3, longest + 1)); + return `${fence}${language}\n${text.trimEnd()}\n${fence}`; +} + +export function preview({ repo, previous, version, commit, subject, diff, prompt, files }) { + const tag = `v${version}`; + const compare = `https://github.com/${repo}/compare/v${previous}...${tag}`; + const rows = [ + ['Version', previous ? `${previous} → **${version}**` : `**${version}**, la première`], + ['Publié depuis', `\`${commit}\` ${subject.replaceAll('|', '\\|')}`], + ['Commit sur `main`', `\`chore(release): ${tag}\`, \`CHANGELOG.md\` seul`], + ['Tag', `\`${tag}\`, sur ce commit`], + [ + 'Page de la release', + previous + ? `la section écrite plus haut, et [la comparaison](${compare}) une fois le tag créé` + : 'la section écrite plus haut', + ], + [ + 'Fichiers', + files.length ? files.map((file) => `\`${file}\``).join('
') : 'aucune release à comparer', + ], + ['Site', `la page de téléchargement passe à ${version}`], + ]; + return [ + `# Dry run : ce que changerait la ${version}`, + '', + 'Aucun commit, aucun tag, aucune compilation, aucune signature, aucune publication.', + '', + '| Quoi | Avec quoi |', + '|---|---|', + ...rows.map(([what, how]) => `| ${what} | ${how} |`), + '', + '## `CHANGELOG.md`', + '', + fenced(diff || '(aucun changement)', 'diff'), + '', + '## Fiche de mise à jour, dans l’application', + '', + fenced(prompt, 'markdown'), + '', + ].join('\n'); +} + +function main() { + const { values } = parseArgs({ + options: { version: { type: 'string' }, prompt: { type: 'string' }, repo: { type: 'string' } }, + }); + for (const name of ['version', 'prompt', 'repo']) { + if (!values[name]) { + throw new Error(`--${name} is required`); + } + } + const run = (command, args) => execFileSync(command, args, { encoding: 'utf8' }).trim(); + /** The first release has no tag before it. */ + const attempt = (command, args) => { + try { + return run(command, args); + } catch { + return ''; + } + }; + + const tag = attempt('git', ['describe', '--tags', '--abbrev=0', '--match', 'v*']); + const previous = tag.replace(/^v/, ''); + const assets = tag + ? run('gh', ['release', 'view', tag, '--repo', values.repo, '--json', 'assets', '--jq', '.assets[].name']) + : ''; + process.stdout.write( + preview({ + repo: values.repo, + previous, + version: values.version, + commit: run('git', ['rev-parse', '--short=8', 'HEAD']), + subject: run('git', ['log', '-1', '--format=%s']), + diff: run('git', ['diff', '--unified=1', '--', 'CHANGELOG.md']), + prompt: readFileSync(values.prompt, 'utf8'), + files: renamed(assets.split('\n').filter(Boolean), previous, values.version), + }), + ); +} + +if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { + main(); +} diff --git a/scripts/release-preview.test.mjs b/scripts/release-preview.test.mjs new file mode 100644 index 00000000..1115ad32 --- /dev/null +++ b/scripts/release-preview.test.mjs @@ -0,0 +1,65 @@ +import assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; + +import { preview, renamed } from './release-preview.mjs'; + +const RELEASE = { + repo: 'owner/name', + previous: '1.1.0', + version: '1.2.0', + commit: '3dc69d1d', + subject: 'Website: language button named in full (#1652)', + diff: '+## [1.2.0] - 2026-12-01\n+\n+- Tabs: raised (#1)', + prompt: '### ✨ Added\n\n- Tabs: raised (#1)\n', + files: ['devnotes-1.2.0-linux', 'latest.json'], +}; + +describe('renamed', () => { + it('puts the new version in the names of the last release', () => { + const files = ['devnotes_1.1.0_x64-setup.exe', 'devnotes-1.1.0-linux', 'latest.json']; + + assert.deepEqual(renamed(files, '1.1.0', '1.2.0'), [ + 'devnotes_1.2.0_x64-setup.exe', + 'devnotes-1.2.0-linux', + 'latest.json', + ]); + }); +}); + +describe('preview', () => { + it('says what would be committed, tagged and published, and from what', () => { + const text = preview(RELEASE); + + for (const said of [ + '1.1.0 → **1.2.0**', + '`3dc69d1d` Website: language button named in full (#1652)', + '`chore(release): v1.2.0`', + '`v1.2.0`, sur ce commit', + 'https://github.com/owner/name/compare/v1.1.0...v1.2.0', + '`devnotes-1.2.0-linux`
`latest.json`', + ]) { + assert.ok(text.includes(said), said); + } + }); + + it('shows the changelog as a diff and the prompt as it is written', () => { + const text = preview(RELEASE); + + assert.ok(text.includes(`\`\`\`diff\n${RELEASE.diff}\n\`\`\``)); + assert.ok(text.includes(`\`\`\`markdown\n${RELEASE.prompt.trimEnd()}\n\`\`\``)); + }); + + it('is not closed early by a fence in the diff, nor split by a bar in a title', () => { + const text = preview({ ...RELEASE, diff: '+```js\n+x\n+```', subject: 'Tables: a | b' }); + + assert.ok(text.includes('````diff\n+```js\n+x\n+```\n````')); + assert.ok(text.includes('Tables: a \\| b |')); + }); + + it('does without a release before it', () => { + const text = preview({ ...RELEASE, previous: '', files: [] }); + + assert.ok(text.includes('**1.2.0**, la première')); + assert.ok(!text.includes('/compare/')); + }); +});