55 dry_run :
66 description : Dry run will not publish to npm, just test it.
77 required : true
8- package :
9- description : npm package name.
10- required : true
11- scope :
12- description : npm package scope (must not include '@' prefix).
8+ package_dir :
9+ description : directory containing the package.json file.
1310 required : true
1411 tag :
1512 description : npm package tag.
@@ -26,40 +23,53 @@ inputs:
2623runs :
2724 using : " composite"
2825 steps :
26+ - uses : actions/setup-node@v6
27+ with :
28+ node-version : " lts/*"
29+ package-manager-cache : " false"
30+ # Note: setting up the registry allows auth to be passed via env.NODE_AUTH_TOKEN
31+ registry-url : https://registry.npmjs.org
32+
33+ - name : Prepare
34+ id : prepare
35+ shell : bash
36+ run : |
37+ echo "package_name=$(jq -r ".name" < "${{ inputs.package_dir }}"/package.json)" >> $GITHUB_OUTPUT
38+ echo "package_local_version=$(jq -r ".version" < "${{ inputs.package_dir }}"/package.json)" >> $GITHUB_OUTPUT
39+
2940 - name : Check npm latest version
3041 id : check_version
3142 shell : bash
3243 run : |
33- echo "Check crate latest published version for '${{ inputs.package }}' package"
44+ echo "Check npmjs.com latest published version for '${{ steps.prepare.outputs.package_name }}' package"
3445
3546 if [ "${{ inputs.tag }}" != "latest" -a "${{ inputs.tag }}" != "next" ]; then
3647 echo "Tag '${{ inputs.tag }}' is not valid. It should be one of 'latest' or 'next'"
3748 exit 1
3849 fi
3950
40- LOCAL_VERSION=$(cat ${{ inputs.package }}/package.json | jq -r '.version')
41- NEXT_REMOTE_VERSION=$(npm view @${{ inputs.scope }}/${{ inputs.package }} dist-tags.next 2> /dev/null || true)
42- LATEST_REMOTE_VERSION=$(npm view @${{ inputs.scope }}/${{ inputs.package }} dist-tags.latest 2> /dev/null || true)
51+ NEXT_REMOTE_VERSION=$(npm view ${{ steps.prepare.outputs.package_name }} dist-tags.next 2> /dev/null || true)
52+ LATEST_REMOTE_VERSION=$(npm view ${{ steps.prepare.outputs.package_name }} dist-tags.latest 2> /dev/null || true)
4353
44- echo "Latest crate.io version: '$LATEST_REMOTE_VERSION'"
45- echo "Next crate.io version: '$NEXT_REMOTE_VERSION'"
46- echo "Local version: '$LOCAL_VERSION '"
54+ echo "Latest npmjs.com version: '$LATEST_REMOTE_VERSION'"
55+ echo "Next npmjs.com version: '$NEXT_REMOTE_VERSION'"
56+ echo "Local version: '${{ steps.prepare.outputs.package_local_version }} '"
4757
4858 if [ "${{ inputs.tag }}" == "latest" ]; then
49- if [ "$LOCAL_VERSION " == "$LATEST_REMOTE_VERSION" ]; then
59+ if [ "${{ steps.prepare.outputs.package_local_version }} " == "$LATEST_REMOTE_VERSION" ]; then
5060 echo "Local version and remote version are the same: no need to publish to npm registry"
5161 DEPLOY_MODE='none'
52- elif [ "$LOCAL_VERSION " == "$NEXT_REMOTE_VERSION" ]; then
62+ elif [ "${{ steps.prepare.outputs.package_local_version }} " == "$NEXT_REMOTE_VERSION" ]; then
5363 DEPLOY_MODE='promote'
5464 else
5565 DEPLOY_MODE='publish'
5666 fi
5767 else # input.tag == 'next'
58- if [ "$LOCAL_VERSION " == "$LATEST_REMOTE_VERSION" ]; then
68+ if [ "${{ steps.prepare.outputs.package_local_version }} " == "$LATEST_REMOTE_VERSION" ]; then
5969 # A latest already published: no need to tag with next
6070 echo "Local version and remote version are the same: no need to publish to npm registry"
6171 DEPLOY_MODE='none'
62- elif [ "$LOCAL_VERSION " == "$NEXT_REMOTE_VERSION" ]; then
72+ elif [ "${{ steps.prepare.outputs.package_local_version }} " == "$NEXT_REMOTE_VERSION" ]; then
6373 echo "Local version and remote version are the same: no need to publish to npm registry"
6474 DEPLOY_MODE='none'
6575 else
@@ -70,43 +80,43 @@ runs:
7080 echo "Deploy mode: '$DEPLOY_MODE'"
7181 echo "Dry run: '${{ inputs.dry_run }}'"
7282 echo "deploy_mode=$DEPLOY_MODE" >> $GITHUB_OUTPUT
73- echo "package_version=$LOCAL_VERSION" >> $GITHUB_OUTPUT
7483
7584 - name : Build package
7685 shell : bash
77- working-directory : ${{ inputs.package }}
86+ working-directory : ${{ inputs.package_dir }}
7887 env :
79- WASM_PACK_ARGS : --release --scope ${{ inputs.scope }}
88+ WASM_PACK_ARGS : --release
8089 run : |
81- echo "Build '@ ${{ inputs.scope }}/${{ inputs.package }}' package"
90+ echo "::group:: Build '${{ steps.prepare.outputs.package_name }}' package"
8291 make build
92+ echo "::endgroup::"
8393
8494 - name : Prepare publish
8595 shell : bash
8696 run : |
87- cp ./LICENSE ${{ inputs.package }}
88- cp -f ${{ inputs.package }}/npm/README.md ${{ inputs.package }}/
97+ cp ./LICENSE ${{ inputs.package_dir }}
98+ cp -f ${{ inputs.package_dir }}/npm/README.md ${{ inputs.package_dir }}/
8999
90100 - name : List package
91101 shell : bash
92102 run : |
93- echo "List '@ ${{ inputs.scope }}/${{ inputs.package }}' package"
94- ls -al -R ${{ inputs.package }}/dist
103+ echo "List '${{ steps.prepare.outputs.package_name }}' package"
104+ ls -al -R ${{ inputs.package_dir }}/dist
95105
96106 - name : Publish package new version
97107 if : steps.check_version.outputs.deploy_mode == 'publish'
98108 shell : bash
109+ working-directory : ${{ inputs.package_dir }}
99110 env :
100- NPM_TOKEN : ${{ inputs.api_token }}
111+ NODE_AUTH_TOKEN : ${{ inputs.api_token }}
101112 run : |
102- echo "Publish '@${{ inputs.scope }}/${{ inputs.package }}' package"
103- npm set "//registry.npmjs.org/:_authToken=${NPM_TOKEN}"
104- if [ -z "${NPM_TOKEN}" -a "${{ inputs.dry_run }}" == "true" ]; then
113+ echo "Publish '${{ steps.prepare.outputs.package_name }}' package"
114+ if [ -z "${NODE_AUTH_TOKEN}" -a "${{ inputs.dry_run }}" == "true" ]; then
105115 echo "Warning: An NPM access token is required for authentication and has not been provided."
106116 else
107117 npm whoami
108118 fi
109- cd ${{ inputs.package }}/
119+
110120 if [ "${{ inputs.dry_run }}" == "false" ]; then
111121 dry_run_option=""
112122 else
@@ -115,14 +125,18 @@ runs:
115125 npm publish --tag ${{ inputs.tag }} --access ${{ inputs.access }} $dry_run_option
116126
117127 - name : Promote package distribution tag to 'latest'
118- if : inputs.dry_run == 'false' && steps.check_version.outputs.deploy_mode == 'promote'
128+ if : steps.check_version.outputs.deploy_mode == 'promote'
119129 shell : bash
130+ working-directory : ${{ inputs.package_dir }}
120131 env :
121- NPM_TOKEN : ${{ inputs.api_token }}
132+ NODE_AUTH_TOKEN : ${{ inputs.api_token }}
122133 run : |
123- echo "Publish '@${{ inputs.scope }}/${{ inputs.package }}' package"
124- npm set "//registry.npmjs.org/:_authToken=${NPM_TOKEN}"
125- npm whoami
126- cd ${{ inputs.package }}/
127- npm dist-tag add @${{ inputs.scope }}/${{ inputs.package }}@${{ steps.check_version.outputs.package_version }} latest
128- npm dist-tag rm @${{ inputs.scope }}/${{ inputs.package }}@${{ steps.check_version.outputs.package_version }} next
134+ echo "Promote '${{ steps.prepare.outputs.package_name }}' package version '${{ steps.prepare.outputs.package_local_version }}' from 'next' to 'latest'"
135+ if [ "${{ inputs.dry_run }}" == "false" ]; then
136+ npm whoami
137+ npm dist-tag add ${{ steps.prepare.outputs.package_name }}"@${{ steps.prepare.outputs.package_local_version }} latest
138+ npm dist-tag rm ${{ steps.prepare.outputs.package_name }}"@${{ steps.prepare.outputs.package_local_version }} next
139+ else
140+ echo "Dry run: npm dist-tag add ${{ steps.prepare.outputs.package_name }}"@${{ steps.prepare.outputs.package_local_version }} latest
141+ echo "Dry run: npm dist-tag rm ${{ steps.prepare.outputs.package_name }}"@${{ steps.prepare.outputs.package_local_version }} next
142+ fi
0 commit comments