diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 28630ee6f..0017a3536 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -83,8 +83,12 @@ jobs: test "$(npm --version)" = 11.21.0 bun run check:release node --test scripts/release.test.mjs scripts/release-workspace.test.mjs scripts/release-promotion.test.mjs scripts/release-registry-provenance.test.mjs + # A push without release commits, or a rerun on a tagged commit, publishes no editor. + - name: Plan the release + id: plan + run: node scripts/release.mjs --dry-run --github-output - name: Require unused editor versions before publishing npm - if: ${{ needs.validation.outputs.vscode_release_affected == 'true' }} + if: ${{ needs.validation.outputs.vscode_release_affected == 'true' && steps.plan.outputs.version != '' }} run: node packages/vscode/scripts/verify-store-availability.mjs - run: bun run release env: diff --git a/scripts/editor-release-gate.test.mjs b/scripts/editor-release-gate.test.mjs index 9aff43f7a..d3244b9ec 100644 --- a/scripts/editor-release-gate.test.mjs +++ b/scripts/editor-release-gate.test.mjs @@ -32,9 +32,13 @@ test('release publishes only the same-run artifacts whose bytes and all sixteen const release = workflow('release'), editor = workflow('editor-verification') assert.equal(release.jobs.release.needs, 'validation') assert.equal(release.jobs.validation.with.release_build, true) + const plan = release.jobs.release.steps.findIndex(step => step.run === 'node scripts/release.mjs --dry-run --github-output') const availability = release.jobs.release.steps.findIndex(step => step.run?.includes('verify-store-availability.mjs')) const npm = release.jobs.release.steps.findIndex(step => step.run === 'bun run release') - assert.ok(availability >= 0 && availability < npm) + assert.ok(plan >= 0 && plan < availability && availability < npm) + // Only a planned release needs unused editor versions; a no-release push must not fail on them. + assert.equal(release.jobs.release.steps[plan].id, 'plan') + assert.match(release.jobs.release.steps[availability].if, /steps\.plan\.outputs\.version != ''/) const steps = release.jobs['publish-editors'].steps const downloads = steps.filter(step => step.uses?.startsWith('actions/download-artifact@')) assert.equal(downloads.length, 2) diff --git a/scripts/release.mjs b/scripts/release.mjs index 572a8786c..6c1848b27 100644 --- a/scripts/release.mjs +++ b/scripts/release.mjs @@ -2,7 +2,7 @@ // tag and notes from the commits (the same resolver as `aronrepo check` and // `aronrepo explain`); this repository's workspace and promotion modules stage, // verify and promote the npm cohort; Aronrepo then creates the GitHub release. -import { mkdir, writeFile } from 'node:fs/promises' +import { appendFile, mkdir, writeFile } from 'node:fs/promises' import { dirname, join } from 'node:path' import { pathToFileURL } from 'node:url' import semver from 'semver' @@ -72,6 +72,7 @@ async function resume(environment, plan, roots, fetchMetadata) { export async function release({ dryRun = false, + githubOutput, branch, cwd = process.cwd(), env = process.env, @@ -92,6 +93,8 @@ export async function release({ } const roots = releasePackageRoots(cwd) if (dryRun) { + // Later workflow steps, such as the editor version gate, run only for an actual release. + if (githubOutput) await appendFile(githubOutput, `release=${plan.release || ''}\nversion=${plan.version ?? ''}\ntag=${plan.tag ?? ''}\n`) log(plan.version ? `\nDry run: would release ${plan.tag} of ${roots.length} packages on ${plan.channel.distTag}.\n\n${plan.notes}` : '\nDry run: no release.') @@ -150,10 +153,12 @@ export async function release({ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { // `--dry-run` prints the plan and notes without verifying, packing or writing anything; + // `--github-output` also writes `release`, `version` and `tag` to $GITHUB_OUTPUT; // `--branch ` plans as that release branch, such as `main` from a feature branch. const branchIndex = process.argv.indexOf('--branch') release({ dryRun: process.argv.includes('--dry-run'), + ...(process.argv.includes('--github-output') ? { githubOutput: process.env.GITHUB_OUTPUT } : {}), ...(branchIndex > 0 ? { branch: process.argv[branchIndex + 1] } : {}) }).catch(error => { console.error(error instanceof Error ? error.stack ?? error.message : error) diff --git a/scripts/release.test.mjs b/scripts/release.test.mjs index 90414df87..07c6173a4 100644 --- a/scripts/release.test.mjs +++ b/scripts/release.test.mjs @@ -147,3 +147,19 @@ test('releases nothing for non-release commits, and resumes the GitHub release o assert.deepEqual(promoted.uploads, ['release-notes-v1.0.1.md']) assert.deepEqual(promoted.steps, ['github v1.0.1']) }) + +test('a dry run writes the plan for later workflow steps without releasing', async () => { + const { cwd, env, commit } = createRepo() + const output = path.join(cwd, 'github-output') + const harness = createHarness(cwd, env) + const quiet = await release({ ...harness.options, dryRun: true, githubOutput: output, env: { ...env, GITHUB_REF_NAME: 'main' } }) + assert.equal(quiet.status, 'dry-run') + assert.equal(readFileSync(output, 'utf8'), 'release=\nversion=\ntag=\n') + + commit('Fix(A): Repair the cache', { 'packages/a/index.js': 'export {}' }) + writeFileSync(output, '') + await release({ ...harness.options, dryRun: true, githubOutput: output, env: { ...env, GITHUB_REF_NAME: 'main' } }) + assert.equal(readFileSync(output, 'utf8'), 'release=patch\nversion=1.0.1\ntag=v1.0.1\n') + assert.deepEqual(harness.steps, []) + assert.deepEqual(harness.releases, []) +})