Skip to content

Commit 46ff06a

Browse files
committed
feat(release): support npm/pnpm workspaces and Lerna releases
1 parent aaab44d commit 46ff06a

34 files changed

Lines changed: 8042 additions & 369 deletions

‎.github/workflows/__test-release.yml‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,90 @@ jobs:
177177
test -f "$RUNNER_TEMP/release-smoke-ran"
178178
test "$COMMAND_OUTCOME" = failure
179179
test "$TARBALL_OUTCOME" = failure
180+
181+
prepared-workspaces:
182+
name: Test prepared workspace packaging (${{ matrix.manager }})
183+
runs-on: ubuntu-latest
184+
permissions:
185+
contents: read
186+
strategy:
187+
fail-fast: false
188+
matrix:
189+
manager: [pnpm10, pnpm]
190+
steps:
191+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
192+
with:
193+
persist-credentials: false
194+
- name: Arrange - Create a workspace with compiled output and failing hooks
195+
id: workspace
196+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
197+
env:
198+
MANAGER: ${{ matrix.manager }}
199+
with:
200+
script: |
201+
const fs = require('node:fs');
202+
const path = require('node:path');
203+
const lock = JSON.parse(fs.readFileSync('actions/release/prepare/package-lock.json', 'utf8'));
204+
const version = lock.packages[`node_modules/${process.env.MANAGER}`].version;
205+
const directory = fs.mkdtempSync(path.join(process.env.RUNNER_TEMP, 'pnpm-release-'));
206+
const write = async (file, value) => {
207+
const target = path.join(directory, file);
208+
await io.mkdirP(path.dirname(target));
209+
fs.writeFileSync(target, typeof value === 'string' ? value : JSON.stringify(value));
210+
};
211+
const scripts = Object.fromEntries(['preinstall', 'postinstall', 'prepare', 'prepack', 'postpack'].map(name => [name, 'exit 91']));
212+
await write('.node-version', fs.readFileSync('.node-version', 'utf8'));
213+
await write('package.json', { private: true, packageManager: `pnpm@${version}` });
214+
await write('pnpm-workspace.yaml', "packages:\n - packages/*\n");
215+
await write('packages/core/package.json', { name: '@example/core', version: '1.4.0' });
216+
await write('packages/cli/package.json', {
217+
name: '@example/cli', version: '2.3.0', files: ['dist'], scripts,
218+
dependencies: { '@example/core': 'workspace:^' },
219+
});
220+
await write('packages/cli/dist/index.js', 'compiled by CI\n');
221+
core.setOutput('directory', directory);
222+
- uses: $/actions/setup-node
223+
with:
224+
working-directory: ${{ steps.workspace.outputs.directory }}
225+
install-dependencies: "false"
226+
- name: Arrange - Resolve the workspace lockfile
227+
working-directory: ${{ steps.workspace.outputs.directory }}
228+
run: pnpm install --lockfile-only --ignore-scripts
229+
- name: Arrange - Upload the prepared build
230+
id: build
231+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
232+
with:
233+
path: ${{ steps.workspace.outputs.directory }}
234+
name: workspace-build-${{ matrix.manager }}-${{ github.run_id }}-${{ github.run_attempt }}
235+
if-no-files-found: error
236+
- name: Arrange - Remove local build output before restoration
237+
working-directory: ${{ steps.workspace.outputs.directory }}
238+
run: rm packages/cli/dist/index.js
239+
- name: Arrange - Link the prepared workspace without running hooks
240+
working-directory: ${{ steps.workspace.outputs.directory }}
241+
run: pnpm install --frozen-lockfile --ignore-scripts
242+
- name: Act - Package the selected workspace from CI output
243+
id: package
244+
uses: $/actions/package/create
245+
with:
246+
working-directory: ${{ steps.workspace.outputs.directory }}
247+
package-directory: packages/cli
248+
build-artifact-id: ${{ steps.build.outputs.artifact-id }}
249+
build-artifact-path: ${{ steps.workspace.outputs.directory }}
250+
artifact-name: workspace-package-${{ matrix.manager }}-${{ github.run_id }}-${{ github.run_attempt }}
251+
- name: Assert - Compiled bytes and native workspace dependency resolution
252+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
253+
env:
254+
TARBALL: ${{ steps.package.outputs.package-tarball-path }}
255+
ARTIFACT_ID: ${{ steps.package.outputs.package-tarball-artifact-id }}
256+
with:
257+
script: |
258+
const assert = require('node:assert/strict');
259+
const { stdout: compiled } = await exec.getExecOutput('tar', ['-xOf', process.env.TARBALL, 'package/dist/index.js']);
260+
const { stdout: manifest } = await exec.getExecOutput('tar', ['-xOf', process.env.TARBALL, 'package/package.json']);
261+
const parsed = JSON.parse(manifest);
262+
assert.equal(compiled, 'compiled by CI\n');
263+
assert.equal(parsed.name, '@example/cli');
264+
assert.equal(parsed.version, '2.3.0');
265+
assert.equal(parsed.dependencies['@example/core'], '^1.4.0');
266+
assert.match(process.env.ARTIFACT_ID, /^[1-9][0-9]*$/);

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,41 @@ jobs:
129129
dry-run: "true"
130130
provenance: "false"
131131

132+
assert-package-validation:
133+
name: Assert - Collect validated package from another job
134+
needs: act-without-container
135+
runs-on: ubuntu-latest
136+
permissions:
137+
actions: read
138+
contents: read
139+
steps:
140+
- id: collect
141+
uses: $/actions/package/collect
142+
with:
143+
directories: '["."]'
144+
working-directory: tests/npm
145+
- name: Check collected artifact identity
146+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
147+
env:
148+
ARTIFACTS: ${{ steps.collect.outputs.artifacts }}
149+
EXPECTED_ARTIFACT_ID: ${{ needs.act-without-container.outputs.package-tarball-artifact-id }}
150+
with:
151+
script: |
152+
const assert = require('node:assert/strict');
153+
assert.deepEqual(JSON.parse(process.env.ARTIFACTS), { '.': process.env.EXPECTED_ARTIFACT_ID });
154+
155+
- name: Act - Reject missing package validation
156+
id: missing-validation
157+
continue-on-error: true
158+
uses: $/actions/package/collect
159+
with:
160+
directories: '["missing"]'
161+
working-directory: tests/npm
162+
- name: Assert - Missing validation blocks collection
163+
env:
164+
OUTCOME: ${{ steps.missing-validation.outcome }}
165+
run: test "$OUTCOME" = failure
166+
132167
act-without-container-and-github-reports:
133168
# jscpd:ignore-start
134169
name: Act - Run the continuous integration workflow (without container and GitHub reports)

0 commit comments

Comments
 (0)