|
| 1 | +name: Publish NPM |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + # |
| 6 | + # Temporarily disabled |
| 7 | + # |
| 8 | + # workflow_run: |
| 9 | + # types: [completed] |
| 10 | + # workflows: [release] |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +defaults: |
| 17 | + run: |
| 18 | + shell: bash |
| 19 | + |
| 20 | +env: |
| 21 | + ACTIONS_RUNNER_DEBUG: true |
| 22 | + NPM_CONFIG_PROVENANCE: true |
| 23 | + |
| 24 | +jobs: |
| 25 | + publish-arch: |
| 26 | + permissions: |
| 27 | + actions: read |
| 28 | + contents: read |
| 29 | + id-token: write |
| 30 | + name: ${{ matrix.os }}-${{ matrix.arch }} |
| 31 | + runs-on: ubuntu-latest |
| 32 | + strategy: |
| 33 | + max-parallel: 3 |
| 34 | + fail-fast: false |
| 35 | + 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 |
| 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.workflow_run.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: Download Release Assets |
| 56 | + uses: actions/download-artifact@v5 |
| 57 | + with: |
| 58 | + merge-multiple: true |
| 59 | + # Download all foundry artifacts from the triggering release run |
| 60 | + pattern: "foundry_*" |
| 61 | + repository: foundry-rs/foundry |
| 62 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 63 | + # run-id: ${{ github.event.workflow_run.id }} |
| 64 | + path: foundry_artifacts |
| 65 | + |
| 66 | + - name: Setup Bun |
| 67 | + uses: oven-sh/setup-bun@main |
| 68 | + with: |
| 69 | + bun-version: latest |
| 70 | + registries: | |
| 71 | + https://registry.npmjs.org |
| 72 | +
|
| 73 | + - name: Setup Node (for npm publish auth) |
| 74 | + uses: actions/setup-node@v4 |
| 75 | + with: |
| 76 | + node-version: lts |
| 77 | + registry-url: "https://registry.npmjs.org" |
| 78 | + |
| 79 | + - name: Install Dependencies |
| 80 | + working-directory: npm |
| 81 | + run: bun install --frozen-lockfile |
| 82 | + |
| 83 | + - name: Derive RELEASE_VERSION |
| 84 | + id: release-version |
| 85 | + run: | |
| 86 | + set -euo pipefail |
| 87 | +
|
| 88 | + # Derive RELEASE_VERSION from any foundry artifact we downloaded |
| 89 | + # Expected names: foundry_<VERSION>_<platform>_<arch>.{tar.gz,zip} |
| 90 | +
|
| 91 | + first_file=$(ls ../foundry_artifacts/foundry_* 2>/dev/null | head -n1 || true) |
| 92 | + if [[ -z "${first_file}" ]]; then |
| 93 | + echo "No foundry artifacts found to publish" >&2 |
| 94 | + exit 1 |
| 95 | + fi |
| 96 | +
|
| 97 | + version_part=$(basename "$first_file") |
| 98 | + version_part=${version_part#foundry_} |
| 99 | +
|
| 100 | + export RELEASE_VERSION=${version_part%%_*} |
| 101 | +
|
| 102 | + echo "Detected RELEASE_VERSION=$RELEASE_VERSION" |
| 103 | + echo "RELEASE_VERSION=$RELEASE_VERSION" >> "$GITHUB_OUTPUT" |
| 104 | +
|
| 105 | + - name: Publish Binaries |
| 106 | + working-directory: npm |
| 107 | + env: |
| 108 | + PROVENANCE: true |
| 109 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 110 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 111 | + NPM_REGISTRY_URL: ${{ env.NPM_REGISTRY_URL }} |
| 112 | + run: | |
| 113 | + set -euo pipefail |
| 114 | +
|
| 115 | + echo "Artifacts in foundry_artifacts:" |
| 116 | + ls -la ../foundry_artifacts || true |
| 117 | +
|
| 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" |
| 129 | +
|
| 130 | + publish-meta: |
| 131 | + needs: publish-arch |
| 132 | + runs-on: ubuntu-latest |
| 133 | + # if: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 134 | + env: |
| 135 | + RELEASE_VERSION: ${{ needs.publish-arch.outputs.RELEASE_VERSION }} |
| 136 | + steps: |
| 137 | + - name: Checkout |
| 138 | + uses: actions/checkout@v5 |
| 139 | + |
| 140 | + - name: Setup Bun |
| 141 | + uses: oven-sh/setup-bun@main |
| 142 | + with: |
| 143 | + bun-version: latest |
| 144 | + registries: | |
| 145 | + https://registry.npmjs.org |
| 146 | +
|
| 147 | + - name: Setup Node (for npm publish auth) |
| 148 | + uses: actions/setup-node@v4 |
| 149 | + with: |
| 150 | + node-version: lts |
| 151 | + registry-url: "https://registry.npmjs.org" |
| 152 | + |
| 153 | + - name: Install Dependencies |
| 154 | + working-directory: npm |
| 155 | + run: bun install --frozen-lockfile |
| 156 | + |
| 157 | + - name: Publish @foundry-rs/foundry |
| 158 | + working-directory: npm |
| 159 | + env: |
| 160 | + 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" |
0 commit comments