Added registry support to npm test.
This commit is contained in:
@@ -9,6 +9,14 @@ inputs:
|
|||||||
description: "Node.js version to use."
|
description: "Node.js version to use."
|
||||||
required: false
|
required: false
|
||||||
default: "20"
|
default: "20"
|
||||||
|
registries:
|
||||||
|
description: "Newline-separated list of registry URLs that require authentication."
|
||||||
|
required: false
|
||||||
|
default: "${{ github.server_url }}/api/packages/${{ github.repository_owner }}/npm/index.json"
|
||||||
|
apiKeys:
|
||||||
|
description: "Newline-separated list of API keys corresponding to registries."
|
||||||
|
required: false
|
||||||
|
default: "${{ github.token }}"
|
||||||
testCommand:
|
testCommand:
|
||||||
description: "Command to run tests. Default: npm test"
|
description: "Command to run tests. Default: npm test"
|
||||||
required: false
|
required: false
|
||||||
@@ -50,6 +58,12 @@ runs:
|
|||||||
node-version: ${{ inputs.nodeVersion }}
|
node-version: ${{ inputs.nodeVersion }}
|
||||||
cache: npm
|
cache: npm
|
||||||
cache-dependency-path: ${{ inputs.workingDirectory }}/package-lock.json
|
cache-dependency-path: ${{ inputs.workingDirectory }}/package-lock.json
|
||||||
|
- name: "Configure npm authentication"
|
||||||
|
if: ${{ inputs.registries != '' && inputs.apiKeys != '' }}
|
||||||
|
run: |
|
||||||
|
bash "${{ github.action_path }}/configure-auth.sh" add "${{ inputs.registries }}" "${{ inputs.apiKeys }}"
|
||||||
|
working-directory: ${{ inputs.workingDirectory }}
|
||||||
|
shell: bash
|
||||||
- name: "Install dependencies"
|
- name: "Install dependencies"
|
||||||
run: npm ci
|
run: npm ci
|
||||||
working-directory: ${{ inputs.workingDirectory }}
|
working-directory: ${{ inputs.workingDirectory }}
|
||||||
@@ -74,3 +88,9 @@ runs:
|
|||||||
path: ${{ inputs.workingDirectory }}/${{ inputs.coverageDirectory }}
|
path: ${{ inputs.workingDirectory }}/${{ inputs.coverageDirectory }}
|
||||||
if-no-files-found: warn
|
if-no-files-found: warn
|
||||||
retention-days: ${{ inputs.retention-days }}
|
retention-days: ${{ inputs.retention-days }}
|
||||||
|
- name: "Clean up npm authentication"
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
bash "${{ github.action_path }}/configure-auth.sh" remove
|
||||||
|
working-directory: ${{ inputs.workingDirectory }}
|
||||||
|
shell: bash
|
||||||
|
|||||||
42
npm/npm-test/configure-auth.sh
Normal file
42
npm/npm-test/configure-auth.sh
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
ACTION="$1"
|
||||||
|
AUTH_URLS="$2"
|
||||||
|
API_KEYS="$3"
|
||||||
|
|
||||||
|
if [ "$ACTION" == "add" ]; then
|
||||||
|
# Parse newline-separated URLs and tokens into arrays
|
||||||
|
IFS=$'\n' read -rd '' -a URLS <<< "$AUTH_URLS" || true
|
||||||
|
IFS=$'\n' read -rd '' -a KEYS <<< "$API_KEYS" || true
|
||||||
|
|
||||||
|
# Verify arrays have matching lengths
|
||||||
|
if [ ${#URLS[@]} -ne ${#KEYS[@]} ]; then
|
||||||
|
echo "Error: Number of authUrls (${#URLS[@]}) does not match number of apiKeys (${#KEYS[@]})"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Configure authentication for each registry
|
||||||
|
for i in "${!URLS[@]}"; do
|
||||||
|
URL="${URLS[$i]}"
|
||||||
|
KEY="${KEYS[$i]}"
|
||||||
|
|
||||||
|
# Skip empty entries
|
||||||
|
if [ -z "$URL" ] || [ -z "$KEY" ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove protocol from URL for npm config
|
||||||
|
REGISTRY_PATH=$(echo "$URL" | sed -E 's|https?://||')
|
||||||
|
|
||||||
|
echo "Configuring authentication for: $URL"
|
||||||
|
npm config set --location=project "//${REGISTRY_PATH}:_authToken" "$KEY"
|
||||||
|
done
|
||||||
|
elif [ "$ACTION" == "remove" ]; then
|
||||||
|
# Clean up project .npmrc
|
||||||
|
rm -f .npmrc
|
||||||
|
echo "Removed npm authentication configuration"
|
||||||
|
else
|
||||||
|
echo "Error: Invalid action '$ACTION'. Use 'add' or 'remove'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user