npm ci fails with E401 when a consuming repo's package-lock.json pins a package to the private Gitea npm registry, since these composite actions never write an .npmrc or set a registry auth token. Add an optional NPM_TOKEN input that writes .npmrc before install; existing consumers that don't pass it are unaffected.
57 lines
1.8 KiB
YAML
57 lines
1.8 KiB
YAML
name: NPM Test
|
|
description: Install dependencies and run npm tests
|
|
|
|
inputs:
|
|
INSTALL_CMD:
|
|
description: "Install command"
|
|
default: "npm ci"
|
|
TEST_SCRIPT:
|
|
description: "npm script to run (must exist in package.json)"
|
|
default: "test"
|
|
TEST_ARGS:
|
|
description: "Additional arguments to pass after -- to the test script"
|
|
default: ""
|
|
WORKING_DIRECTORY:
|
|
description: "Directory to run commands in"
|
|
default: "."
|
|
NPM_TOKEN:
|
|
description: "Auth token for the private Gitea npm registry (@stat-tackler scope). Leave empty if the repo installs no private packages."
|
|
default: ""
|
|
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- uses: actions/setup-node@v5
|
|
with:
|
|
node-version-file: package.json
|
|
|
|
- name: Cache node_modules
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ${{ inputs.WORKING_DIRECTORY }}/node_modules
|
|
key: node-modules-${{ hashFiles(format('{0}/package-lock.json', inputs.WORKING_DIRECTORY)) }}
|
|
restore-keys: node-modules-
|
|
|
|
- name: Configure private registry auth
|
|
if: inputs.NPM_TOKEN != ''
|
|
shell: sh
|
|
working-directory: ${{ inputs.WORKING_DIRECTORY }}
|
|
run: |
|
|
printf '%s\n%s\n' \
|
|
'@stat-tackler:registry=https://gitea.pixelparasol.com/api/packages/stat-tackler/npm/' \
|
|
'//gitea.pixelparasol.com/api/packages/stat-tackler/npm/:_authToken=${{ inputs.NPM_TOKEN }}' \
|
|
>> .npmrc
|
|
|
|
- name: Install
|
|
shell: sh
|
|
working-directory: ${{ inputs.WORKING_DIRECTORY }}
|
|
run: ${{ inputs.INSTALL_CMD }}
|
|
|
|
- name: Test
|
|
shell: sh
|
|
working-directory: ${{ inputs.WORKING_DIRECTORY }}
|
|
run: npm run ${{ inputs.TEST_SCRIPT }}${{ inputs.TEST_ARGS != '' && format(' -- {0}', inputs.TEST_ARGS) || '' }}
|