File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,36 +12,27 @@ concurrency:
1212 cancel-in-progress : true
1313
1414jobs :
15- build-and- publish :
15+ publish :
1616 runs-on : ubuntu-latest
17- defaults :
18- run :
19- working-directory : ./v4-client-js
2017 permissions :
2118 contents : write
19+ id-token : write
20+
2221 steps :
23- - name : Checkout
24- uses : actions/checkout@v3
22+ - uses : actions/checkout@v3
2523 with :
26- fetch-depth : 0 # fetch all history for all tags and branches
24+ fetch-depth : 0
2725
28- - name : Npm
29- uses : actions/setup-node@v3
26+ - name : Setup Node
27+ uses : actions/setup-node@v4
3028 with :
31- node-version : 20.8.1
32- registry-url : https://registry.npmjs.org
33- cache : " npm"
29+ node-version-file : ' .nvmrc '
30+ registry-url : https://registry.npmjs.org/
31+ cache : npm
3432 cache-dependency-path : ' **/package-lock.json'
3533
36- - name : Install
34+ - name : Install dependencies
3735 run : npm ci
38- env :
39- NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN_READ }}
40-
41- # Run semantic-release to automatically bump the version based on PR title
42- - name : Run semantic-release
43- run : npm run release
44- env :
45- NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN_WRITE }}
46-
4736
37+ - name : Publish if needed
38+ run : ./v4-client-js/scripts/publish-if-not-exists.sh
Original file line number Diff line number Diff line change 1- v20.8.1
1+ v24
Original file line number Diff line number Diff line change 1- #! /bin/bash
2- set -euxo pipefail
1+ #! /usr/ bin/env bash
2+ set -euo pipefail
33
4- VERSION=$( cat package.json | jq -r ' .version' )
5- NAME=$( cat package.json | jq -r ' .name' )
4+ VERSION=$( jq -r ' .version' package.json)
5+ NAME=$( jq -r ' .name' package.json)
6+ TAG=" v${VERSION} "
67
7- test -z " $( npm info $NAME @$VERSION ) "
8- if [ $? -eq 0 ]; then
9- set -e
8+ echo " Checking npm registry for ${NAME} @${VERSION} ..."
109
11- git config --global user.email " ci@dydx.exchange"
12- git config --global user.name " github_actions"
10+ set +e
11+ VIEW_OUTPUT=$( npm view " ${NAME} @${VERSION} " 2>&1 )
12+ VIEW_EXIT=$?
13+ set -e
1314
14- # Get version and tag
15- git tag v4-client-js@${VERSION}
16- git push --tags
15+ if [ $VIEW_EXIT -eq 0 ]; then
16+ echo " Skipping publish: ${NAME} @${VERSION} already exists"
17+ exit 0
18+ fi
19+
20+ if ! echo " $VIEW_OUTPUT " | grep -qiE ' E404|not found|No matching version' ; then
21+ echo " Registry check failed unexpectedly:"
22+ echo " $VIEW_OUTPUT "
23+ exit 1
24+ fi
1725
18- npm publish
26+ echo " Version not found. Proceeding with release."
27+
28+ git fetch --tags --quiet
29+ git config user.email " ci@dydx.exchange"
30+ git config user.name " github_actions"
31+
32+ if git show-ref --tags --verify --quiet " refs/tags/$TAG " ; then
33+ echo " Tag $TAG already exists"
1934else
20- echo " skipping publish, package $NAME @$VERSION already published"
35+ git tag -a " $TAG " -m " Release $TAG "
36+ git push origin " $TAG "
2137fi
38+
39+ unset NODE_AUTH_TOKEN
40+ npm publish --provenance --access public
You can’t perform that action at this time.
0 commit comments