forked from foundry-rs/foundry
-
Notifications
You must be signed in to change notification settings - Fork 0
250 lines (218 loc) · 7.9 KB
/
npm.yml
File metadata and controls
250 lines (218 loc) · 7.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
name: npm
permissions: {}
on:
workflow_dispatch:
inputs:
run_id:
type: string
required: false
description: The run id of the release to publish
workflow_run:
types: [completed]
workflows: [release]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
defaults:
run:
shell: bash
env:
ACTIONS_RUNNER_DEBUG: true
NPM_CONFIG_PROVENANCE: true
NPM_REGISTRY_URL: "https://registry.npmjs.org"
jobs:
publish-arch:
permissions:
contents: read
actions: read
id-token: write
name: ${{ matrix.os }}-${{ matrix.arch }}
runs-on: ubuntu-latest
strategy:
max-parallel: 3
fail-fast: false
matrix:
include:
- os: linux
arch: amd64
- os: linux
arch: arm64
- os: darwin
arch: amd64
- os: darwin
arch: arm64
- os: win32
arch: amd64
# Run automatically after a successful 'release' workflow, or manually if a run_id is provided
if: >-
${{
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') ||
(github.event_name == 'workflow_dispatch' && inputs.run_id != '')
}}
outputs:
RELEASE_VERSION: ${{ steps.release-version.outputs.RELEASE_VERSION }}
steps:
- name: Checkout
uses: actions/checkout@v5
with:
persist-credentials: false
- name: Set Isolated Artifact Directory
id: paths
run: |
set -euo pipefail
printf 'artifact_dir=%s\n' "$RUNNER_TEMP/foundry_artifacts" >> "$GITHUB_OUTPUT"
- name: Prepare Isolated Artifact Directory
env:
ARTIFACT_DIR: ${{ steps.paths.outputs.artifact_dir }}
run: |
mkdir -p "$ARTIFACT_DIR"
ls -la "$ARTIFACT_DIR" || true
- name: Download Release Assets
uses: actions/download-artifact@v5
with:
merge-multiple: true
# Download all foundry artifacts from the triggering release run
pattern: "foundry_*"
# Extract artifacts into an isolated temp directory, not the workspace
path: ${{ steps.paths.outputs.artifact_dir }}
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id || inputs.run_id }}
- name: Setup Bun
uses: oven-sh/setup-bun@735343b667d3e6f658f44d0eca948eb6282f2b76 # v2
with:
bun-version: latest
- name: Setup Node (for npm publish auth)
uses: actions/setup-node@v5
with:
node-version: "24"
registry-url: "https://registry.npmjs.org"
- name: Install Dependencies
working-directory: ./npm
run: bun install --frozen-lockfile
- name: Transpile TS -> JS
working-directory: ./npm
run: bun run build
- name: Derive RELEASE_VERSION
id: release-version
working-directory: ./npm
env:
PROVENANCE: true
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_REGISTRY_URL: ${{ env.NPM_REGISTRY_URL }}
ARTIFACT_DIR: ${{ steps.paths.outputs.artifact_dir }}
run: |
set -euo pipefail
echo "Artifacts in $ARTIFACT_DIR:"
ls -la "$ARTIFACT_DIR" || true
# Derive RELEASE_VERSION from any foundry artifact we downloaded
# Expected names: foundry_<VERSION>_<platform>_<arch>.{tar.gz,zip}
first_file=$(ls "$ARTIFACT_DIR"/foundry_* 2>/dev/null | head -n1 || true)
if [[ -z "${first_file}" ]]; then
echo "No foundry artifacts found to publish" >&2
exit 1
fi
version_part=$(basename "$first_file")
version_part=${version_part#foundry_}
export RELEASE_VERSION=${version_part%%_*}
echo "Detected RELEASE_VERSION=$RELEASE_VERSION"
printf 'RELEASE_VERSION=%s\n' "$RELEASE_VERSION" >>"$GITHUB_OUTPUT"
- name: Stage Binary Into Package
working-directory: ./npm
env:
RELEASE_VERSION: ${{ steps.release-version.outputs.RELEASE_VERSION }}
ARTIFACT_DIR: ${{ steps.paths.outputs.artifact_dir }}
run: |
set -euo pipefail
mkdir -p "$ARTIFACT_DIR/tmp"
FILE_PREFIX="$ARTIFACT_DIR/foundry_${RELEASE_VERSION}_${{ matrix.os }}_${{ matrix.arch }}"
if [[ -f "${FILE_PREFIX}.zip" ]]; then
echo "Extracting ${FILE_PREFIX}.zip"
if ! command -v unzip >/dev/null 2>&1; then
sudo apt-get update -y && sudo apt-get install -y unzip
fi
unzip -o "${FILE_PREFIX}.zip" -d "$ARTIFACT_DIR/tmp"
BIN="$ARTIFACT_DIR/tmp/forge.exe"
else
echo "Extracting ${FILE_PREFIX}.tar.gz"
tar -xzf "${FILE_PREFIX}.tar.gz" -C "$ARTIFACT_DIR/tmp"
BIN="$ARTIFACT_DIR/tmp/forge"
fi
echo "Staging binary $BIN into @foundry-rs/forge-${{ matrix.os }}-${{ matrix.arch }}"
PLATFORM_NAME=${{ matrix.os }} ARCH=${{ matrix.arch }} FORGE_BIN_PATH="$BIN" bun ./scripts/prepublish.ts
- name: Sanity Check Binary
working-directory: ./npm
run: |
set -euo pipefail
PKG_DIR="./@foundry-rs/forge-${{ matrix.os }}-${{ matrix.arch }}"
BIN="$PKG_DIR/bin/forge"
if [[ "${{ matrix.os }}" == "win32" ]]; then
BIN="$PKG_DIR/bin/forge.exe"
fi
echo "Verifying binary at: $BIN"
ls -la "$BIN"
if [[ ! -f "$BIN" ]]; then
echo "ERROR: Binary not found at $BIN" >&2
exit 1
fi
if [[ "${{ matrix.os }}" != "win32" ]]; then
if [[ ! -x "$BIN" ]]; then
echo "ERROR: Binary not marked executable" >&2
exit 1
fi
fi
- name: Publish ${{ matrix.os }}-${{ matrix.arch }} Binary
working-directory: ./npm
env:
PROVENANCE: true
VERSION_NAME: ${{ steps.release-version.outputs.RELEASE_VERSION }}
RELEASE_VERSION: ${{ steps.release-version.outputs.RELEASE_VERSION }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
set -euo pipefail
ls -la ./@foundry-rs/forge-${{ matrix.os }}-${{ matrix.arch }}
bun ./scripts/publish.ts ./@foundry-rs/forge-${{ matrix.os }}-${{ matrix.arch }}
echo "Published @foundry-rs/forge-${{ matrix.os }}-${{ matrix.arch }}"
publish-meta:
permissions:
contents: read
actions: read
id-token: write
needs: publish-arch
name: Publish Meta Package
runs-on: ubuntu-latest
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
RELEASE_VERSION: ${{ needs.publish-arch.outputs.RELEASE_VERSION }}
steps:
- name: Checkout
uses: actions/checkout@v5
with:
persist-credentials: false
- name: Setup Bun
uses: oven-sh/setup-bun@735343b667d3e6f658f44d0eca948eb6282f2b76 # v2
with:
bun-version: latest
- name: Setup Node (for npm publish auth)
uses: actions/setup-node@v5
with:
node-version: "24"
registry-url: "https://registry.npmjs.org"
- name: Install Dependencies
working-directory: ./npm
run: bun install --frozen-lockfile
- name: Transpile TS -> JS
working-directory: ./npm
run: bun run build
- name: Publish Meta
working-directory: ./npm
run: bun run ./scripts/publish.ts ./@foundry-rs/forge
env:
PROVENANCE: true
VERSION_NAME: ${{ env.RELEASE_VERSION }}
RELEASE_VERSION: ${{ env.RELEASE_VERSION }}
NPM_TOKEN: ${{ env.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ env.NODE_AUTH_TOKEN }}
NPM_REGISTRY_URL: ${{ env.NPM_REGISTRY_URL }}