Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion scripts/editor-release-gate.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion scripts/release.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand All @@ -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.')
Expand Down Expand Up @@ -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 <name>` 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)
Expand Down
16 changes: 16 additions & 0 deletions scripts/release.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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, [])
})
Loading