@@ -18,65 +18,167 @@ jobs:
1818 permissions :
1919 contents : write
2020 id-token : write
21+ concurrency :
22+ group : release-${{ github.ref_name }}
23+ cancel-in-progress : false
2124 steps :
2225 - name : Checkout
2326 uses : actions/checkout@v4
2427 with :
2528 fetch-depth : 0
29+ fetch-tags : true
2630
2731 - name : Setup pnpm
2832 uses : pnpm/action-setup@v4
2933 with :
3034 version : 9
3135
36+ - name : Setup Node.js (act)
37+ if : ${{ env.ACT == 'true' }}
38+ uses : actions/setup-node@v4
39+ with :
40+ node-version : ' 22'
41+ registry-url : ' https://registry.npmjs.org/'
42+
3243 - name : Setup Node.js
44+ if : ${{ env.ACT != 'true' }}
3345 uses : actions/setup-node@v4
3446 with :
3547 node-version : ' 22'
3648 cache : ' pnpm'
37- cache-dependency-path : pnpm-lock.yaml
49+ cache-dependency-path : ' **/ pnpm-lock.yaml'
3850 registry-url : ' https://registry.npmjs.org/'
3951
52+ - name : Install dependencies (act)
53+ if : ${{ env.ACT == 'true' }}
54+ run : pnpm install --no-frozen-lockfile
55+
4056 - name : Install dependencies
57+ if : ${{ env.ACT != 'true' }}
4158 run : pnpm install --frozen-lockfile
4259
60+ - name : Compile contracts
61+ if : ${{ env.ACT != 'true' }}
62+ run : pnpm hardhat compile
63+ env :
64+ SKIP_HARDHAT_TASKS : " true"
65+
66+ - name : Run tests
67+ if : ${{ env.ACT != 'true' }}
68+ run : pnpm test
69+ env :
70+ SKIP_HARDHAT_TASKS : " true"
71+
4372 - name : Compute version
4473 id : version
74+ shell : bash
4575 run : |
76+ set -euo pipefail
4677 INPUT_VERSION="${{ github.event.inputs.version }}"
78+ CHANNEL="${{ github.event.inputs.dist_tag }}"
79+ SHORT_SHA=$(git rev-parse --short HEAD)
4780 if [ -n "$INPUT_VERSION" ]; then
4881 echo "version=$INPUT_VERSION" >> "$GITHUB_OUTPUT"
4982 exit 0
5083 fi
51- LATEST=$(git tag -l 'v*' | sort --version-sort | tail -n 1)
84+ if [ "$CHANNEL" != "latest" ] && [ -n "$CHANNEL" ]; then
85+ BASE_VERSION=$(node -p "require('./package.json').version")
86+ NEXT="v${BASE_VERSION}-${CHANNEL}.${SHORT_SHA}"
87+ echo "version=$NEXT" >> "$GITHUB_OUTPUT"
88+ exit 0
89+ fi
90+ LATEST=$(git tag -l 'v[0-9]*.[0-9]*.[0-9]*' | sort -V | tail -n 1 || true)
5291 if [ -z "$LATEST" ]; then
53- NEXT="v0.1.0-beta"
92+ BASE_VERSION=$(node -p "require('./package.json').version")
93+ NEXT="v${BASE_VERSION}"
5494 else
5595 BASE=${LATEST#v}
5696 NEXT="v$(npx --yes semver -i patch "$BASE")"
5797 fi
5898 echo "version=$NEXT" >> "$GITHUB_OUTPUT"
5999
60100 - name : Update package version
61- run : pnpm version $(echo ${{ steps.version.outputs.version }} | sed 's/^v//') --no-git-tag-version
101+ run : pnpm version " $(echo " ${{ steps.version.outputs.version }}" | sed 's/^v//')" --no-git-tag-version
62102
63103 - name : Build
64104 run : pnpm run build
65105
106+ - name : Ensure version not already on npm
107+ if : ${{ env.ACT != 'true' }}
108+ shell : bash
109+ run : |
110+ set -euo pipefail
111+ PKG_NAME=$(node -p "require('./package.json').name")
112+ VERSION=$(echo "${{ steps.version.outputs.version }}" | sed 's/^v//')
113+ if npm view "$PKG_NAME@$VERSION" version >/dev/null 2>&1; then
114+ echo "Version $VERSION is already published to npm. Aborting."
115+ exit 1
116+ fi
117+
66118 - name : Publish to npm
119+ if : ${{ env.ACT != 'true' }}
67120 env :
68121 NODE_AUTH_TOKEN : ${{ secrets.NPM_PUBLISH_TOKEN }}
69- run : pnpm publish --tag ${{ github.event.inputs.dist_tag }} --access public --no-git-checks
122+ shell : bash
123+ run : |
124+ set -euo pipefail
125+ pnpm publish --tag "${{ github.event.inputs.dist_tag }}" --access public --provenance --no-git-checks
126+
127+ - name : Commit version bump
128+ if : ${{ env.ACT != 'true' }}
129+ env :
130+ VERSION : ${{ steps.version.outputs.version }}
131+ BRANCH : ${{ github.ref_name }}
132+ GIT_AUTHOR_NAME : github-actions[bot]
133+ GIT_AUTHOR_EMAIL : 41898282+github-actions[bot]@users.noreply.github.com
134+ GIT_COMMITTER_NAME : github-actions[bot]
135+ GIT_COMMITTER_EMAIL : 41898282+github-actions[bot]@users.noreply.github.com
136+ shell : bash
137+ run : |
138+ set -euo pipefail
139+ git add package.json pnpm-lock.yaml || true
140+ if git diff --cached --quiet; then
141+ echo "No version changes to commit"
142+ else
143+ git commit -m "chore(release): $VERSION [skip ci]"
144+ git push origin HEAD:refs/heads/$BRANCH
145+ fi
146+
147+ - name : Ensure git tag does not already exist
148+ if : ${{ env.ACT != 'true' }}
149+ shell : bash
150+ run : |
151+ set -euo pipefail
152+ TAG="${{ steps.version.outputs.version }}"
153+ if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then
154+ echo "Git tag $TAG already exists locally."
155+ exit 1
156+ fi
157+ if git ls-remote --tags origin "refs/tags/$TAG" | grep -q .; then
158+ echo "Git tag $TAG already exists on origin."
159+ exit 1
160+ fi
70161
71162 - name : Create git tag
163+ if : ${{ env.ACT != 'true' }}
164+ shell : bash
72165 run : |
73- git tag ${{ steps.version.outputs.version }}
74- git push origin ${{ steps.version.outputs.version }}
166+ set -euo pipefail
167+ git tag -a "${{ steps.version.outputs.version }}" -m "Release ${{ steps.version.outputs.version }}"
168+ git push origin "${{ steps.version.outputs.version }}"
75169
76170 - name : Create GitHub release
171+ if : ${{ env.ACT != 'true' }}
77172 env :
78173 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
174+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
175+ shell : bash
79176 run : |
80- gh release create ${{ steps.version.outputs.version }} \
81- --title ${{ steps.version.outputs.version }} \
82- --generate-notes
177+ set -euo pipefail
178+ PRERELEASE_FLAG=""
179+ if [[ "${{ github.event.inputs.dist_tag }}" != "latest" && -n "${{ github.event.inputs.dist_tag }}" ]]; then
180+ PRERELEASE_FLAG="--prerelease"
181+ fi
182+ gh release create "${{ steps.version.outputs.version }}" \
183+ --title "${{ steps.version.outputs.version }}" \
184+ --generate-notes $PRERELEASE_FLAG
0 commit comments