11name : Node.js Package
22
3- run-name : ${{ github.event_name == 'workflow_dispatch' && format('Dry run publish {0}', inputs.version) || format('Publish {0}', github.event.release.tag_name) }}
3+ run-name : ${{ github.event_name == 'workflow_dispatch' && (inputs.publish && format('Publish {0}', inputs.version) || format(' Dry run publish {0}', inputs.version) ) || format('Publish {0}', github.event.release.tag_name) }}
44
55on :
66 release :
1111 description : " Version to rehearse, with or without v prefix. Example: 12.0.1"
1212 required : true
1313 type : string
14+ publish :
15+ description : " Publish packages to npm instead of dry running"
16+ required : true
17+ default : false
18+ type : boolean
1419
1520jobs :
1621 publish :
4752 echo "tag=v$VERSION" >> "$GITHUB_OUTPUT"
4853 echo "version=$VERSION" >> "$GITHUB_OUTPUT"
4954
55+ - name : Verify npm publish token
56+ if : ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.publish) }}
57+ run : |
58+ if npm whoami > /dev/null 2>&1; then
59+ echo "npm publish token is valid"
60+ else
61+ echo "::error::npm publish token is invalid, expired, or missing required registry access"
62+ exit 1
63+ fi
64+ env :
65+ NODE_AUTH_TOKEN : ${{ secrets.npm_token }}
66+
5067 - name : Update versions
5168 env :
5269 TAG : ${{ steps.version.outputs.tag }}
@@ -69,18 +86,23 @@ jobs:
6986
7087 - name : Git commit
7188 if : ${{ github.event_name == 'release' }}
72- run : git commit -am "${{ steps.version.outputs.tag }}"
89+ run : |
90+ if git diff --quiet; then
91+ echo "Version bump already committed"
92+ else
93+ git commit -am "${{ steps.version.outputs.tag }}"
94+ fi
7395
7496 - name : Git push
7597 if : ${{ github.event_name == 'release' }}
7698 run : git push
7799
78100 - name : Dry run publish
79- if : ${{ github.event_name == 'workflow_dispatch' }}
101+ if : ${{ github.event_name == 'workflow_dispatch' && !inputs.publish }}
80102 run : npm publish --ws --dry-run
81103
82104 - name : Publish packages to NPM
83- if : ${{ github.event_name == 'release' }}
105+ if : ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.publish) }}
84106 run : npm publish --ws
85107 env :
86108 NODE_AUTH_TOKEN : ${{ secrets.npm_token }}
0 commit comments