feat(npm): support a private registry token

This commit is contained in:
2026-10-03 22:44:30 +01:00
parent 2e49670452
commit caaad0efab
3 changed files with 80 additions and 2 deletions
+29
View File
@@ -36,11 +36,25 @@ on:
required: false
type: boolean
default: false
npm-registry-scope:
description: "Scope served by a private npm registry, for example '@fortawesome'. Used only when npm-registry-url and the npm-registry-token secret are also set."
required: false
type: string
default: ""
npm-registry-url:
description: "URL of the private npm registry, for example 'https://npm.fontawesome.com/'. Used only when npm-registry-scope and the npm-registry-token secret are also set."
required: false
type: string
default: ""
runner:
description: "Runner label, or JSON object such as {\"group\":\"ci\",\"labels\":[\"linux\"]} to select a runner group. Falls back to vars.SHARED_ACTIONS_RUNNER, then ubuntu-latest."
required: false
type: string
default: ""
secrets:
npm-registry-token:
description: "Auth token for the private npm registry"
required: false
concurrency:
group: node-pr-${{ github.repository }}-${{ github.event_name }}-${{ github.head_ref || github.ref_name }}-${{ inputs.working-directory }}
@@ -120,6 +134,21 @@ jobs:
with:
node-version: ${{ inputs.node-version }}
# The npmrc lives in RUNNER_TEMP, not the checkout, so no git command can pick the token up.
- name: Configure the private npm registry
env:
NPM_SCOPE: ${{ inputs.npm-registry-scope }}
NPM_URL: ${{ inputs.npm-registry-url }}
NPM_TOKEN: ${{ secrets.npm-registry-token }}
run: |
[ -n "$NPM_SCOPE" ] && [ -n "$NPM_URL" ] && [ -n "$NPM_TOKEN" ] || exit 0
echo "::add-mask::$NPM_TOKEN"
url="${NPM_URL%/}/"
npmrc="$RUNNER_TEMP/private-registry.npmrc"
(umask 077 && printf '%s:registry=%s\n//%s:_authToken=%s\n' "$NPM_SCOPE" "$url" "${url#*://}" "$NPM_TOKEN" > "$npmrc")
echo "NPM_CONFIG_USERCONFIG=$npmrc" >> "$GITHUB_ENV"
echo "Using a private npm registry for $NPM_SCOPE."
- name: Install dependencies
working-directory: ${{ inputs.working-directory }}
env: