@@ -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]*$/);
0 commit comments