|
| 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 CI 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 | + build-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 | + skip-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 | + name: ${{ steps.fixture.outputs.name }} |
| 149 | + version: 1.2.3 |
| 150 | + commands: | |
| 151 | + test "$PWD" = "$GITHUB_WORKSPACE/actions/package/test" |
| 152 | + test "$PACKAGE_NAME" = "$EXPECTED_PACKAGE_NAME" |
| 153 | + test "$PACKAGE_VERSION" = 1.2.3 |
| 154 | + consumer=$(mktemp -d) |
| 155 | + npm install --prefix "$consumer" --ignore-scripts --offline --no-audit --no-fund "$PACKAGE_TARBALL_PATH" |
| 156 | + test "$("$consumer/node_modules/.bin/release-fixture")" = "$PACKAGE_VERSION" |
| 157 | + touch "$RUNNER_TEMP/release-smoke-ran" |
| 158 | + - name: Act - Reject a failing package command |
| 159 | + id: failing-command |
| 160 | + continue-on-error: true |
| 161 | + uses: $/actions/package/test |
| 162 | + with: |
| 163 | + tarball-path: ${{ steps.fixture.outputs.tarball }} |
| 164 | + name: ${{ steps.fixture.outputs.name }} |
| 165 | + version: 1.2.3 |
| 166 | + commands: exit 7 |
| 167 | + - name: Act - Reject modified tarball bytes |
| 168 | + id: modified-tarball |
| 169 | + continue-on-error: true |
| 170 | + uses: $/actions/package/test |
| 171 | + with: |
| 172 | + tarball-path: ${{ steps.fixture.outputs.tarball }} |
| 173 | + name: ${{ steps.fixture.outputs.name }} |
| 174 | + version: 1.2.3 |
| 175 | + commands: printf changed >> "$PACKAGE_TARBALL_PATH" |
| 176 | + - name: Assert - Smoke checks ran and rejected both failures |
| 177 | + env: |
| 178 | + SMOKE_OUTCOME: ${{ steps.smoke.outcome }} |
| 179 | + COMMAND_OUTCOME: ${{ steps.failing-command.outcome }} |
| 180 | + TARBALL_OUTCOME: ${{ steps.modified-tarball.outcome }} |
| 181 | + run: | |
| 182 | + test "$SMOKE_OUTCOME" = success |
| 183 | + test -f "$RUNNER_TEMP/release-smoke-ran" |
| 184 | + test "$COMMAND_OUTCOME" = failure |
| 185 | + test "$TARBALL_OUTCOME" = failure |
0 commit comments