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 .
8+ package_dir :
9+ description : directory containing the package.json file .
1010 required : true
1111 scope :
1212 description : npm package scope (must not include '@' prefix).
@@ -26,40 +26,46 @@ inputs:
2626runs :
2727 using : " composite"
2828 steps :
29+ - name : Prepare
30+ id : prepare
31+ shell : bash
32+ run : |
33+ echo "package_name=$(jq -r ".name" < "${{ inputs.package_dir }}"/package.json)" >> $GITHUB_OUTPUT
34+ echo "package_local_version=$(jq -r ".version" < "${{ inputs.package_dir }}"/package.json)" >> $GITHUB_OUTPUT
35+
2936 - name : Check npm latest version
3037 id : check_version
3138 shell : bash
3239 run : |
33- echo "Check crate latest published version for '${{ inputs.package }}' package"
40+ echo "Check npmjs.com latest published version for '${{ steps.prepare.outputs.package_name }}' package"
3441
3542 if [ "${{ inputs.tag }}" != "latest" -a "${{ inputs.tag }}" != "next" ]; then
3643 echo "Tag '${{ inputs.tag }}' is not valid. It should be one of 'latest' or 'next'"
3744 exit 1
3845 fi
3946
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)
47+ NEXT_REMOTE_VERSION=$(npm view ${{ steps.prepare.outputs.package_name }} dist-tags.next 2> /dev/null || true)
48+ LATEST_REMOTE_VERSION=$(npm view ${{ steps.prepare.outputs.package_name }} dist-tags.latest 2> /dev/null || true)
4349
44- echo "Latest crate.io version: '$LATEST_REMOTE_VERSION'"
45- echo "Next crate.io version: '$NEXT_REMOTE_VERSION'"
46- echo "Local version: '$LOCAL_VERSION '"
50+ echo "Latest npmjs.com version: '$LATEST_REMOTE_VERSION'"
51+ echo "Next npmjs.com version: '$NEXT_REMOTE_VERSION'"
52+ echo "Local version: '${{ steps.prepare.outputs.package_local_version }} '"
4753
4854 if [ "${{ inputs.tag }}" == "latest" ]; then
49- if [ "$LOCAL_VERSION " == "$LATEST_REMOTE_VERSION" ]; then
55+ if [ "${{ steps.prepare.outputs.package_local_version }} " == "$LATEST_REMOTE_VERSION" ]; then
5056 echo "Local version and remote version are the same: no need to publish to npm registry"
5157 DEPLOY_MODE='none'
52- elif [ "$LOCAL_VERSION " == "$NEXT_REMOTE_VERSION" ]; then
58+ elif [ "${{ steps.prepare.outputs.package_local_version }} " == "$NEXT_REMOTE_VERSION" ]; then
5359 DEPLOY_MODE='promote'
5460 else
5561 DEPLOY_MODE='publish'
5662 fi
5763 else # input.tag == 'next'
58- if [ "$LOCAL_VERSION " == "$LATEST_REMOTE_VERSION" ]; then
64+ if [ "${{ steps.prepare.outputs.package_local_version }} " == "$LATEST_REMOTE_VERSION" ]; then
5965 # A latest already published: no need to tag with next
6066 echo "Local version and remote version are the same: no need to publish to npm registry"
6167 DEPLOY_MODE='none'
62- elif [ "$LOCAL_VERSION " == "$NEXT_REMOTE_VERSION" ]; then
68+ elif [ "${{ steps.prepare.outputs.package_local_version }} " == "$NEXT_REMOTE_VERSION" ]; then
6369 echo "Local version and remote version are the same: no need to publish to npm registry"
6470 DEPLOY_MODE='none'
6571 else
@@ -70,43 +76,43 @@ runs:
7076 echo "Deploy mode: '$DEPLOY_MODE'"
7177 echo "Dry run: '${{ inputs.dry_run }}'"
7278 echo "deploy_mode=$DEPLOY_MODE" >> $GITHUB_OUTPUT
73- echo "package_version=$LOCAL_VERSION" >> $GITHUB_OUTPUT
7479
7580 - name : Build package
7681 shell : bash
77- working-directory : ${{ inputs.package }}
82+ working-directory : ${{ inputs.package_dir }}
7883 env :
7984 WASM_PACK_ARGS : --release --scope ${{ inputs.scope }}
8085 run : |
81- echo "Build '@ ${{ inputs.scope }}/${{ inputs.package }}' package"
86+ echo "Build '${{ steps.prepare.outputs.package_name }}' package"
8287 make build
8388
8489 - name : Prepare publish
8590 shell : bash
8691 run : |
87- cp ./LICENSE ${{ inputs.package }}
88- cp -f ${{ inputs.package }}/npm/README.md ${{ inputs.package }}/
92+ cp ./LICENSE ${{ inputs.package_dir }}
93+ cp -f ${{ inputs.package_dir }}/npm/README.md ${{ inputs.package_dir }}/
8994
9095 - name : List package
9196 shell : bash
9297 run : |
93- echo "List '@ ${{ inputs.scope }}/${{ inputs.package }}' package"
94- ls -al -R ${{ inputs.package }}/dist
98+ echo "List '${{ steps.prepare.outputs.package_name }}' package"
99+ ls -al -R ${{ inputs.package_dir }}/dist
95100
96101 - name : Publish package new version
97102 if : steps.check_version.outputs.deploy_mode == 'publish'
98103 shell : bash
104+ working-directory : ${{ inputs.package_dir }}
99105 env :
100106 NPM_TOKEN : ${{ inputs.api_token }}
101107 run : |
102- echo "Publish '@ ${{ inputs.scope }}/${{ inputs.package }}' package"
108+ echo "Publish '${{ steps.prepare.outputs.package_name }}' package"
103109 npm set "//registry.npmjs.org/:_authToken=${NPM_TOKEN}"
104110 if [ -z "${NPM_TOKEN}" -a "${{ inputs.dry_run }}" == "true" ]; then
105111 echo "Warning: An NPM access token is required for authentication and has not been provided."
106112 else
107113 npm whoami
108114 fi
109- cd ${{ inputs.package }}/
115+
110116 if [ "${{ inputs.dry_run }}" == "false" ]; then
111117 dry_run_option=""
112118 else
@@ -117,12 +123,12 @@ runs:
117123 - name : Promote package distribution tag to 'latest'
118124 if : inputs.dry_run == 'false' && steps.check_version.outputs.deploy_mode == 'promote'
119125 shell : bash
126+ working-directory : ${{ inputs.package_dir }}
120127 env :
121128 NPM_TOKEN : ${{ inputs.api_token }}
122129 run : |
123- echo "Publish '@ ${{ inputs.scope }}/ ${{ inputs.package }}' package "
130+ echo "Promote ' ${{ steps.prepare.outputs.package_name }}' package version ' ${{ steps.prepare.outputs.package_local_version }}' from 'next' to 'latest' "
124131 npm set "//registry.npmjs.org/:_authToken=${NPM_TOKEN}"
125132 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
133+ npm dist-tag add ${{ steps.prepare.outputs.package_name }}"@${{ steps.prepare.outputs.package_local_version }} latest
134+ npm dist-tag rm ${{ steps.prepare.outputs.package_name }}"@${{ steps.prepare.outputs.package_local_version }} next
0 commit comments