Repository navigation
88 lines (77 loc) · 3.5 KB
/
Copy pathrelease.yml
File metadata and controls
88 lines (77 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: Publish SDK to NPM and GitHub Package Registry
on:
release:
types: [published, edited]
workflow_dispatch: {}
permissions:
id-token: write
contents: read
packages: write
jobs:
publish:
name: Publish to NPM and GitHub Package Registry
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' || !github.event.release.draft }}
environment: npm
steps:
- name: Checkout branch
uses: actions/checkout@v7
with:
persist-credentials: false
# The Node version in .nvmrc and npm 12 (new enough for OIDC trusted
# publishing), with the .npmrc supply-chain settings. cache: '' means no
# npm cache, so nothing from an earlier run (e.g. a pull request) can
# affect what gets published.
- name: Set up Node and npm
uses: ./.github/actions/setup-node-npm
with:
cache: ''
# Configure auth for GHR only. npm registry auth is handled by OIDC
# (no .npmrc token entry needed — omitting registry-url from setup-node
# ensures npm falls through to OIDC for registry.npmjs.org).
- name: Configure GitHub Package Registry auth
run: echo "//npm.pkg.github.com/:_authToken=\${NODE_AUTH_TOKEN}" >> ~/.npmrc
# Deps only. --ignore-scripts stops `prepare` from building here; we build
# exactly once in the pack step below.
- name: Install dependencies
run: npm ci --ignore-scripts
# Don't build the published artifact from packages whose registry
# signatures don't verify.
- name: Verify package signatures
run: npm audit signatures
# Test, build, and pack a single tarball. Both registries publish this
# same artifact, so npm and GHR receive byte-identical bytes and the test
# suite runs only once. --ignore-scripts on pack avoids a rebuild.
- id: pack
name: Test, build, and pack
run: |
npm test
npm run build
tarball=$(npm pack --ignore-scripts | tail -n1)
echo "tarball=$tarball" >> "$GITHUB_OUTPUT"
# publish.sh derives name/version from the tarball and computes the
# dist-tag itself: `latest` only when strictly newer than the registry's
# current latest, otherwise v<major>-last-published; beta/alpha/rc for
# pre-releases. npm publishes first; if it fails the job stops before GHR,
# keeping the registries in sync.
#
# npm publish uses OIDC trusted publishing (no NPM_PUBLISH_TOKEN needed).
# publish.sh adds --provenance for supply-chain attestations.
- id: release
name: Publish to NPM
env:
TARBALL: ${{ steps.pack.outputs.tarball }}
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' }}
run: scripts/publish.sh "https://registry.npmjs.org" "$TARBALL"
- name: Publish to GitHub Package Registry
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TARBALL: ${{ steps.pack.outputs.tarball }}
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' }}
run: scripts/publish.sh "https://npm.pkg.github.com" "$TARBALL"
# - name: Report results to Jellyfish
# uses: optimizely/jellyfish-deployment-reporter-action@main
# if: ${{ always() && github.event_name == 'release' && (steps.release.outcome == 'success' || steps.release.outcome == 'failure') }}
# with:
# jellyfish_api_token: ${{ secrets.JELLYFISH_API_TOKEN }}
# is_successful: ${{ steps.release.outcome == 'success' }}