|
| 1 | +name: Release |
| 2 | +env: |
| 3 | + DEBUG: napi:* |
| 4 | + APP_NAME: rust-decoder |
| 5 | + MACOSX_DEPLOYMENT_TARGET: "10.13" |
| 6 | +permissions: |
| 7 | + contents: read |
| 8 | +on: |
| 9 | + push: |
| 10 | + tags: |
| 11 | + - "v*" |
| 12 | + workflow_dispatch: |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + settings: |
| 19 | + - host: macos-latest |
| 20 | + target: x86_64-apple-darwin |
| 21 | + - host: windows-latest |
| 22 | + target: x86_64-pc-windows-msvc |
| 23 | + - host: ubuntu-latest |
| 24 | + target: x86_64-unknown-linux-gnu |
| 25 | + docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian |
| 26 | + - host: ubuntu-latest |
| 27 | + target: x86_64-unknown-linux-musl |
| 28 | + docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine |
| 29 | + - host: macos-latest |
| 30 | + target: aarch64-apple-darwin |
| 31 | + - host: ubuntu-latest |
| 32 | + target: aarch64-unknown-linux-gnu |
| 33 | + docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64 |
| 34 | + - host: ubuntu-latest |
| 35 | + target: aarch64-unknown-linux-musl |
| 36 | + docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine |
| 37 | + - host: windows-latest |
| 38 | + target: aarch64-pc-windows-msvc |
| 39 | + - host: ubuntu-latest |
| 40 | + target: riscv64gc-unknown-linux-gnu |
| 41 | + setup: | |
| 42 | + sudo apt-get update |
| 43 | + sudo apt-get install gcc-riscv64-linux-gnu -y |
| 44 | + name: stable - ${{ matrix.settings.target }} - node@22 |
| 45 | + runs-on: ${{ matrix.settings.host }} |
| 46 | + steps: |
| 47 | + - uses: actions/checkout@v7 |
| 48 | + - name: Setup node |
| 49 | + uses: actions/setup-node@v6 |
| 50 | + if: ${{ !matrix.settings.docker }} |
| 51 | + with: |
| 52 | + node-version: 22 |
| 53 | + cache: npm |
| 54 | + - name: Install |
| 55 | + uses: dtolnay/rust-toolchain@stable |
| 56 | + if: ${{ !matrix.settings.docker }} |
| 57 | + with: |
| 58 | + toolchain: nightly-2025-09-30 |
| 59 | + targets: ${{ matrix.settings.target }} |
| 60 | + - name: Cache cargo |
| 61 | + uses: actions/cache@v5 |
| 62 | + with: |
| 63 | + path: | |
| 64 | + ~/.cargo/registry/index/ |
| 65 | + ~/.cargo/registry/cache/ |
| 66 | + ~/.cargo/git/db/ |
| 67 | + .cargo-cache |
| 68 | + target/ |
| 69 | + key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }} |
| 70 | + - name: Setup toolchain |
| 71 | + run: ${{ matrix.settings.setup }} |
| 72 | + if: ${{ matrix.settings.setup }} |
| 73 | + shell: bash |
| 74 | + - name: Install dependencies |
| 75 | + if: ${{ !matrix.settings.docker }} |
| 76 | + run: npm ci |
| 77 | + - name: Build in docker |
| 78 | + uses: addnab/docker-run-action@v3 |
| 79 | + if: ${{ matrix.settings.docker }} |
| 80 | + with: |
| 81 | + image: ${{ matrix.settings.docker }} |
| 82 | + options: "--user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build" |
| 83 | + run: | |
| 84 | + # Upgrade Node.js to 22 (napi-rs images ship Node 18, @napi-rs/cli requires >= 20) |
| 85 | + if command -v apk > /dev/null 2>&1; then |
| 86 | + apk add --no-cache xz |
| 87 | + wget -qO- https://unofficial-builds.nodejs.org/download/release/v22.14.0/node-v22.14.0-linux-x64-musl.tar.xz | tar -xJ -C /usr/local --strip-components=1 |
| 88 | + else |
| 89 | + curl -fsSL https://deb.nodesource.com/setup_22.x | bash - |
| 90 | + apt-get install -y nodejs |
| 91 | + fi |
| 92 | + rustup toolchain install nightly-2025-09-30 |
| 93 | + rustup default nightly-2025-09-30 |
| 94 | + rustup target add ${{ matrix.settings.target }} |
| 95 | + if [ "${{ matrix.settings.target }}" = "aarch64-unknown-linux-musl" ]; then |
| 96 | + apk add --no-cache zig |
| 97 | + fi |
| 98 | + npm ci |
| 99 | + npm run build -- --target ${{ matrix.settings.target }} |
| 100 | + - name: Build |
| 101 | + run: npm run build -- --target ${{ matrix.settings.target }} |
| 102 | + if: ${{ !matrix.settings.docker }} |
| 103 | + shell: bash |
| 104 | + - name: Upload artifact |
| 105 | + uses: actions/upload-artifact@v7 |
| 106 | + with: |
| 107 | + name: bindings-${{ matrix.settings.target }} |
| 108 | + path: ${{ env.APP_NAME }}.*.node |
| 109 | + if-no-files-found: error |
| 110 | + build-freebsd: |
| 111 | + runs-on: ubuntu-latest |
| 112 | + name: Build FreeBSD |
| 113 | + steps: |
| 114 | + - uses: actions/checkout@v7 |
| 115 | + - name: Build |
| 116 | + id: build |
| 117 | + uses: cross-platform-actions/action@v1.2.0 |
| 118 | + env: |
| 119 | + DEBUG: napi:* |
| 120 | + RUSTUP_IO_THREADS: 1 |
| 121 | + with: |
| 122 | + operating_system: freebsd |
| 123 | + version: "14.0" |
| 124 | + memory: 8G |
| 125 | + cpu_count: 3 |
| 126 | + environment_variables: DEBUG RUSTUP_IO_THREADS |
| 127 | + shell: bash |
| 128 | + run: | |
| 129 | + sudo pkg install -y -f curl node libnghttp2 npm |
| 130 | + curl https://sh.rustup.rs -sSf --output rustup.sh |
| 131 | + sh rustup.sh -y --profile minimal --default-toolchain nightly-2025-09-30 |
| 132 | + source "$HOME/.cargo/env" |
| 133 | + echo "~~~~ rustc --version ~~~~" |
| 134 | + rustc --version |
| 135 | + echo "~~~~ node -v ~~~~" |
| 136 | + node -v |
| 137 | + echo "~~~~ npm --version ~~~~" |
| 138 | + npm --version |
| 139 | + pwd |
| 140 | + ls -lah |
| 141 | + whoami |
| 142 | + env |
| 143 | + freebsd-version |
| 144 | + npm ci |
| 145 | + npm run build |
| 146 | + rm -rf node_modules |
| 147 | + rm -rf target |
| 148 | + - name: Upload artifact |
| 149 | + uses: actions/upload-artifact@v7 |
| 150 | + with: |
| 151 | + name: bindings-freebsd |
| 152 | + path: ${{ env.APP_NAME }}.*.node |
| 153 | + if-no-files-found: error |
| 154 | + publish: |
| 155 | + name: Publish |
| 156 | + runs-on: ubuntu-latest |
| 157 | + environment: release |
| 158 | + permissions: |
| 159 | + id-token: write |
| 160 | + contents: read |
| 161 | + needs: |
| 162 | + - build |
| 163 | + - build-freebsd |
| 164 | + steps: |
| 165 | + - uses: actions/checkout@v7 |
| 166 | + - name: Setup node |
| 167 | + uses: actions/setup-node@v6 |
| 168 | + with: |
| 169 | + node-version: 22 |
| 170 | + registry-url: "https://registry.npmjs.org" |
| 171 | + cache: npm |
| 172 | + - name: Install dependencies |
| 173 | + run: npm ci |
| 174 | + - name: Verify tag matches package.json version |
| 175 | + if: startsWith(github.ref, 'refs/tags/') |
| 176 | + run: | |
| 177 | + TAG="${GITHUB_REF_NAME#v}" |
| 178 | + PKG="$(node -p "require('./package.json').version")" |
| 179 | + echo "tag=$TAG package.json=$PKG" |
| 180 | + if [ "$TAG" != "$PKG" ]; then |
| 181 | + echo "::error::tag $GITHUB_REF_NAME does not match package.json version $PKG" |
| 182 | + exit 1 |
| 183 | + fi |
| 184 | + - name: Download all artifacts |
| 185 | + uses: actions/download-artifact@v8 |
| 186 | + with: |
| 187 | + path: artifacts |
| 188 | + - name: Move artifacts |
| 189 | + run: npm run artifacts |
| 190 | + - name: List packages |
| 191 | + run: ls -R ./npm |
| 192 | + shell: bash |
| 193 | + - name: Publish |
| 194 | + run: | |
| 195 | + # Upgrade npm for OIDC trusted publishing (requires npm >= 11.5.1) |
| 196 | + npm install -g npm@latest |
| 197 | +
|
| 198 | + # Update versions across platform packages (skip auto-publishing them) |
| 199 | + npx napi prepublish --no-gh-release --skip-optional-publish |
| 200 | +
|
| 201 | + # Publish platform packages (skip packages without artifacts, stuck at 0.0.0) |
| 202 | + for pkg_dir in npm/*/; do |
| 203 | + if [ -d "$pkg_dir" ]; then |
| 204 | + pkg_version=$(node -p "require('./${pkg_dir}package.json').version") |
| 205 | + if [ "$pkg_version" = "0.0.0" ]; then |
| 206 | + echo "Skipping ${pkg_dir} (no artifact, version 0.0.0)" |
| 207 | + continue |
| 208 | + fi |
| 209 | + (cd "$pkg_dir" && npm publish --provenance --access public) |
| 210 | + fi |
| 211 | + done |
| 212 | +
|
| 213 | + # Publish main package (prepublish already ran above) |
| 214 | + npm publish --provenance --access public --ignore-scripts |
0 commit comments