1- name : Publish SDK to NPM
1+ name : Publish SDK to NPM and GitHub Package Registry
22
33on :
44 release :
77
88jobs :
99 publish :
10- name : Publish to NPM
10+ name : Publish to NPM and GitHub Package Registry
1111 runs-on : ubuntu-latest
1212 if : ${{ github.event_name == 'workflow_dispatch' || !github.event.release.draft }}
13+ permissions :
14+ contents : read
15+ packages : write
1316 steps :
1417 - name : Checkout branch
1518 uses : actions/checkout@v4
@@ -20,11 +23,19 @@ jobs:
2023 node-version : 18
2124 registry-url : " https://registry.npmjs.org/"
2225 always-auth : " true"
23- env :
24- NODE_AUTH_TOKEN : ${{ secrets.NPM_PUBLISH_TOKEN }}
2526
27+ # Add auth for the GitHub Package Registry publish. npm expands
28+ # ${NODE_AUTH_TOKEN} at runtime per-step, so each publish step uses the
29+ # right token for its registry. We do NOT route the @optimizely scope to
30+ # GPR, so `npm ci` still resolves dependencies from npm; publish.sh passes
31+ # --registry explicitly to target GPR.
32+ - name : Configure GitHub Package Registry auth
33+ run : echo "//npm.pkg.github.com/:_authToken=\${NODE_AUTH_TOKEN}" >> ~/.npmrc
34+
35+ # Deps only. --ignore-scripts stops `prepare` from building here; we build
36+ # exactly once in the pack step below.
2637 - name : Install dependencies
27- run : npm install
38+ run : npm ci --ignore-scripts
2839
2940 - id : latest-release
3041 name : Export latest release git tag
4253 run : |
4354 VERSION=$(jq -r '.version' package.json)
4455 LATEST_RELEASE_TAG="${{ steps.latest-release.outputs['latest-release-tag']}}"
45-
56+
4657 if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then
4758 RELEASE_TAG=${GITHUB_REF#refs/tags/}
4859 else
@@ -61,17 +72,29 @@ jobs:
6172 echo "npm-tag=v$(echo $VERSION | awk -F. '{print $1}')-latest" >> "$GITHUB_OUTPUT"
6273 fi
6374
75+ # Test, build, and pack a single tarball. Both registries publish this
76+ # same artifact, so npm and GPR receive byte-identical bytes and the test
77+ # suite runs only once. --ignore-scripts on pack avoids a rebuild.
78+ - id : pack
79+ name : Test, build, and pack
80+ run : |
81+ npm test
82+ npm run build
83+ tarball=$(npm pack --ignore-scripts | tail -n1)
84+ echo "tarball=$tarball" >> "$GITHUB_OUTPUT"
85+
6486 - id : release
65- name : Test, build and publish to npm
87+ name : Publish to NPM
6688 env :
67- BROWSERSTACK_USERNAME : ${{ secrets.BROWSERSTACK_USERNAME }}
68- BROWSERSTACK_ACCESS_KEY : ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
6989 NODE_AUTH_TOKEN : ${{ secrets.NPM_PUBLISH_TOKEN }}
70- run : |
71- if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then
72- DRY_RUN="--dry-run"
73- fi
74- npm publish --tag=${{ steps.npm-tag.outputs['npm-tag'] }} $DRY_RUN
90+ DRY_RUN : ${{ github.event_name == 'workflow_dispatch' }}
91+ run : scripts/publish.sh "https://registry.npmjs.org" "${{ steps.pack.outputs.tarball }}" "${{ steps.npm-tag.outputs['npm-tag'] }}"
92+
93+ - name : Publish to GitHub Package Registry
94+ env :
95+ NODE_AUTH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
96+ DRY_RUN : ${{ github.event_name == 'workflow_dispatch' }}
97+ run : scripts/publish.sh "https://npm.pkg.github.com" "${{ steps.pack.outputs.tarball }}" "${{ steps.npm-tag.outputs['npm-tag'] }}"
7598
7699 # - name: Report results to Jellyfish
77100 # uses: optimizely/jellyfish-deployment-reporter-action@main
0 commit comments