@@ -181,3 +181,111 @@ jobs:
181181 assert.equal(process.env.OUTCOME, process.env.EXPECTED_OUTCOME);
182182 assert.equal(createHash('sha256').update(fs.readFileSync(process.env.TARBALL)).digest('hex'), process.env.EXPECTED_DIGEST);
183183 assert.deepEqual(fs.readdirSync(process.env.RUNNER_TEMP).filter(name => name.startsWith('package-test-')), []);
184+
185+ consumer :
186+ name : Installed consumer (${{ matrix.fixture.name }})
187+ runs-on : ubuntu-latest
188+ permissions :
189+ contents : read
190+ strategy :
191+ fail-fast : false
192+ matrix :
193+ fixture :
194+ - name : empty consumer
195+ project : " "
196+ outcome : success
197+ - name : example project
198+ project : consumer-fixture
199+ outcome : success
200+ - name : failed installation
201+ project : " "
202+ outcome : failure
203+ steps :
204+ - name : Arrange - Checkout
205+ uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
206+ with :
207+ persist-credentials : false
208+ - name : Arrange - Package and example project with failing install hooks
209+ id : fixture
210+ uses : actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
211+ env :
212+ FAIL_INSTALL : ${{ matrix.fixture.outcome == 'failure' }}
213+ with :
214+ script : |
215+ const fs = require('node:fs');
216+ const path = require('node:path');
217+ const { createHash } = require('node:crypto');
218+ const directory = fs.mkdtempSync(path.join(process.env.RUNNER_TEMP, 'consumer-fixture-'));
219+ const packageDirectory = path.join(directory, 'package');
220+ await io.mkdirP(packageDirectory);
221+ const scripts = { preinstall: 'exit 91', install: 'exit 91', postinstall: 'exit 91', prepare: 'exit 91' };
222+ fs.writeFileSync(path.join(packageDirectory, 'package.json'), JSON.stringify({
223+ name: '@example/consumer-fixture', version: '1.2.3', main: 'index.js',
224+ bin: { 'fixture-cli': 'cli.js' }, scripts,
225+ dependencies: process.env.FAIL_INSTALL === 'true' ? { missing: `file:${directory}/missing.tgz` } : {},
226+ }));
227+ fs.writeFileSync(path.join(packageDirectory, 'index.js'), 'module.exports = 42;');
228+ fs.writeFileSync(path.join(packageDirectory, 'cli.js'), '#!/usr/bin/env node\nconsole.log(require("./package.json").version);');
229+ const tarball = path.join(directory, 'fixture.tgz');
230+ await exec.exec('tar', ['-czf', tarball, '-C', directory, 'package']);
231+ const project = path.join(process.env.GITHUB_WORKSPACE, 'consumer-fixture');
232+ await io.mkdirP(path.join(project, 'node_modules', 'must-not-copy'));
233+ await io.mkdirP(path.join(project, '.git'));
234+ fs.writeFileSync(path.join(project, 'node_modules', 'must-not-copy', 'sentinel'), 'preserve');
235+ fs.writeFileSync(path.join(project, '.git', 'sentinel'), 'preserve');
236+ fs.writeFileSync(path.join(project, '.fixture-config'), 'copied');
237+ fs.writeFileSync(path.join(project, 'package.json'), JSON.stringify({
238+ name: 'example-consumer', private: true,
239+ dependencies: { '@example/consumer-fixture': 'file:../must-not-resolve' },
240+ scripts: { ...scripts, build: 'node build.cjs' },
241+ }));
242+ fs.writeFileSync(path.join(project, 'build.cjs'), 'require("node:assert/strict").equal(require("@example/consumer-fixture"), 42);');
243+ core.setOutput('tarball', tarball);
244+ core.setOutput('digest', createHash('sha256').update(fs.readFileSync(tarball)).digest('hex'));
245+ core.setOutput('project-manifest', fs.readFileSync(path.join(project, 'package.json'), 'utf8'));
246+ - name : Act - Exercise the installed package
247+ id : test
248+ continue-on-error : true
249+ uses : $/actions/package/test
250+ env :
251+ TEST_PROJECT : ${{ matrix.fixture.project }}
252+ with :
253+ tarball-path : ${{ steps.fixture.outputs.tarball }}
254+ test-project : ${{ matrix.fixture.project }}
255+ commands : |
256+ test "$PWD" != "$GITHUB_WORKSPACE"
257+ test "$PACKAGE_NAME" = @example/consumer-fixture
258+ test "$PACKAGE_VERSION" = 1.2.3
259+ test "$(fixture-cli)" = "$PACKAGE_VERSION"
260+ test -f "$PACKAGE_INSTALL_PATH/index.js"
261+ test ! -e node_modules/must-not-copy
262+ test ! -e .git
263+ node -e 'require("node:assert/strict").equal(require(process.env.PACKAGE_NAME), 42)'
264+ if [ -n "$TEST_PROJECT" ]; then
265+ test "$(cat .fixture-config)" = copied
266+ npm run build
267+ fi
268+ touch "$RUNNER_TEMP/consumer-command-ran"
269+ - name : Assert - Outcome, cleanup and unchanged source files
270+ uses : actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
271+ env :
272+ OUTCOME : ${{ steps.test.outcome }}
273+ EXPECTED_OUTCOME : ${{ matrix.fixture.outcome }}
274+ TARBALL : ${{ steps.fixture.outputs.tarball }}
275+ EXPECTED_DIGEST : ${{ steps.fixture.outputs.digest }}
276+ PROJECT_MANIFEST : ${{ steps.fixture.outputs.project-manifest }}
277+ with :
278+ script : |
279+ const assert = require('node:assert/strict');
280+ const fs = require('node:fs');
281+ const path = require('node:path');
282+ const { createHash } = require('node:crypto');
283+ assert.equal(process.env.OUTCOME, process.env.EXPECTED_OUTCOME);
284+ assert.equal(fs.existsSync(path.join(process.env.RUNNER_TEMP, 'consumer-command-ran')), process.env.OUTCOME === 'success');
285+ assert.equal(createHash('sha256').update(fs.readFileSync(process.env.TARBALL)).digest('hex'), process.env.EXPECTED_DIGEST);
286+ assert.deepEqual(fs.readdirSync(process.env.RUNNER_TEMP).filter(name => name.startsWith('package-test-')), []);
287+ const project = path.join(process.env.GITHUB_WORKSPACE, 'consumer-fixture');
288+ assert.equal(fs.readFileSync(path.join(project, 'package.json'), 'utf8'), process.env.PROJECT_MANIFEST);
289+ assert.equal(fs.readFileSync(path.join(project, 'node_modules', 'must-not-copy', 'sentinel'), 'utf8'), 'preserve');
290+ assert.equal(fs.readFileSync(path.join(project, '.git', 'sentinel'), 'utf8'), 'preserve');
291+ assert.equal(fs.existsSync(path.join(project, 'package-lock.json')), false);
0 commit comments