Skip to content

Commit e68e5db

Browse files
publish-npm: make npm_registry and npm_publish_token optional for trusted publishers support
1 parent 560bd36 commit e68e5db

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

publish-npm/action.yml

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,40 @@ inputs:
77
description: "NPM package path"
88
npm_registry:
99
description: "NPM registry"
10+
required: false
1011
npm_publish_token:
1112
description: "Publish token"
13+
required: false
1214
outputs:
1315
version:
1416
description: "version"
1517
value: ${{ steps.publish_npm.outputs.version }}
1618
runs:
1719
using: "composite"
1820
steps:
19-
- name: Setup Node
20-
uses: actions/setup-node@v4
21-
with:
22-
node-version: 20.15.1
21+
- name: Ensure required NPM version for Trusted Publishers
22+
if: ${{ inputs.npm_publish_token == '' }}
23+
id: npm_setup
24+
shell: bash
25+
run: |
26+
required_version="11.5.1"
27+
current_version=$(npm --version)
28+
if npx semver "$current_version" -r "<$required_version" >/dev/null 2>&1; then
29+
echo "Upgrading npm from $current_version to $required_version"
30+
npm install -g npm@$required_version
31+
echo "previous_version=$current_version" >> $GITHUB_OUTPUT
32+
fi
2333
- name: Publish NPM
2434
shell: bash
2535
working-directory: ${{ inputs.npm_package_path }}
2636
id: publish_npm
2737
run: |
28-
echo "//${{ inputs.npm_registry }}/:_authToken=${{ inputs.npm_publish_token }}" >> .npmrc
29-
echo "@raycast:registry=https://${{ inputs.npm_registry }}" >> .npmrc
38+
if [[ -n "${{ inputs.npm_registry }}" ]]; then
39+
if [[ -n "${{ inputs.npm_publish_token }}" ]]; then
40+
echo "//${{ inputs.npm_registry }}/:_authToken=${{ inputs.npm_publish_token }}" >> .npmrc
41+
fi
42+
echo "@raycast:registry=https://${{ inputs.npm_registry }}" >> .npmrc
43+
fi
3044
3145
version=`jq -r .version package.json`
3246
name=`jq -r .name package.json`
@@ -36,8 +50,14 @@ runs:
3650
echo "Registry version: $public_version"
3751
3852
if [[ "$version" != "$public_version" ]]; then
39-
npm publish
53+
npm publish --tag latest
4054
echo "version=$version" >> $GITHUB_OUTPUT
4155
else
4256
echo "Skipping API publishing"
4357
fi
58+
- name: Restore previous NPM version
59+
if: ${{ steps.npm_setup.outputs.previous_version != '' }}
60+
shell: bash
61+
run: |
62+
echo "Restoring npm to previous version ${{ steps.npm_setup.outputs.previous_version }}"
63+
npm install -g npm@${{ steps.npm_setup.outputs.previous_version }}

0 commit comments

Comments
 (0)