Skip to content

Commit 94a3231

Browse files
authored
chore(ci): move npm publishing into release workflow (#8362)
1 parent bc401f7 commit 94a3231

2 files changed

Lines changed: 94 additions & 104 deletions

File tree

.github/workflows/npm-beta-release.yml

Lines changed: 0 additions & 100 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 94 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ on:
2020
- '.github/workflows/release.yml'
2121
# Allows you to run this workflow manually from the Actions tab
2222
workflow_dispatch:
23+
inputs:
24+
snapshot_tag:
25+
description: 'NPM dist-tag for the beta release'
26+
required: true
27+
default: 'beta'
28+
type: choice
29+
options:
30+
- beta
31+
- alpha
32+
- rc
33+
- preview
2334

2435
concurrency: ${{ github.workflow }}-${{ github.ref }}
2536

@@ -34,6 +45,7 @@ jobs:
3445
# This job prepares the release by creating or updating a release PR.
3546
# Notice the omission of the `publish` flag in the changesets action.
3647
prepare-release:
48+
if: github.event_name == 'push'
3749
permissions:
3850
id-token: write
3951
contents: write
@@ -90,9 +102,9 @@ jobs:
90102
env:
91103
NPM_CONFIG_PROVENANCE: true
92104
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
93-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
94105

95106
check-latest-published:
107+
if: github.event_name == 'push'
96108
runs-on: ubuntu-latest
97109
outputs:
98110
all_latest: ${{ steps.check.outputs.all_latest }}
@@ -129,15 +141,15 @@ jobs:
129141
# Windows is excluded here for speed but tested nightly via cli-install-test.yml.
130142
cli-install-cross-platform-release-test:
131143
needs: [check-latest-published]
132-
if: needs.check-latest-published.outputs.all_latest == 'false'
144+
if: github.event_name == 'push' && needs.check-latest-published.outputs.all_latest == 'false'
133145
uses: ./.github/workflows/cli-install-test.yml
134146
with:
135147
include-windows: false
136148

137149
# This job publishes the release to NPM.
138150
publish-release:
139151
needs: cli-install-cross-platform-release-test
140-
if: github.ref == 'refs/heads/main'
152+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
141153
permissions:
142154
id-token: write
143155
contents: write
@@ -166,6 +178,7 @@ jobs:
166178
uses: actions/setup-node@v6
167179
with:
168180
node-version-file: .nvmrc
181+
registry-url: 'https://registry.npmjs.org'
169182

170183
- name: Setup Foundry
171184
uses: ./.github/actions/setup-foundry
@@ -198,4 +211,81 @@ jobs:
198211
env:
199212
NPM_CONFIG_PROVENANCE: true
200213
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
201-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
214+
215+
publish-beta:
216+
if: github.event_name == 'workflow_dispatch'
217+
concurrency:
218+
group: npm-beta-release
219+
cancel-in-progress: false
220+
permissions:
221+
contents: read
222+
id-token: write
223+
runs-on: ubuntu-latest
224+
steps:
225+
- name: Checkout
226+
uses: actions/checkout@v6
227+
with:
228+
fetch-depth: 0
229+
submodules: recursive
230+
persist-credentials: false
231+
232+
- name: Setup Node.js
233+
uses: actions/setup-node@v6
234+
with:
235+
node-version-file: .nvmrc
236+
registry-url: 'https://registry.npmjs.org'
237+
238+
- name: Check for changesets
239+
run: |
240+
CHANGESET_COUNT=$(find .changeset -name "*.md" ! -name "README.md" ! -name "config.json" 2>/dev/null | wc -l | tr -d ' ')
241+
if [ "$CHANGESET_COUNT" -eq 0 ]; then
242+
echo "::error::No pending changesets found. Beta releases require pending changeset files."
243+
echo ""
244+
echo "To create a beta release:"
245+
echo "1. Add a changeset: pnpm exec changeset"
246+
echo "2. Commit the changeset file"
247+
echo "3. Run this workflow again"
248+
exit 1
249+
fi
250+
echo "Found $CHANGESET_COUNT changeset(s)"
251+
252+
- name: Setup pnpm
253+
uses: pnpm/action-setup@v4
254+
255+
- name: Install dependencies
256+
run: pnpm install --frozen-lockfile
257+
258+
- name: Create snapshot versions
259+
run: pnpm exec changeset version --snapshot ${{ inputs.snapshot_tag }}
260+
261+
- name: Get snapshot version
262+
id: version
263+
run: |
264+
SNAPSHOT_VERSION=$(node -p "require('./typescript/sdk/package.json').version")
265+
echo "snapshot=$SNAPSHOT_VERSION" >> $GITHUB_OUTPUT
266+
267+
# Need to install foundry for the build step. `hardhat-foundry` expects foundry to be installed.
268+
- name: Setup Foundry
269+
uses: ./.github/actions/setup-foundry
270+
271+
- name: Build packages
272+
run: pnpm run build && pnpm run build:zk
273+
274+
- name: Publish beta packages
275+
run: pnpm exec changeset publish --tag ${{ inputs.snapshot_tag }} --no-git-tag
276+
env:
277+
NPM_CONFIG_PROVENANCE: true
278+
279+
- name: Summary
280+
run: |
281+
echo "### Beta Release Published" >> $GITHUB_STEP_SUMMARY
282+
echo "" >> $GITHUB_STEP_SUMMARY
283+
echo "**Version:** \`${{ steps.version.outputs.snapshot }}\`" >> $GITHUB_STEP_SUMMARY
284+
echo "**NPM Tag:** \`${{ inputs.snapshot_tag }}\`" >> $GITHUB_STEP_SUMMARY
285+
echo "**Branch:** \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY
286+
echo "" >> $GITHUB_STEP_SUMMARY
287+
echo "Install with:" >> $GITHUB_STEP_SUMMARY
288+
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
289+
echo "npm install @hyperlane-xyz/sdk@${{ inputs.snapshot_tag }}" >> $GITHUB_STEP_SUMMARY
290+
echo "npm install @hyperlane-xyz/cli@${{ inputs.snapshot_tag }}" >> $GITHUB_STEP_SUMMARY
291+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)