This commit is contained in:
2026-01-01 19:21:04 -08:00
parent 7b9d69e0ad
commit cbf662b8be

View File

@@ -26,27 +26,17 @@ runs:
uses: https://github.com/actions/setup-node@v4 uses: https://github.com/actions/setup-node@v4
with: with:
node-version: ${{ inputs.nodeVersion }} node-version: ${{ inputs.nodeVersion }}
registry-url: ${{ inputs.registry }}
- name: "Publish package" - name: "Publish package"
env:
NODE_AUTH_TOKEN: ${{ inputs.apiKey }}
run: | run: |
# Ensure path starts with ./ so npm recognizes it as a file path # Ensure path starts with ./ so npm recognizes it as a file path
TGZ_PATH="${{ inputs.tgz }}" TGZ_PATH="${{ inputs.tgz }}"
if [[ ! "$TGZ_PATH" =~ ^[./~] ]]; then if [[ ! "$TGZ_PATH" =~ ^[./~] ]]; then
TGZ_PATH="./$TGZ_PATH" TGZ_PATH="./$TGZ_PATH"
fi fi
# Configure npm authentication for the registry (scoped to project)
REGISTRY_HOST=$(echo "${{ inputs.registry }}" | sed -E 's|https?://([^/]+).*|\1|')
npm config set --location=project "//${REGISTRY_HOST}/:_authToken" "${{ inputs.apiKey }}"
npm config set --location=project registry "${{ inputs.registry }}"
echo "Publishing $TGZ_PATH to ${{ inputs.registry }}" echo "Publishing $TGZ_PATH to ${{ inputs.registry }}"
npm publish --location=project "$TGZ_PATH" --access ${{ inputs.access }} npm publish "$TGZ_PATH" --registry ${{ inputs.registry }} --access ${{ inputs.access }}
echo "Package published successfully" echo "Package published successfully"
shell: bash shell: bash
- name: "Clean up npm authentication"
if: always()
run: |
# Clean up project .npmrc in case of early exit
rm -f .npmrc
shell: bash