Skip to content

Commit 31cd29b

Browse files
authored
feat(release)!: publish npm packages validated by CI
* feat(release): automate single-package npm releases with HoverKraft Prepare committed versions, consume an existing build, publish npm packages and GitHub release notes, and recover partial publication. Keep release validation and the consolidated decision record with the release workflow. * refactor(release): publish package artifacts validated by CI * docs: align release ownership in the decision record * refactor(package): rename publication recovery input * refactor(release): pass tarball directly to finalization
1 parent 1f61707 commit 31cd29b

50 files changed

Lines changed: 3608 additions & 66 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/dependabot.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ updates:
3535
versioning-strategy: increase
3636
directories:
3737
- "/"
38+
- "/actions/**/*"
3839
- "/tests/npm"
3940
- "/tests/pnpm"
4041
- "/tests/pnpm-package-manager"

‎.github/workflows/__shared-ci.yml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ jobs:
1717
security-events: write
1818
statuses: write
1919

20+
test-release:
21+
name: Test release preparation and recovery
22+
uses: $/.github/workflows/__test-release.yml
23+
permissions:
24+
actions: read
25+
contents: read
26+
id-token: write
27+
packages: read
28+
pull-requests: write
29+
security-events: write
30+
2031
test-action-dependencies-cache:
2132
name: Test action "dependencies-cache"
2233
needs: linter

‎.github/workflows/__test-action-package-publish.yml‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,26 @@ jobs:
7575
dry-run: "yes"
7676
provenance: "false"
7777

