|
| 1 | +name: Publish NPM |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 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] |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 16 | + cancel-in-progress: true |
| 17 | + |
| 18 | +defaults: |
| 19 | + run: |
| 20 | + shell: bash |
| 21 | + |
| 22 | +env: |
| 23 | + ACTIONS_RUNNER_DEBUG: true |
| 24 | + NPM_CONFIG_PROVENANCE: true |
| 25 | + |
| 26 | +jobs: |
| 27 | + publish-arch: |
| 28 | + permissions: |
| 29 | + actions: read |
| 30 | + contents: read |
| 31 | + id-token: write |
| 32 | + name: ${{ matrix.os }}-${{ matrix.arch }} |
| 33 | + runs-on: ubuntu-latest |
| 34 | + strategy: |
| 35 | + max-parallel: 3 |
| 36 | + fail-fast: false |
| 37 | + matrix: |
| 38 | + include: |
| 39 | + - os: linux |
| 40 | + arch: amd64 |
| 41 | + - os: linux |
| 42 | + arch: arm64 |
| 43 | + - os: darwin |
| 44 | + arch: amd64 |
| 45 | + - os: darwin |
| 46 | + arch: arm64 |
| 47 | + - os: win32 |
| 48 | + arch: amd64 |
| 49 | + if: ${{ github.event_name == 'workflow_run' && github.event.workflow.conclusion == 'success' }} |
| 50 | + outputs: |
| 51 | + RELEASE_VERSION: ${{ steps.release-version.outputs.RELEASE_VERSION }} |
| 52 | + env: |
| 53 | + NPM_REGISTRY_URL: "https://registry.npmjs.org" |
| 54 | + steps: |
| 55 | + - name: Checkout |
| 56 | + uses: actions/checkout@v5 |
| 57 | + |
| 58 | + - name: Download Release Assets |
| 59 | + uses: actions/download-artifact@v5 |
| 60 | + with: |
| 61 | + merge-multiple: true |
| 62 | + # Download all foundry artifacts from the triggering release run |
| 63 | + pattern: "foundry_*" |
| 64 | + path: foundry_artifacts |
| 65 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 66 | + run-id: ${{ github.event.workflow_run.id || inputs.run_id }} |
| 67 | + |
| 68 | + - name: Setup Bun |
| 69 | + uses: oven-sh/setup-bun@main |
| 70 | + with: |
| 71 | + bun-version: latest |
| 72 | + registries: | |
| 73 | + https://registry.npmjs.org |
| 74 | +
|
| 75 | + - name: Setup Node (for npm publish auth) |
| 76 | + uses: actions/setup-node@v4 |
| 77 | + with: |
| 78 | + node-version: "24" |
| 79 | + registry-url: "https://registry.npmjs.org" |
| 80 | + |
| 81 | + - name: Install Dependencies |
| 82 | + working-directory: ./npm |
| 83 | + run: bun install --frozen-lockfile |
| 84 | + |
| 85 | + - name: Transpile TS -> JS |
| 86 | + working-directory: ./npm |
| 87 | + run: bun run build |
| 88 | + |
| 89 | + - name: Derive RELEASE_VERSION |
| 90 | + 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 }} |
| 97 | + run: | |
| 98 | + set -euo pipefail |
| 99 | +
|
| 100 | + echo "Artifacts in foundry_artifacts:" |
| 101 | + ls -la ../foundry_artifacts || true |
| 102 | +
|
| 103 | + # Derive RELEASE_VERSION from any foundry artifact we downloaded |
| 104 | + # Expected names: foundry_<VERSION>_<platform>_<arch>.{tar.gz,zip} |
| 105 | + first_file=$(ls ../foundry_artifacts/foundry_* 2>/dev/null | head -n1 || true) |
| 106 | + if [[ -z "${first_file}" ]]; then |
| 107 | + echo "No foundry artifacts found to publish" >&2 |
| 108 | + exit 1 |
| 109 | + fi |
| 110 | + version_part=$(basename "$first_file") |
| 111 | + version_part=${version_part#foundry_} |
| 112 | + export RELEASE_VERSION=${version_part%%_*} |
| 113 | + echo "Detected RELEASE_VERSION=$RELEASE_VERSION" |
| 114 | +
|
| 115 | + echo "RELEASE_VERSION=$RELEASE_VERSION" >> "$GITHUB_OUTPUT" |
| 116 | +
|
| 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 |
| 167 | + env: |
| 168 | + PROVENANCE: true |
| 169 | + VERSION_NAME: ${{ steps.release-version.outputs.RELEASE_VERSION }} |
| 170 | + RELEASE_VERSION: ${{ steps.release-version.outputs.RELEASE_VERSION }} |
| 171 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 172 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 173 | + run: | |
| 174 | + set -euo pipefail |
| 175 | +
|
| 176 | + ls -la ./@foundry-rs/forge-${{ matrix.os }}-${{ matrix.arch }} |
| 177 | +
|
| 178 | + bun ./scripts/publish.ts ./@foundry-rs/forge-${{ matrix.os }}-${{ matrix.arch }} |
| 179 | +
|
| 180 | + echo "Published @foundry-rs/forge-${{ matrix.os }}-${{ matrix.arch }}" |
| 181 | +
|
| 182 | + publish-meta: |
| 183 | + permissions: |
| 184 | + actions: read |
| 185 | + contents: read |
| 186 | + id-token: write |
| 187 | + needs: publish-arch |
| 188 | + name: Publish Meta Package |
| 189 | + runs-on: ubuntu-latest |
| 190 | + env: |
| 191 | + 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" |
| 195 | + steps: |
| 196 | + - name: Checkout |
| 197 | + uses: actions/checkout@v5 |
| 198 | + |
| 199 | + - name: Setup Bun |
| 200 | + uses: oven-sh/setup-bun@main |
| 201 | + with: |
| 202 | + bun-version: latest |
| 203 | + registries: | |
| 204 | + https://registry.npmjs.org |
| 205 | +
|
| 206 | + - name: Setup Node (for npm publish auth) |
| 207 | + uses: actions/setup-node@v4 |
| 208 | + with: |
| 209 | + node-version: "24" |
| 210 | + registry-url: "https://registry.npmjs.org" |
| 211 | + |
| 212 | + - name: Install Dependencies |
| 213 | + working-directory: ./npm |
| 214 | + run: bun install --frozen-lockfile |
| 215 | + |
| 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 |
| 223 | + env: |
| 224 | + PROVENANCE: true |
| 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 }} |
0 commit comments