|
| 1 | +name: CI |
| 2 | +env: |
| 3 | + DEBUG: napi:* |
| 4 | + APP_NAME: cel-typescript |
| 5 | + MACOSX_DEPLOYMENT_TARGET: '10.13' |
| 6 | + |
| 7 | +on: |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + tags: |
| 12 | + - 'v*.*.*' |
| 13 | + pull_request: |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + if: "!contains(github.event.head_commit.message, 'skip ci')" |
| 18 | + strategy: |
| 19 | + fail-fast: false |
| 20 | + matrix: |
| 21 | + settings: |
| 22 | + - host: macos-latest |
| 23 | + target: x86_64-apple-darwin |
| 24 | + build: | |
| 25 | + npm run build |
| 26 | + strip -x *.node |
| 27 | + - host: macos-latest |
| 28 | + target: aarch64-apple-darwin |
| 29 | + build: | |
| 30 | + npm run build --target aarch64-apple-darwin |
| 31 | + strip -x *.node |
| 32 | + - host: windows-latest |
| 33 | + target: x86_64-pc-windows-msvc |
| 34 | + build: yarn build |
| 35 | + - host: windows-latest |
| 36 | + target: aarch64-pc-windows-msvc |
| 37 | + build: npm run build --target aarch64-pc-windows-msvc |
| 38 | + - host: ubuntu-latest |
| 39 | + target: x86_64-unknown-linux-gnu |
| 40 | + docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian |
| 41 | + build: | |
| 42 | + set -e && |
| 43 | + npm run build --target x86_64-unknown-linux-gnu && |
| 44 | + strip *.node |
| 45 | + - host: ubuntu-latest |
| 46 | + target: aarch64-unknown-linux-gnu |
| 47 | + docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64 |
| 48 | + build: | |
| 49 | + set -e && |
| 50 | + npm run build --target aarch64-unknown-linux-gnu && |
| 51 | + aarch64-unknown-linux-gnu-strip *.node |
| 52 | + - host: ubuntu-latest |
| 53 | + target: armv7-unknown-linux-gnueabihf |
| 54 | + docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-arm |
| 55 | + build: | |
| 56 | + set -e && |
| 57 | + npm run build --target armv7-unknown-linux-gnueabihf && |
| 58 | + arm-linux-gnueabihf-strip *.node |
| 59 | + - host: ubuntu-latest |
| 60 | + target: aarch64-linux-android |
| 61 | + build: | |
| 62 | + npm run build --target aarch64-linux-android |
| 63 | + ${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip *.node |
| 64 | + - host: ubuntu-latest |
| 65 | + target: armv7-linux-androideabi |
| 66 | + build: | |
| 67 | + npm run build --target armv7-linux-androideabi |
| 68 | + ${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip *.node |
| 69 | +
|
| 70 | + name: stable - ${{ matrix.settings.target }} - node@18 |
| 71 | + runs-on: ${{ matrix.settings.host }} |
| 72 | + |
| 73 | + steps: |
| 74 | + - uses: actions/checkout@v4 |
| 75 | + |
| 76 | + - name: Setup node |
| 77 | + uses: actions/setup-node@v4 |
| 78 | + if: ${{ !matrix.settings.docker }} |
| 79 | + with: |
| 80 | + node-version: 18 |
| 81 | + check-latest: true |
| 82 | + cache: npm |
| 83 | + |
| 84 | + - name: Install |
| 85 | + uses: dtolnay/rust-toolchain@stable |
| 86 | + if: ${{ !matrix.settings.docker }} |
| 87 | + with: |
| 88 | + targets: ${{ matrix.settings.target }} |
| 89 | + |
| 90 | + - name: Cache cargo |
| 91 | + uses: actions/cache@v3 |
| 92 | + with: |
| 93 | + path: | |
| 94 | + ~/.cargo/registry/index/ |
| 95 | + ~/.cargo/registry/cache/ |
| 96 | + ~/.cargo/git/db/ |
| 97 | + .cargo-cache |
| 98 | + target/ |
| 99 | + key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }} |
| 100 | + |
| 101 | + - uses: goto-bus-stop/setup-zig@v2 |
| 102 | + if: ${{ matrix.settings.target == 'armv7-unknown-linux-gnueabihf' }} |
| 103 | + with: |
| 104 | + version: 0.11.0 |
| 105 | + |
| 106 | + - name: Setup toolchain |
| 107 | + if: ${{ matrix.settings.docker }} |
| 108 | + uses: actions-rs/toolchain@v1 |
| 109 | + with: |
| 110 | + toolchain: stable |
| 111 | + target: ${{ matrix.settings.target }} |
| 112 | + override: true |
| 113 | + |
| 114 | + - name: Cache NPM dependencies |
| 115 | + uses: actions/cache@v3 |
| 116 | + with: |
| 117 | + path: node_modules |
| 118 | + key: npm-cache-${{ matrix.settings.target }}-${{ hashFiles('package-lock.json') }} |
| 119 | + |
| 120 | + - name: Install dependencies |
| 121 | + run: npm ci |
| 122 | + |
| 123 | + - name: Build in docker |
| 124 | + uses: addnab/docker-run-action@v3 |
| 125 | + if: ${{ matrix.settings.docker }} |
| 126 | + with: |
| 127 | + image: ${{ matrix.settings.docker }} |
| 128 | + 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 |
| 129 | + run: ${{ matrix.settings.build }} |
| 130 | + |
| 131 | + - name: Build |
| 132 | + if: ${{ !matrix.settings.docker }} |
| 133 | + run: ${{ matrix.settings.build }} |
| 134 | + shell: bash |
| 135 | + |
| 136 | + - name: Upload artifact |
| 137 | + if: startsWith(github.ref, 'refs/tags/v') |
| 138 | + uses: actions/upload-artifact@v3 |
| 139 | + with: |
| 140 | + name: bindings-${{ matrix.settings.target }} |
| 141 | + path: ${{ env.APP_NAME }}.*.node |
| 142 | + if-no-files-found: error |
| 143 | + |
| 144 | + test-macOS-windows-binding: |
| 145 | + name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }} |
| 146 | + needs: |
| 147 | + - build |
| 148 | + strategy: |
| 149 | + fail-fast: false |
| 150 | + matrix: |
| 151 | + settings: |
| 152 | + - host: macos-latest |
| 153 | + target: x86_64-apple-darwin |
| 154 | + - host: windows-latest |
| 155 | + target: x86_64-pc-windows-msvc |
| 156 | + node: |
| 157 | + - '18' |
| 158 | + - '20' |
| 159 | + runs-on: ${{ matrix.settings.host }} |
| 160 | + |
| 161 | + steps: |
| 162 | + - uses: actions/checkout@v4 |
| 163 | + |
| 164 | + - name: Setup node |
| 165 | + uses: actions/setup-node@v4 |
| 166 | + with: |
| 167 | + node-version: ${{ matrix.node }} |
| 168 | + check-latest: true |
| 169 | + cache: npm |
| 170 | + |
| 171 | + - name: Cache NPM dependencies |
| 172 | + uses: actions/cache@v3 |
| 173 | + with: |
| 174 | + path: node_modules |
| 175 | + key: npm-cache-test-${{ matrix.settings.target }}-${{ hashFiles('package-lock.json') }} |
| 176 | + |
| 177 | + - name: Install dependencies |
| 178 | + run: npm ci |
| 179 | + |
| 180 | + - name: Download artifacts |
| 181 | + uses: actions/download-artifact@v3 |
| 182 | + with: |
| 183 | + name: bindings-${{ matrix.settings.target }} |
| 184 | + path: . |
| 185 | + |
| 186 | + - name: List packages |
| 187 | + run: ls -R . |
| 188 | + shell: bash |
| 189 | + |
| 190 | + - name: Test bindings |
| 191 | + run: npm test |
| 192 | + |
| 193 | + test-linux-x64-gnu-binding: |
| 194 | + name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }} |
| 195 | + needs: |
| 196 | + - build |
| 197 | + strategy: |
| 198 | + fail-fast: false |
| 199 | + matrix: |
| 200 | + node: |
| 201 | + - '18' |
| 202 | + - '20' |
| 203 | + runs-on: ubuntu-latest |
| 204 | + |
| 205 | + steps: |
| 206 | + - uses: actions/checkout@v4 |
| 207 | + |
| 208 | + - name: Setup node |
| 209 | + uses: actions/setup-node@v4 |
| 210 | + with: |
| 211 | + node-version: ${{ matrix.node }} |
| 212 | + check-latest: true |
| 213 | + cache: npm |
| 214 | + |
| 215 | + - name: Cache NPM dependencies |
| 216 | + uses: actions/cache@v3 |
| 217 | + with: |
| 218 | + path: node_modules |
| 219 | + key: npm-cache-test-linux-x64-gnu-${{ hashFiles('package-lock.json') }} |
| 220 | + |
| 221 | + - name: Install dependencies |
| 222 | + run: npm ci |
| 223 | + |
| 224 | + - name: Download artifacts |
| 225 | + uses: actions/download-artifact@v3 |
| 226 | + with: |
| 227 | + name: bindings-x86_64-unknown-linux-gnu |
| 228 | + path: . |
| 229 | + |
| 230 | + - name: List packages |
| 231 | + run: ls -R . |
| 232 | + shell: bash |
| 233 | + |
| 234 | + - name: Test bindings |
| 235 | + run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim npm test |
| 236 | + |
| 237 | + publish: |
| 238 | + name: Publish |
| 239 | + runs-on: ubuntu-latest |
| 240 | + if: startsWith(github.ref, 'refs/tags/v') |
| 241 | + needs: |
| 242 | + - test-macOS-windows-binding |
| 243 | + - test-linux-x64-gnu-binding |
| 244 | + |
| 245 | + steps: |
| 246 | + - uses: actions/checkout@v4 |
| 247 | + |
| 248 | + - name: Setup node |
| 249 | + uses: actions/setup-node@v4 |
| 250 | + with: |
| 251 | + node-version: 18 |
| 252 | + check-latest: true |
| 253 | + cache: npm |
| 254 | + |
| 255 | + - name: Cache NPM dependencies |
| 256 | + uses: actions/cache@v3 |
| 257 | + with: |
| 258 | + path: node_modules |
| 259 | + key: npm-cache-ubuntu-latest-${{ hashFiles('package-lock.json') }} |
| 260 | + |
| 261 | + - name: Install dependencies |
| 262 | + run: npm ci |
| 263 | + |
| 264 | + - name: Download all artifacts |
| 265 | + uses: actions/download-artifact@v3 |
| 266 | + with: |
| 267 | + path: artifacts |
| 268 | + |
| 269 | + - name: Move artifacts |
| 270 | + run: | |
| 271 | + mkdir -p dist |
| 272 | + for artifact in artifacts/bindings-*; do |
| 273 | + mv $artifact/*.node dist/ |
| 274 | + done |
| 275 | +
|
| 276 | + - name: List packages |
| 277 | + run: ls -R . |
| 278 | + shell: bash |
| 279 | + |
| 280 | + - name: Publish |
| 281 | + env: |
| 282 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 283 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 284 | + run: | |
| 285 | + if [ -z "$NPM_TOKEN" ]; then |
| 286 | + echo "NPM_TOKEN is not set, skipping publish" |
| 287 | + exit 0 |
| 288 | + fi |
| 289 | + npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN |
| 290 | + npm publish --access public |
0 commit comments