|
| 1 | +name: CI |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + pull_request: |
| 7 | + |
| 8 | +env: |
| 9 | + DEBUG: 'napi:*' |
| 10 | + MACOSX_DEPLOYMENT_TARGET: '10.13' |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + strategy: |
| 15 | + fail-fast: false |
| 16 | + matrix: |
| 17 | + targets: |
| 18 | + [ |
| 19 | + 'x86_64-apple-darwin', |
| 20 | + 'aarch64-apple-darwin', |
| 21 | + 'x86_64-pc-windows-msvc', |
| 22 | + 'i686-pc-windows-msvc', |
| 23 | + 'aarch64-pc-windows-msvc', |
| 24 | + 'x86_64-unknown-linux-gnu', |
| 25 | + 'aarch64-unknown-linux-gnu', |
| 26 | + 'x86_64-unknown-linux-musl', |
| 27 | + 'aarch64-unknown-linux-musl', |
| 28 | + 'armv7-unknown-linux-gnueabihf', |
| 29 | + 'aarch64-linux-android', |
| 30 | + 'armv7-linux-androideabi', |
| 31 | + ] |
| 32 | + runs-on: ubuntu-latest |
| 33 | + steps: |
| 34 | + - name: Checkout code |
| 35 | + uses: actions/checkout@v4 |
| 36 | + - name: Cache cargo registry |
| 37 | + uses: actions/cache@v4 |
| 38 | + with: |
| 39 | + path: | |
| 40 | + ~/.cargo |
| 41 | + ${{ github.workspace }}/.xwin |
| 42 | + ~/.napi-rs |
| 43 | + ./target |
| 44 | + key: ${{ matrix.targets }}-cargo-cache |
| 45 | + - name: Install Rust toolchain |
| 46 | + uses: dtolnay/rust-toolchain@stable |
| 47 | + with: |
| 48 | + toolchain: stable |
| 49 | + targets: ${{ matrix.targets }} |
| 50 | + - name: Install pnpm |
| 51 | + uses: pnpm/action-setup@v4 |
| 52 | + - name: Install Node |
| 53 | + uses: actions/setup-node@v4 |
| 54 | + with: |
| 55 | + node-version: 22 |
| 56 | + cache: pnpm |
| 57 | + - name: Install ziglang |
| 58 | + uses: goto-bus-stop/setup-zig@v1 |
| 59 | + with: |
| 60 | + version: 0.13.0 |
| 61 | + - name: Install cargo toolchains |
| 62 | + uses: taiki-e/install-action@v2 |
| 63 | + env: |
| 64 | + GITHUB_TOKEN: ${{ github.token }} |
| 65 | + with: |
| 66 | + tool: cargo-zigbuild,cargo-xwin |
| 67 | + - name: Install dependencies |
| 68 | + run: pnpm install |
| 69 | + - name: Build bindings |
| 70 | + run: pnpm build --target ${{ matrix.targets }} |
| 71 | + env: |
| 72 | + XWIN_CACHE_DIR: ${{ github.workspace }}/.xwin |
| 73 | + - name: Upload artifacts |
| 74 | + uses: actions/upload-artifact@v4 |
| 75 | + with: |
| 76 | + name: bindings-${{ matrix.targets }} |
| 77 | + path: ./*.node |
| 78 | + if-no-files-found: error |
| 79 | + test-host: |
| 80 | + strategy: |
| 81 | + fail-fast: false |
| 82 | + matrix: |
| 83 | + settings: |
| 84 | + - target: x86_64-apple-darwin |
| 85 | + host: macos-latest |
| 86 | + - target: aarch64-apple-darwin |
| 87 | + host: macos-latest |
| 88 | + - target: x86_64-pc-windows-msvc |
| 89 | + host: windows-latest |
| 90 | + - target: i686-pc-windows-msvc |
| 91 | + host: windows-latest |
| 92 | + node: [18, 20, 22] |
| 93 | + runs-on: ${{ matrix.settings.host }} |
| 94 | + needs: |
| 95 | + - build |
| 96 | + steps: |
| 97 | + - name: Checkout code |
| 98 | + uses: actions/checkout@v4 |
| 99 | + - name: Install pnpm |
| 100 | + uses: pnpm/action-setup@v4 |
| 101 | + - name: Install Node |
| 102 | + uses: actions/setup-node@v4 |
| 103 | + if: matrix.settings.target != 'aarch64-apple-darwin' |
| 104 | + with: |
| 105 | + node-version: ${{ matrix.node }} |
| 106 | + cache: pnpm |
| 107 | + architecture: x64 |
| 108 | + - uses: actions/setup-node@v4 |
| 109 | + if: matrix.settings.target == 'aarch64-apple-darwin' |
| 110 | + with: |
| 111 | + node-version: ${{ matrix.node }} |
| 112 | + cache: pnpm |
| 113 | + architecture: arm64 |
| 114 | + - name: Setup node x86 |
| 115 | + if: matrix.settings.target == 'i686-pc-windows-msvc' |
| 116 | + run: pnpm config set supportedArchitectures.cpu "ia32" |
| 117 | + shell: bash |
| 118 | + - name: Install dependencies |
| 119 | + run: pnpm install |
| 120 | + - name: Setup node x86 |
| 121 | + uses: actions/setup-node@v4 |
| 122 | + if: matrix.settings.target == 'i686-pc-windows-msvc' |
| 123 | + with: |
| 124 | + node-version: 22 |
| 125 | + cache: pnpm |
| 126 | + architecture: x86 |
| 127 | + - name: Download bindings |
| 128 | + uses: actions/download-artifact@v4 |
| 129 | + with: |
| 130 | + name: bindings-${{ matrix.settings.target }} |
| 131 | + path: ./ |
| 132 | + - name: Run tests |
| 133 | + run: pnpm test |
| 134 | + test-docker: |
| 135 | + strategy: |
| 136 | + fail-fast: false |
| 137 | + matrix: |
| 138 | + settings: |
| 139 | + - target: x86_64-unknown-linux-gnu |
| 140 | + docker: node:18-slim |
| 141 | + args: '' |
| 142 | + - target: aarch64-unknown-linux-gnu |
| 143 | + docker: node:18-slim |
| 144 | + args: '--platform linux/arm64' |
| 145 | + - target: x86_64-unknown-linux-musl |
| 146 | + docker: node:18-alpine |
| 147 | + args: '' |
| 148 | + - target: aarch64-unknown-linux-musl |
| 149 | + docker: node:18-alpine |
| 150 | + args: '--platform linux/arm64' |
| 151 | + - target: armv7-unknown-linux-gnueabihf |
| 152 | + docker: node:18-bullseye-slim |
| 153 | + args: '--platform linux/arm/v7' |
| 154 | + runs-on: ubuntu-latest |
| 155 | + needs: |
| 156 | + - build |
| 157 | + steps: |
| 158 | + - name: Checkout code |
| 159 | + uses: actions/checkout@v4 |
| 160 | + - name: Install node |
| 161 | + uses: actions/setup-node@v4 |
| 162 | + with: |
| 163 | + node-version: 22 |
| 164 | + cache: pnpm |
| 165 | + - name: Install dependencies |
| 166 | + run: pnpm install |
| 167 | + - name: Download bindings |
| 168 | + uses: actions/download-artifact@v4 |
| 169 | + with: |
| 170 | + name: bindings-${{ matrix.settings.target }} |
| 171 | + path: ./ |
| 172 | + - name: Set up QEMU |
| 173 | + uses: docker/setup-qemu-action@v3 |
| 174 | + with: |
| 175 | + platforms: arm64,arm |
| 176 | + - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes |
| 177 | + - name: Run tests |
| 178 | + uses: addnab/docker-run-action@v3 |
| 179 | + with: |
| 180 | + image: ${{ matrix.settings.docker }} |
| 181 | + options: ${{ matrix.settings.args }} -v ${{ github.workspace }}:/build -w /build |
| 182 | + run: | |
| 183 | + set -e |
| 184 | + pnpm test |
| 185 | + publish: |
| 186 | + name: Publish |
| 187 | + runs-on: ubuntu-latest |
| 188 | + needs: |
| 189 | + - build |
| 190 | + - test-host |
| 191 | + - test-docker |
| 192 | + steps: |
| 193 | + - name: Checkout code |
| 194 | + uses: actions/checkout@v4 |
| 195 | + - name: Install pnpm |
| 196 | + uses: pnpm/action-setup@v4 |
| 197 | + - name: Install Node |
| 198 | + uses: actions/setup-node@v4 |
| 199 | + with: |
| 200 | + node-version: 22 |
| 201 | + cache: pnpm |
| 202 | + - name: Install dependencies |
| 203 | + run: pnpm install |
| 204 | + - name: Download all artifacts |
| 205 | + uses: actions/download-artifact@v4 |
| 206 | + with: |
| 207 | + path: artifacts |
| 208 | + - name: Move artifacts |
| 209 | + run: pnpm artifacts |
| 210 | + - name: List packages |
| 211 | + run: ls -R npm |
| 212 | + shell: bash |
| 213 | + - name: Publish |
| 214 | + run: | |
| 215 | + if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$"; |
| 216 | + then |
| 217 | + echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc |
| 218 | + npm publish --access public |
| 219 | + elif git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+"; |
| 220 | + then |
| 221 | + echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc |
| 222 | + npm publish --tag next --access public |
| 223 | + else |
| 224 | + echo "Not a release, skipping publish" |
| 225 | + fi |
| 226 | + env: |
| 227 | + GITHUB_TOKEN: ${{ github.token }} |
| 228 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments