Skip to content

Commit 6066de2

Browse files
maximizeITGitHub Copilot
andcommitted
fix(ci): pass expanded auth token to Yarn's npmrc for GitHub Packages
actions/setup-node writes `${NODE_AUTH_TOKEN}` as a literal placeholder into the temp npmrc it creates (NPM_CONFIG_USERCONFIG). npm expands env-var references from .npmrc; Yarn classic does NOT. Yarn therefore sent the string '${NODE_AUTH_TOKEN}' as the Bearer token → 401 on npm.pkg.github.com. Fix: before `yarn install`, append the bash-expanded token to the file that NPM_CONFIG_USERCONFIG points to. The previous attempt wrote to ~/.npmrc instead, which Yarn never reads when NPM_CONFIG_USERCONFIG is set. Co-authored-by: GitHub Copilot <copilot@noreply.github.com>
1 parent 84d92a3 commit 6066de2

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@ jobs:
2323
registry-url: 'https://npm.pkg.github.com/'
2424
scope: '@staffbase'
2525

26+
- name: Configure GitHub Packages auth for Yarn
27+
# actions/setup-node writes `${NODE_AUTH_TOKEN}` literally into the temp npmrc;
28+
# Yarn classic does NOT expand env-var placeholders from npmrc files (unlike npm).
29+
# Appending the already-expanded token to the same file that NPM_CONFIG_USERCONFIG
30+
# points to is the reliable fix.
31+
run: echo "//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}" >> "$NPM_CONFIG_USERCONFIG"
32+
env:
33+
NODE_AUTH_TOKEN: ${{ secrets.STAFFBOT_NPM_READ }}
34+
2635
- name: Install Yarn Dependencies
2736
working-directory: samples/weather-forecast
2837
run: yarn install --frozen-lockfile
29-
env:
30-
NODE_AUTH_TOKEN: ${{ secrets.STAFFBOT_NPM_READ }}
3138

3239
- name: Run Build
3340
working-directory: samples/weather-forecast

0 commit comments

Comments
 (0)