Skip to content

Commit 91784ab

Browse files
committed
feat(release): support npm/pnpm workspaces and Lerna releases
Extend preparation, package selection, publication and recovery for npm/pnpm workspaces and fixed or independent Lerna projects, with colocated tests.
1 parent dfd1662 commit 91784ab

27 files changed

Lines changed: 7502 additions & 236 deletions

‎.github/workflows/__pull-request-ci.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name: Internal - Pull request - Continuous Integration
33
on:
44
merge_group:
55
pull_request:
6-
branches: [main]
76

87
permissions: {}
98

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

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

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ jobs:
3131
name: Assert - Ensure build artifact has been uploaded (without container)
3232
runs-on: ubuntu-latest
3333
needs: act-without-container
34+
outputs:
35+
package-artifact-id: ${{ steps.package.outputs.package-tarball-artifact-id }}
3436
permissions:
3537
actions: read
3638
contents: read
@@ -106,6 +108,45 @@ jobs:
106108
package-tarball-artifact-id: ${{ steps.package.outputs.package-tarball-artifact-id }}
107109
dry-run: "true"
108110
provenance: "false"
111+
- name: Record validated package
112+
uses: hoverkraft-tech/ci-github-common/actions/set-matrix-output@44f6108cef0e9884ea7735f3d62932c2310745d4 # 0.39.1
113+
with:
114+
artifact-name: release-package-validation
115+
value: |
116+
{"name":"prepared-fixture","artifactId":"${{ steps.package.outputs.package-tarball-artifact-id }}","attempt":${{ github.run_attempt }}}
117+
118+
assert-package-validation:
119+
name: Assert - Collect validated package from another job
120+
needs: assert-without-container
121+
runs-on: ubuntu-latest
122+
permissions:
123+
actions: read
124+
contents: read
125+
steps:
126+
- id: collect
127+
uses: $/actions/release/collect-packages
128+
with:
129+
packages: '[{"name":"prepared-fixture"}]'
130+
- name: Check collected artifact identity
131+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
132+
env:
133+
PACKAGES: ${{ steps.collect.outputs.packages }}
134+
EXPECTED_ARTIFACT_ID: ${{ needs.assert-without-container.outputs.package-artifact-id }}
135+
with:
136+
script: |
137+
const assert = require('node:assert/strict');
138+
assert.deepEqual(JSON.parse(process.env.PACKAGES), [{ name: 'prepared-fixture', artifactId: process.env.EXPECTED_ARTIFACT_ID }]);
139+
140+
- name: Act - Reject missing package validation
141+
id: missing-validation
142+
continue-on-error: true
143+
uses: $/actions/release/collect-packages
144+
with:
145+
packages: '[{"name":"missing-fixture"}]'
146+
- name: Assert - Missing validation blocks collection
147+
env:
148+
OUTCOME: ${{ steps.missing-validation.outcome }}
149+
run: test "$OUTCOME" = failure
109150

110151
act-without-container-and-github-reports:
111152
# jscpd:ignore-start

‎.github/workflows/prepare-package-release.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ See [the release guide](release.md).
4040

4141
| **Input** | **Description** | **Required** | **Type** | **Default** |
4242
| -------------------------- | ----------------------------------------------------------------------------------------------------------------------- | ------------ | ---------- | ----------- |
43-
| **`working-directory`** | Public npm project directory containing its package.json and lockfile. | **false** | **string** | `.` |
43+
| **`versioning`** | Versioning tool, npm for one public package or lerna for fixed or independent workspaces. | **false** | **string** | `npm` |
44+
| **`working-directory`** | Project or workspace root containing the lockfile and package manager configuration. | **false** | **string** | `.` |
45+
| **`package-directory`** | Public npm package directory relative to working-directory. Leave as . for a root package or Lerna workspaces. | **false** | **string** | `.` |
4446
| **`github-app-client-id`** | Optional GitHub App client ID, paired with the github-app-key secret to generate a repository-scoped preparation token. | **false** | **string** | - |
4547

4648
<!-- inputs:end -->

‎.github/workflows/prepare-package-release.yml‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@ name: Prepare Node.js Package Release
66
on:
77
workflow_call:
88
inputs:
9+
versioning:
10+
description: Versioning tool, npm for one public package or lerna for fixed or independent workspaces.
11+
type: string
12+
default: npm
913
working-directory:
10-
description: Public npm project directory containing its package.json and lockfile.
14+
description: Project or workspace root containing the lockfile and package manager configuration.
15+
type: string
16+
default: .
17+
package-directory:
18+
description: Public npm package directory relative to working-directory. Leave as . for a root package or Lerna workspaces.
1119
type: string
1220
default: .
1321
github-app-client-id:
@@ -60,5 +68,7 @@ jobs:
6068
- id: prepare
6169
uses: $/actions/release/prepare
6270
with:
71+
versioning: ${{ inputs.versioning }}
6372
working-directory: ${{ inputs.working-directory }}
73+
package-directory: ${{ inputs.package-directory }}
6474
github-token: ${{ steps.release-token.outputs.token || github.token }}

0 commit comments

Comments
 (0)