Skip to content

Commit 4bd106e

Browse files
o-azgrandizzy
authored andcommitted
chore: tweak npm publish & handle nightly releases (foundry-rs#11513)
* Install node 24, working dir * Test with prev run id * Fix artifact and publish path * Debug * chore: add missing prepublish * chore: default to provenance=true unless specified * chore: meta name * chore: cleanup * chore: uncomment workflow_run --------- Co-authored-by: grandizzy <[email protected]>
1 parent 7c8ac93 commit 4bd106e

File tree

7 files changed

+167
-73
lines changed

7 files changed

+167
-73
lines changed

.github/workflows/npm.yml

Lines changed: 108 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ name: Publish NPM
22

33
on:
44
workflow_dispatch:
5-
#
6-
# Temporarily disabled
7-
#
8-
# workflow_run:
9-
# types: [completed]
10-
# workflows: [release]
5+
inputs:
6+
run_id:
7+
type: string
8+
required: false
9+
description: The run id of the release to publish
10+
workflow_run:
11+
types: [completed]
12+
workflows: [release]
1113

1214
concurrency:
1315
group: ${{ github.workflow }}-${{ github.ref }}
@@ -33,8 +35,6 @@ jobs:
3335
max-parallel: 3
3436
fail-fast: false
3537
matrix:
36-
# we don't need a specific runner for any of these
37-
# because they've all been built already. We're just publishing
3838
include:
3939
- os: linux
4040
arch: amd64
@@ -46,22 +46,24 @@ jobs:
4646
arch: arm64
4747
- os: win32
4848
arch: amd64
49-
# if: ${{ github.event.workflow_run.conclusion == 'success' }}
49+
if: ${{ github.event_name == 'workflow_run' && github.event.workflow.conclusion == 'success' }}
5050
outputs:
5151
RELEASE_VERSION: ${{ steps.release-version.outputs.RELEASE_VERSION }}
5252
env:
5353
NPM_REGISTRY_URL: "https://registry.npmjs.org"
5454
steps:
55+
- name: Checkout
56+
uses: actions/checkout@v5
57+
5558
- name: Download Release Assets
5659
uses: actions/download-artifact@v5
5760
with:
5861
merge-multiple: true
5962
# Download all foundry artifacts from the triggering release run
6063
pattern: "foundry_*"
61-
repository: foundry-rs/foundry
62-
github-token: ${{ secrets.GITHUB_TOKEN }}
63-
# run-id: ${{ github.event.workflow_run.id }}
6464
path: foundry_artifacts
65+
github-token: ${{ secrets.GITHUB_TOKEN }}
66+
run-id: ${{ github.event.workflow_run.id || inputs.run_id }}
6567

6668
- name: Setup Bun
6769
uses: oven-sh/setup-bun@main
@@ -73,66 +75,123 @@ jobs:
7375
- name: Setup Node (for npm publish auth)
7476
uses: actions/setup-node@v4
7577
with:
76-
node-version: lts
78+
node-version: "24"
7779
registry-url: "https://registry.npmjs.org"
7880

7981
- name: Install Dependencies
80-
working-directory: npm
82+
working-directory: ./npm
8183
run: bun install --frozen-lockfile
8284

85+
- name: Transpile TS -> JS
86+
working-directory: ./npm
87+
run: bun run build
88+
8389
- name: Derive RELEASE_VERSION
8490
id: release-version
91+
working-directory: ./npm
92+
env:
93+
PROVENANCE: true
94+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
95+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
96+
NPM_REGISTRY_URL: ${{ env.NPM_REGISTRY_URL }}
8597
run: |
8698
set -euo pipefail
8799
100+
echo "Artifacts in foundry_artifacts:"
101+
ls -la ../foundry_artifacts || true
102+
88103
# Derive RELEASE_VERSION from any foundry artifact we downloaded
89104
# Expected names: foundry_<VERSION>_<platform>_<arch>.{tar.gz,zip}
90-
91105
first_file=$(ls ../foundry_artifacts/foundry_* 2>/dev/null | head -n1 || true)
92106
if [[ -z "${first_file}" ]]; then
93107
echo "No foundry artifacts found to publish" >&2
94108
exit 1
95109
fi
96-
97110
version_part=$(basename "$first_file")
98111
version_part=${version_part#foundry_}
99-
100112
export RELEASE_VERSION=${version_part%%_*}
101-
102113
echo "Detected RELEASE_VERSION=$RELEASE_VERSION"
114+
103115
echo "RELEASE_VERSION=$RELEASE_VERSION" >> "$GITHUB_OUTPUT"
104116
105-
- name: Publish Binaries
106-
working-directory: npm
117+
- name: Stage Binary Into Package
118+
working-directory: ./npm
119+
env:
120+
RELEASE_VERSION: ${{ steps.release-version.outputs.RELEASE_VERSION }}
121+
run: |
122+
set -euo pipefail
123+
mkdir -p tmp
124+
125+
FILE_PREFIX="../foundry_artifacts/foundry_${RELEASE_VERSION}_${{ matrix.os }}_${{ matrix.arch }}"
126+
if [[ -f "${FILE_PREFIX}.zip" ]]; then
127+
echo "Extracting ${FILE_PREFIX}.zip"
128+
if ! command -v unzip >/dev/null 2>&1; then
129+
sudo apt-get update -y && sudo apt-get install -y unzip
130+
fi
131+
unzip -o "${FILE_PREFIX}.zip" -d ./tmp
132+
BIN=./tmp/forge.exe
133+
else
134+
echo "Extracting ${FILE_PREFIX}.tar.gz"
135+
tar -xzf "${FILE_PREFIX}.tar.gz" -C ./tmp
136+
BIN=./tmp/forge
137+
fi
138+
139+
echo "Staging binary $BIN into @foundry-rs/forge-${{ matrix.os }}-${{ matrix.arch }}"
140+
PLATFORM_NAME=${{ matrix.os }} ARCH=${{ matrix.arch }} FORGE_BIN_PATH="$BIN" bun ./scripts/prepublish.ts
141+
142+
- name: Sanity Check Binary
143+
working-directory: ./npm
144+
run: |
145+
set -euo pipefail
146+
PKG_DIR="./@foundry-rs/forge-${{ matrix.os }}-${{ matrix.arch }}"
147+
BIN="$PKG_DIR/bin/forge"
148+
if [[ "${{ matrix.os }}" == "win32" ]]; then
149+
BIN="$PKG_DIR/bin/forge.exe"
150+
fi
151+
echo "Verifying binary at: $BIN"
152+
ls -la "$BIN"
153+
if [[ ! -f "$BIN" ]]; then
154+
echo "ERROR: Binary not found at $BIN" >&2
155+
exit 1
156+
fi
157+
158+
if [[ "${{ matrix.os }}" != "win32" ]]; then
159+
if [[ ! -x "$BIN" ]]; then
160+
echo "ERROR: Binary not marked executable" >&2
161+
exit 1
162+
fi
163+
fi
164+
165+
- name: Publish ${{ matrix.os }}-${{ matrix.arch }} Binary
166+
working-directory: ./npm
107167
env:
108168
PROVENANCE: true
169+
VERSION_NAME: ${{ steps.release-version.outputs.RELEASE_VERSION }}
170+
RELEASE_VERSION: ${{ steps.release-version.outputs.RELEASE_VERSION }}
109171
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
110172
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
111-
NPM_REGISTRY_URL: ${{ env.NPM_REGISTRY_URL }}
112173
run: |
113174
set -euo pipefail
114175
115-
echo "Artifacts in foundry_artifacts:"
116-
ls -la ../foundry_artifacts || true
176+
ls -la ./@foundry-rs/forge-${{ matrix.os }}-${{ matrix.arch }}
117177
118-
# Derive RELEASE_VERSION from any foundry artifact we downloaded
119-
# Expected names: foundry_<VERSION>_<platform>_<arch>.{tar.gz,zip}
120-
first_file=$(ls ../foundry_artifacts/foundry_* 2>/dev/null | head -n1 || true)
121-
if [[ -z "${first_file}" ]]; then
122-
echo "No foundry artifacts found to publish" >&2
123-
exit 1
124-
fi
125-
version_part=$(basename "$first_file")
126-
version_part=${version_part#foundry_}
127-
export RELEASE_VERSION=${version_part%%_*}
128-
echo "Detected RELEASE_VERSION=$RELEASE_VERSION"
178+
bun ./scripts/publish.ts ./@foundry-rs/forge-${{ matrix.os }}-${{ matrix.arch }}
179+
180+
echo "Published @foundry-rs/forge-${{ matrix.os }}-${{ matrix.arch }}"
129181
130182
publish-meta:
183+
permissions:
184+
actions: read
185+
contents: read
186+
id-token: write
131187
needs: publish-arch
188+
name: Publish Meta Package
132189
runs-on: ubuntu-latest
133-
# if: ${{ github.event.workflow_run.conclusion == 'success' }}
134190
env:
135191
RELEASE_VERSION: ${{ needs.publish-arch.outputs.RELEASE_VERSION }}
192+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
193+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
194+
NPM_REGISTRY_URL: "https://registry.npmjs.org"
136195
steps:
137196
- name: Checkout
138197
uses: actions/checkout@v5
@@ -147,21 +206,24 @@ jobs:
147206
- name: Setup Node (for npm publish auth)
148207
uses: actions/setup-node@v4
149208
with:
150-
node-version: lts
209+
node-version: "24"
151210
registry-url: "https://registry.npmjs.org"
152211

153212
- name: Install Dependencies
154-
working-directory: npm
213+
working-directory: ./npm
155214
run: bun install --frozen-lockfile
156215

157-
- name: Publish @foundry-rs/foundry
158-
working-directory: npm
216+
- name: Transpile TS -> JS
217+
working-directory: ./npm
218+
run: bun run build
219+
220+
- name: Publish Meta
221+
working-directory: ./npm
222+
run: bun run ./scripts/publish.ts ./@foundry-rs/forge
159223
env:
160224
PROVENANCE: true
161-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
162-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
163-
run: |
164-
set -euo pipefail
165-
166-
bun ./scripts/publish.ts ./@foundry-rs/foundry
167-
echo "Published @foundry-rs/foundry"
225+
VERSION_NAME: ${{ env.RELEASE_VERSION }}
226+
RELEASE_VERSION: ${{ env.RELEASE_VERSION }}
227+
NPM_TOKEN: ${{ env.NPM_TOKEN }}
228+
NODE_AUTH_TOKEN: ${{ env.NODE_AUTH_TOKEN }}
229+
NPM_REGISTRY_URL: ${{ env.NPM_REGISTRY_URL }}

npm/@foundry-rs/forge-darwin-amd64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@foundry-rs/forge-darwin-amd64",
3-
"version": "1.2.3",
3+
"version": "1.3.2",
44
"type": "module",
55
"homepage": "https://getfoundry.sh/forge",
66
"description": "Fast and flexible Ethereum testing framework (macOS amd64)",

npm/@foundry-rs/forge-linux-amd64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@foundry-rs/forge-linux-amd64",
3-
"version": "1.2.3",
3+
"version": "1.3.2",
44
"type": "module",
55
"homepage": "https://getfoundry.sh/forge",
66
"description": "Fast and flexible Ethereum testing framework (Linux amd64)",

npm/@foundry-rs/forge-linux-arm64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@foundry-rs/forge-linux-arm64",
3-
"version": "1.2.3",
3+
"version": "1.3.2",
44
"type": "module",
55
"homepage": "https://getfoundry.sh/forge",
66
"description": "Fast and flexible Ethereum testing framework (Linux arm64)",

npm/@foundry-rs/forge-win32-amd64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@foundry-rs/forge-win32-amd64",
3-
"version": "1.2.3",
3+
"version": "1.3.2",
44
"type": "module",
55
"homepage": "https://getfoundry.sh/forge",
66
"description": "Fast and flexible Ethereum testing framework (Windows amd64)",

npm/scripts/prepublish.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ const TARGET_MAP = {
2323
'amd64-win32': 'x86_64-pc-windows-msvc'
2424
} as const
2525

26-
const ARCH_MAP = { amd64: 'x64', arm64: 'arm64', aarch64: 'arm64' } as const
27-
2826
main().catch(error => {
2927
console.error(colors.red, error)
3028
process.exit(1)
@@ -43,17 +41,18 @@ async function main() {
4341
}
4442

4543
function getPlatformInfo() {
46-
const platform = Bun.env.PLATFORM_NAME as keyof typeof PLATFORM_MAP
47-
const arch = Bun.env.ARCH as keyof typeof ARCH_MAP
44+
const platformEnv = Bun.env.PLATFORM_NAME as keyof typeof PLATFORM_MAP
45+
const archEnv = (Bun.env.ARCH || '') as 'amd64' | 'arm64' | 'aarch64'
4846

49-
if (!platform || !arch)
47+
if (!platformEnv || !archEnv)
5048
throw new Error('PLATFORM_NAME and ARCH environment variables are required')
5149

52-
const npmPlatform = PLATFORM_MAP[platform]
53-
const npmArch = ARCH_MAP[arch]
50+
const platform = PLATFORM_MAP[platformEnv]
51+
// Normalize arch for package names and target mapping
52+
const arch = archEnv === 'aarch64' ? 'arm64' : archEnv
5453

55-
if (!npmPlatform || !npmArch)
56-
throw new Error('Invalid platform or architecture')
54+
if (!platform || (arch !== 'amd64' && arch !== 'arm64'))
55+
throw new Error(`Invalid platform or architecture: platform=${platformEnv}, arch=${archEnv}`)
5756

5857
const { values } = NodeUtil.parseArgs({
5958
args: Bun.argv,
@@ -67,10 +66,10 @@ function getPlatformInfo() {
6766
const profile = Bun.env.NODE_ENV === 'production' ? 'release' : Bun.env.PROFILE || 'release'
6867
const forgeBinPath = values['forge-bin-path'] || findForgeBinary(arch, platform, profile)
6968

70-
return { platform: npmPlatform, arch: npmArch, forgeBinPath }
69+
return { platform, arch, forgeBinPath }
7170
}
7271

73-
function findForgeBinary(arch: string, platform: string, profile: string): string {
72+
function findForgeBinary(arch: string, platform: string, profile: string) {
7473
const targetDir = TARGET_MAP[`${arch}-${platform}` as keyof typeof TARGET_MAP]
7574
const targetPath = NodePath.join(process.cwd(), '..', 'target', targetDir, profile, 'forge')
7675

0 commit comments

Comments
 (0)