|
| 1 | +# release flow: |
| 2 | +# 1. tag v* on main triggers this workflow |
| 3 | +# 2. build job produces a tarball + slsa provenance via the slsa-github-generator |
| 4 | +# reusable workflow (which runs in an isolated builder, not in our repo's runner) |
| 5 | +# 3. publish job uses npm trusted publisher (oidc) to publish with --provenance |
| 6 | +# 4. sign job runs cosign sign-blob keylessly, identity = this workflow |
| 7 | +# |
| 8 | +# secrets used: none. there is no NPM_TOKEN. credentials are minted via oidc per run. |
| 9 | + |
| 10 | +name: release |
| 11 | + |
| 12 | +on: |
| 13 | + push: |
| 14 | + tags: ["v*"] |
| 15 | + workflow_dispatch: |
| 16 | + |
| 17 | +permissions: {} |
| 18 | + |
| 19 | +jobs: |
| 20 | + build: |
| 21 | + name: build tarball + slsa provenance |
| 22 | + runs-on: ubuntu-latest |
| 23 | + permissions: |
| 24 | + contents: read |
| 25 | + id-token: write |
| 26 | + outputs: |
| 27 | + tarball-name: ${{ steps.pack.outputs.tarball-name }} |
| 28 | + tarball-sha256: ${{ steps.pack.outputs.tarball-sha256 }} |
| 29 | + steps: |
| 30 | + - name: harden runner |
| 31 | + uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2 |
| 32 | + with: |
| 33 | + egress-policy: audit |
| 34 | + |
| 35 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 36 | + with: |
| 37 | + persist-credentials: false |
| 38 | + |
| 39 | + - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6 |
| 40 | + with: |
| 41 | + node-version: 24 |
| 42 | + cache: npm |
| 43 | + registry-url: https://registry.npmjs.org |
| 44 | + |
| 45 | + - name: install (locked, no scripts) |
| 46 | + run: npm ci --ignore-scripts |
| 47 | + |
| 48 | + - name: build |
| 49 | + run: npm run build |
| 50 | + |
| 51 | + - name: pack |
| 52 | + id: pack |
| 53 | + run: | |
| 54 | + set -euo pipefail |
| 55 | + tarball=$(npm pack --silent | tail -n 1) |
| 56 | + sha=$(shasum -a 256 "$tarball" | awk '{print $1}') |
| 57 | + echo "tarball-name=$tarball" >>"$GITHUB_OUTPUT" |
| 58 | + echo "tarball-sha256=$sha" >>"$GITHUB_OUTPUT" |
| 59 | +
|
| 60 | + - name: upload tarball |
| 61 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 |
| 62 | + with: |
| 63 | + name: tarball |
| 64 | + path: ${{ steps.pack.outputs.tarball-name }} |
| 65 | + if-no-files-found: error |
| 66 | + retention-days: 7 |
| 67 | + |
| 68 | + provenance: |
| 69 | + name: slsa v1.0 provenance |
| 70 | + needs: [build] |
| 71 | + permissions: |
| 72 | + actions: read |
| 73 | + contents: read |
| 74 | + id-token: write |
| 75 | + uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@f7dd8c54c2067bafc12ca7a55595d5ee9b75204a # v2.1.0 |
| 76 | + with: |
| 77 | + base64-subjects: ${{ needs.build.outputs.tarball-sha256 }} |
| 78 | + provenance-name: ${{ needs.build.outputs.tarball-name }}.intoto.jsonl |
| 79 | + upload-assets: true |
| 80 | + |
| 81 | + publish: |
| 82 | + name: npm trusted publisher (--provenance) |
| 83 | + needs: [build, provenance] |
| 84 | + runs-on: ubuntu-latest |
| 85 | + environment: release |
| 86 | + permissions: |
| 87 | + contents: read |
| 88 | + id-token: write |
| 89 | + steps: |
| 90 | + - name: harden runner |
| 91 | + uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2 |
| 92 | + with: |
| 93 | + egress-policy: audit |
| 94 | + |
| 95 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 96 | + with: |
| 97 | + persist-credentials: false |
| 98 | + |
| 99 | + - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6 |
| 100 | + with: |
| 101 | + node-version: 24 |
| 102 | + registry-url: https://registry.npmjs.org |
| 103 | + |
| 104 | + - name: download tarball |
| 105 | + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 |
| 106 | + with: |
| 107 | + name: tarball |
| 108 | + |
| 109 | + - name: publish |
| 110 | + run: npm publish "${{ needs.build.outputs.tarball-name }}" --provenance --access public |
| 111 | + |
| 112 | + sign: |
| 113 | + name: cosign sign-blob (keyless) |
| 114 | + needs: [build, publish] |
| 115 | + runs-on: ubuntu-latest |
| 116 | + permissions: |
| 117 | + contents: write |
| 118 | + id-token: write |
| 119 | + steps: |
| 120 | + - uses: sigstore/cosign-installer@cad07c2e89fa2edd6e2d7bab4c1aa38e53f76003 # v4.1.1 |
| 121 | + |
| 122 | + - name: download tarball |
| 123 | + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 |
| 124 | + with: |
| 125 | + name: tarball |
| 126 | + |
| 127 | + - name: sign |
| 128 | + run: | |
| 129 | + cosign sign-blob --yes \ |
| 130 | + --output-signature "${{ needs.build.outputs.tarball-name }}.sig" \ |
| 131 | + --output-certificate "${{ needs.build.outputs.tarball-name }}.crt" \ |
| 132 | + "${{ needs.build.outputs.tarball-name }}" |
| 133 | +
|
| 134 | + - name: attach signature to release |
| 135 | + uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3 |
| 136 | + with: |
| 137 | + files: | |
| 138 | + ${{ needs.build.outputs.tarball-name }}.sig |
| 139 | + ${{ needs.build.outputs.tarball-name }}.crt |
0 commit comments