@@ -12,12 +12,13 @@ jobs:
1212 outputs :
1313 VERSION_EXISTS : ${{ steps.check-version.outputs.VERSION_EXISTS }}
1414 VERSION : ${{ steps.get-version.outputs.VERSION }}
15+ RELEASE_CHANNEL : ${{ steps.npm-tag.outputs.RELEASE_CHANNEL }}
1516 steps :
1617 - uses : GitHubSecurityLab/actions-permissions/monitor@v1
1718 - uses : actions/checkout@v5
1819 with :
1920 fetch-depth : 0
20- - uses : actions/setup-node@v4
21+ - uses : actions/setup-node@v5
2122 with :
2223 node-version-file : package.json
2324 registry-url : " https://registry.npmjs.org"
4243 else
4344 echo "VERSION_EXISTS=false" >> "$GITHUB_OUTPUT"
4445 fi
46+ - name : Get npm tag
47+ id : npm-tag
48+ shell : bash
49+ run : |
50+ set -e
51+ VERSION="${{ steps.get-version.outputs.VERSION }}"
52+
53+ # Extract the release channel (latest, alpha, beta, rc)
54+ if [[ $VERSION =~ ^v?[0-9]+\.[0-9]+\.[0-9]+(-(.+))?$ ]]; then
55+ if [[ -n "${BASH_REMATCH[2]}" ]]; then
56+ CAPTURED_CHANNEL="${BASH_REMATCH[2]}"
57+ # The captured channel might have more dots, cases like
58+ # v1.2.3-alpha.1 For such cases we only want the channel relevant
59+ # part which is alpha.
60+ RELEASE_CHANNEL="${CAPTURED_CHANNEL%%.*}"
61+ else
62+ RELEASE_CHANNEL="latest"
63+ fi
64+ else
65+ echo "::error title=Invalid Version::Encountered unexpected version ${{ steps.get-version.outputs.VERSION }}, cannot proceed!"
66+ exit 1
67+ fi
68+
69+ echo "RELEASE_CHANNEL=${RELEASE_CHANNEL}" >> "$GITHUB_OUTPUT"
70+ - name : Output deployment info
71+ run : echo "::notice title=Deployment Info::Deploying version ${{ steps.get-version.outputs.VERSION }} to channel ${{ steps.npm-tag.outputs.RELEASE_CHANNEL }}"
72+
4573 publish :
4674 runs-on : ubuntu-latest
4775 environment : Production
@@ -53,21 +81,22 @@ jobs:
5381 steps :
5482 - uses : GitHubSecurityLab/actions-permissions/monitor@v1
5583 - uses : actions/checkout@v5
56- - uses : actions/setup-node@v4
84+ - uses : actions/setup-node@v5
5785 with :
5886 node-version-file : package.json
5987 registry-url : " https://registry.npmjs.org"
6088 cache : " npm"
89+
6190 - name : Build package
6291 run : |
6392 npm ci
6493 npm run build
6594 - name : Publish to NPM
66- run : npm publish
95+ run : npm publish --tag ${{ needs.check.outputs.RELEASE_CHANNEL }}
6796 env :
6897 NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
6998 - name : Publish git release
7099 env :
71100 GH_TOKEN : ${{ github.token }}
72101 run : |
73- gh release create ${{ needs.check.outputs.VERSION }} --title "${{ needs.check.outputs.VERSION }}" --generate-notes --target ${{ github.sha }}
102+ gh release create ${{ needs.check.outputs.VERSION }} --title "${{ needs.check.outputs.VERSION }}" --generate-notes --target ${{ github.sha }} ${{ (needs.check.outputs.RELEASE_CHANNEL != 'latest' && '--prerelease') || ''}}
0 commit comments