78+
- id: wrong-identity
79+
name: Act - Reject an unintended release package
80+
continue-on-error: true
81+
uses: $/actions/package/publish
82+
with:
83+
package-tarball-artifact-id: ${{ needs.package.outputs.package-tarball-artifact-id }}
84+
name: another-package
85+
version: 0.1.0
86+
dry-run: "true"
87+
provenance: "false"
88+
7889
- name: Assert - Invalid inputs fail before publishing
7990
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
8091
env:
8192
INVALID_ARTIFACT_OUTCOME: ${{ steps.invalid-artifact.outcome }}
93+
WRONG_IDENTITY_OUTCOME: ${{ steps.wrong-identity.outcome }}
8294
INVALID_DRY_RUN_OUTCOME: ${{ steps.invalid-dry-run.outcome }}
8395
with:
8496
script: |
85-
for (const outcome of [process.env.INVALID_ARTIFACT_OUTCOME, process.env.INVALID_DRY_RUN_OUTCOME]) {
97+
for (const outcome of [process.env.INVALID_ARTIFACT_OUTCOME, process.env.INVALID_DRY_RUN_OUTCOME, process.env.WRONG_IDENTITY_OUTCOME]) {
8698
if (outcome !== 'failure') {
8799
core.setFailed('Expected invalid publish inputs to fail');
88100
}
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
name: Internal - Tests for package and release actions
2+
3+
on:
4+
workflow_call:
5+
6+
permissions: {}
7+
8+
jobs:
9+
continuous-integration:
10+
name: Unit tests for ${{ matrix.action }}
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
action:
15+
[package/restore, release/prepare, release/verify, release/finalize]
16+
uses: $/.github/workflows/continuous-integration.yml
17+
permissions:
18+
contents: read
19+
id-token: write
20+
packages: read
21+
pull-requests: write
22+
security-events: write
23+
with:
24+
working-directory: actions/${{ matrix.action }}
25+
build: null
26+
lint: null
27+
test: '{ "coverage": null }'
28+
29+
integration-tests:
30+
name: Test release action inputs, outputs and failures
31+
runs-on: ubuntu-latest
32+
permissions:
33+
actions: read
34+
contents: read
35+
steps:
36+
- name: Arrange - Checkout
37+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
38+
with:
39+
persist-credentials: false
40+
- uses: $/actions/setup-node
41+
with:
42+
working-directory: actions/release/prepare
43+
install-dependencies: "false"
44+
45+
- name: Act - Reject preparation of a private package
46+
id: private-project
47+
continue-on-error: true
48+
uses: $/actions/release/prepare
49+
with:
50+
working-directory: actions/release/prepare
51+
- name: Assert - Preparation failed
52+
env:
53+
OUTCOME: ${{ steps.private-project.outcome }}
54+
run: test "$OUTCOME" = failure
55+
56+
- name: Arrange - Create an installable release tarball
57+
id: fixture
58+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
59+
with:
60+
script: |
61+
const fs = require('node:fs');
62+
const path = require('node:path');
63+
const { createHash } = require('node:crypto');
64+
const directory = fs.mkdtempSync(path.join(process.env.RUNNER_TEMP, 'release-fixture-'));
65+
const name = `hoverkraft-release-test-${context.runId}-${process.env.GITHUB_RUN_ATTEMPT}`;
66+
fs.writeFileSync(path.join(directory, 'package.json'), JSON.stringify({
67+
name, version: '1.2.3', bin: { 'release-fixture': 'cli.js' },
68+
scripts: { prepare: 'exit 91', prepack: 'exit 91', postpack: 'exit 91' },
69+
}));
70+
fs.writeFileSync(path.join(directory, 'cli.js'), '#!/usr/bin/env node\nconsole.log("1.2.3");\n', { mode: 0o755 });
71+
const { stdout } = await exec.getExecOutput('npm', ['pack', '--json', '--ignore-scripts'], { cwd: directory });
72+
const tarball = path.join(directory, JSON.parse(stdout)[0].filename);
73+
core.setOutput('name', name);
74+
core.setOutput('tarball', tarball);
75+
core.setOutput('digest', createHash('sha256').update(fs.readFileSync(tarball)).digest('hex'));
76+
core.setOutput('packages', [{ name, slug: name, version: '1.2.3', tag: 'v1.2.3', directory: '.' }]);
77+
78+
- name: Act - Reject an invalid package artifact ID
79+
id: invalid-artifact
80+
continue-on-error: true
81+
uses: $/actions/release/verify
82+
with:
83+
packages: ${{ steps.fixture.outputs.packages }}
84+
package-tarball-artifact-id: "0"
85+
- name: Act - Reject a mismatched tarball version
86+
id: mismatched-version
87+
continue-on-error: true
88+
uses: $/actions/package/restore
89+
with:
90+
name: ${{ steps.fixture.outputs.name }}
91+
version: 9.9.9
92+
tarball-path: ${{ steps.fixture.outputs.tarball }}
93+
- name: Act - Check an unpublished npm version
94+
id: registry
95+
uses: $/actions/package/restore
96+
with:
97+
name: ${{ steps.fixture.outputs.name }}
98+
version: 1.2.3
99+
tarball-path: ${{ steps.fixture.outputs.tarball }}
100+
- name: Assert - Rejections and registry output
101+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
102+
env:
103+
ARTIFACT_OUTCOME: ${{ steps.invalid-artifact.outcome }}
104+
VERSION_OUTCOME: ${{ steps.mismatched-version.outcome }}
105+
PUBLISHED: ${{ steps.registry.outputs.published }}
106+
TARBALL: ${{ steps.fixture.outputs.tarball }}
107+
EXPECTED_DIGEST: ${{ steps.fixture.outputs.digest }}
108+
with:
109+
script: |
110+
const assert = require('node:assert/strict');
111+
const fs = require('node:fs');
112+
const { createHash } = require('node:crypto');
113+
assert.equal(process.env.ARTIFACT_OUTCOME, 'failure');
114+
assert.equal(process.env.VERSION_OUTCOME, 'failure');
115+
assert.equal(process.env.PUBLISHED, 'false');
116+
assert.equal(createHash('sha256').update(fs.readFileSync(process.env.TARBALL)).digest('hex'), process.env.EXPECTED_DIGEST);
117+
118+
- name: Arrange - Upload the unpublished package
119+
id: unpublished-package
120+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
121+
with:
122+
name: unpublished-package-${{ github.run_id }}-${{ github.run_attempt }}
123+
path: ${{ steps.fixture.outputs.tarball }}
124+
archive: false
125+
if-no-files-found: error
126+
- name: Act - Publish dry run with package recovery enabled
127+
id: publish
128+
uses: $/actions/package/publish
129+
with:
130+
package-tarball-artifact-id: ${{ steps.unpublished-package.outputs.artifact-id }}
131+
recover-existing: "true"
132+
dry-run: "true"
133+
provenance: "false"
134+
- name: Assert - Publish preserved the unpublished tarball
135+
env:
136+
ORIGINAL_TARBALL: ${{ steps.fixture.outputs.tarball }}
137+
PUBLISH_TARBALL: ${{ steps.publish.outputs.package-tarball-path }}
138+
run: cmp "$ORIGINAL_TARBALL" "$PUBLISH_TARBALL"
139+
140+
- name: Act - Install and run the release package
141+
id: smoke
142+
uses: $/actions/package/test
143+
env:
144+
EXPECTED_PACKAGE_NAME: ${{ steps.fixture.outputs.name }}
145+
with:
146+
working-directory: actions/package/test
147+
tarball-path: ${{ steps.fixture.outputs.tarball }}
148+
commands: |
149+
test "$PWD" = "$GITHUB_WORKSPACE/actions/package/test"
150+
test "$PACKAGE_NAME" = "$EXPECTED_PACKAGE_NAME"
151+
test "$PACKAGE_VERSION" = 1.2.3
152+
consumer=$(mktemp -d)
153+
npm install --prefix "$consumer" --ignore-scripts --offline --no-audit --no-fund "$PACKAGE_TARBALL_PATH"
154+
test "$("$consumer/node_modules/.bin/release-fixture")" = "$PACKAGE_VERSION"
155+
touch "$RUNNER_TEMP/release-smoke-ran"
156+
- name: Act - Reject a failing package command
157+
id: failing-command
158+
continue-on-error: true
159+
uses: $/actions/package/test
160+
with:
161+
tarball-path: ${{ steps.fixture.outputs.tarball }}
162+
commands: exit 7
163+
- name: Act - Reject modified tarball bytes
164+
id: modified-tarball
165+
continue-on-error: true
166+
uses: $/actions/package/test
167+
with:
168+
tarball-path: ${{ steps.fixture.outputs.tarball }}
169+
commands: printf changed >> "$PACKAGE_TARBALL_PATH"
170+
- name: Assert - Smoke checks ran and rejected both failures
171+
env:
172+
SMOKE_OUTCOME: ${{ steps.smoke.outcome }}
173+
COMMAND_OUTCOME: ${{ steps.failing-command.outcome }}
174+
TARBALL_OUTCOME: ${{ steps.modified-tarball.outcome }}
175+
run: |
176+
test "$SMOKE_OUTCOME" = success
177+
test -f "$RUNNER_TEMP/release-smoke-ran"
178+
test "$COMMAND_OUTCOME" = failure
179+
test "$TARBALL_OUTCOME" = failure

‎.github/workflows/__test-workflow-continuous-integration.yml‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ jobs:
1717
security-events: write
1818
with:
1919
working-directory: tests/npm
20+
package: true
21+
package-tests: |
22+
tar -xOf "$PACKAGE_TARBALL_PATH" package/dist/test.txt > "$RUNNER_TEMP/package-build.txt"
23+
test "$(cat "$RUNNER_TEMP/package-build.txt")" = 'build test'
24+
test "$PACKAGE_NAME" = test-for-ci-with-npm
25+
consumer=$(mktemp -d)
26+
npm install --prefix "$consumer" --ignore-scripts --offline --no-audit --no-fund "$PACKAGE_TARBALL_PATH"
27+
test -f "$consumer/node_modules/$PACKAGE_NAME/dist/test.txt"
2028
code-ql: |
2129
{
2230
"languages": "javascript-typescript",
@@ -46,6 +54,22 @@ jobs:
4654
- name: Check the build artifacts
4755
run: test -f tests/npm/dist/test.txt
4856

57+
- name: Act - Consume the validated CI package without repacking
58+
id: validated-package
59+
uses: $/actions/package/publish
60+
with:
61+
package-tarball-artifact-id: ${{ needs.act-without-container.outputs.package-tarball-artifact-id }}
62+
name: test-for-ci-with-npm
63+
version: 0.1.0
64+
dry-run: "true"
65+
provenance: "false"
66+
- name: Assert - The CI package contains the compiled output
67+
env:
68+
TARBALL: ${{ steps.validated-package.outputs.package-tarball-path }}
69+
run: |
70+
tar -xOf "$TARBALL" package/dist/test.txt > "$RUNNER_TEMP/ci-packaged-build.txt"
71+
cmp tests/npm/dist/test.txt "$RUNNER_TEMP/ci-packaged-build.txt"
72+
4973
- name: Arrange packaging hooks that must not run
5074
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
5175
with:
@@ -82,6 +106,22 @@ jobs:
82106
tar -xOf "$TARBALL" package/dist/test.txt > "$RUNNER_TEMP/packaged-build.txt"
83107
cmp "$RUNNER_TEMP/prepared-fixture/dist/test.txt" "$RUNNER_TEMP/packaged-build.txt"
84108
test ! -d tests/npm/node_modules
109+
- name: Run package smoke checks with the project runtime
110+
uses: $/actions/package/test
111+
with:
112+
working-directory: tests/npm
113+
tarball-path: ${{ steps.package.outputs.package-tarball-path }}
114+
commands: |
115+
node <<'NODE'
116+
const assert = require('node:assert/strict');
117+
const fs = require('node:fs');
118+
const expected = fs.readFileSync('.node-version', 'utf8').trim().split('.');
119+
assert.deepEqual(process.versions.node.split('.').slice(0, expected.length), expected);
120+
NODE
121+
test "$PACKAGE_NAME" = prepared-fixture
122+
test "$PACKAGE_VERSION" = 1.2.3
123+
tar -xOf "$PACKAGE_TARBALL_PATH" package/dist/test.txt > "$RUNNER_TEMP/smoke-output.txt"
124+
cmp "$RUNNER_TEMP/prepared-fixture/dist/test.txt" "$RUNNER_TEMP/smoke-output.txt"
85125
- name: Validate publishing the prepared tarball
86126
uses: $/actions/package/publish
87127
with:
@@ -111,6 +151,16 @@ jobs:
111151
{"coverage": "github"}
112152
# jscpd:ignore-end
113153

154+
assert-package-disabled:
155+
name: Assert - Package creation is opt-in
156+
needs: act-without-container-and-github-reports
157+
runs-on: ubuntu-latest
158+
permissions: {}
159+
steps:
160+
- env:
161+
PACKAGE_ARTIFACT_ID: ${{ needs.act-without-container-and-github-reports.outputs.package-tarball-artifact-id }}
162+
run: test -z "$PACKAGE_ARTIFACT_ID"
163+
114164
arrange-with-container:
115165
name: Arrange - Build container image for CI workflow
116166
permissions:

0 commit comments

Comments
 (0)