|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + tags: |
| 7 | + - 'v*' |
| 8 | + pull_request: |
| 9 | + branches: [main] |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +env: |
| 13 | + CARGO_TERM_COLOR: always |
| 14 | + APP_NAME: es-module-lexer-rs-native |
| 15 | + |
| 16 | +jobs: |
| 17 | + build: |
| 18 | + name: Build - ${{ matrix.settings.target }} |
| 19 | + runs-on: ${{ matrix.settings.host }} |
| 20 | + strategy: |
| 21 | + fail-fast: false |
| 22 | + matrix: |
| 23 | + settings: |
| 24 | + # Linux x64 |
| 25 | + - host: ubuntu-latest |
| 26 | + target: x86_64-unknown-linux-gnu |
| 27 | + build: | |
| 28 | + cd packages/es-module-lexer-rs |
| 29 | + pnpm build:rust --target x86_64-unknown-linux-gnu |
| 30 | + |
| 31 | + # Linux ARM64 |
| 32 | + - host: ubuntu-latest |
| 33 | + target: aarch64-unknown-linux-gnu |
| 34 | + build: | |
| 35 | + cd packages/es-module-lexer-rs |
| 36 | + sudo apt-get update |
| 37 | + sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu |
| 38 | + pnpm build:rust --target aarch64-unknown-linux-gnu |
| 39 | + |
| 40 | + # macOS x64 |
| 41 | + - host: macos-latest |
| 42 | + target: x86_64-apple-darwin |
| 43 | + build: | |
| 44 | + cd packages/es-module-lexer-rs |
| 45 | + pnpm build:rust --target x86_64-apple-darwin |
| 46 | + |
| 47 | + # macOS ARM64 (Apple Silicon) |
| 48 | + - host: macos-latest |
| 49 | + target: aarch64-apple-darwin |
| 50 | + build: | |
| 51 | + cd packages/es-module-lexer-rs |
| 52 | + pnpm build:rust --target aarch64-apple-darwin |
| 53 | + |
| 54 | + # Windows x64 |
| 55 | + - host: windows-latest |
| 56 | + target: x86_64-pc-windows-msvc |
| 57 | + build: | |
| 58 | + cd packages/es-module-lexer-rs |
| 59 | + pnpm build:rust --target x86_64-pc-windows-msvc |
| 60 | +
|
| 61 | + steps: |
| 62 | + - name: Checkout |
| 63 | + uses: actions/checkout@v4 |
| 64 | + |
| 65 | + - name: Setup pnpm |
| 66 | + uses: pnpm/action-setup@v2 |
| 67 | + with: |
| 68 | + version: 8 |
| 69 | + |
| 70 | + - name: Setup Node.js |
| 71 | + uses: actions/setup-node@v4 |
| 72 | + with: |
| 73 | + node-version: '20' |
| 74 | + cache: 'pnpm' |
| 75 | + |
| 76 | + - name: Setup Rust |
| 77 | + uses: dtolnay/rust-toolchain@stable |
| 78 | + with: |
| 79 | + targets: ${{ matrix.settings.target }} |
| 80 | + |
| 81 | + - name: Cache Rust |
| 82 | + uses: Swatinem/rust-cache@v2 |
| 83 | + with: |
| 84 | + key: ${{ matrix.settings.target }} |
| 85 | + |
| 86 | + - name: Install dependencies |
| 87 | + run: pnpm install |
| 88 | + |
| 89 | + - name: Build |
| 90 | + run: ${{ matrix.settings.build }} |
| 91 | + shell: bash |
| 92 | + |
| 93 | + - name: Upload artifact |
| 94 | + uses: actions/upload-artifact@v4 |
| 95 | + with: |
| 96 | + name: bindings-${{ matrix.settings.target }} |
| 97 | + path: packages/es-module-lexer-rs/*.node |
| 98 | + if-no-files-found: error |
| 99 | + |
| 100 | + build-freebsd: |
| 101 | + name: Build - x86_64-unknown-freebsd |
| 102 | + runs-on: ubuntu-latest |
| 103 | + steps: |
| 104 | + - name: Checkout |
| 105 | + uses: actions/checkout@v4 |
| 106 | + |
| 107 | + - name: Setup pnpm |
| 108 | + uses: pnpm/action-setup@v2 |
| 109 | + with: |
| 110 | + version: 8 |
| 111 | + |
| 112 | + - name: Setup Node.js |
| 113 | + uses: actions/setup-node@v4 |
| 114 | + with: |
| 115 | + node-version: '20' |
| 116 | + cache: 'pnpm' |
| 117 | + |
| 118 | + - name: Install dependencies |
| 119 | + run: pnpm install |
| 120 | + |
| 121 | + - name: Build in FreeBSD |
| 122 | + uses: cross-platform-actions/action@v0.23.0 |
| 123 | + env: |
| 124 | + DEBUG: napi:* |
| 125 | + RUSTUP_IO_THREADS: 1 |
| 126 | + with: |
| 127 | + operating_system: freebsd |
| 128 | + version: '13.2' |
| 129 | + memory: 8G |
| 130 | + cpu_count: 3 |
| 131 | + shell: bash |
| 132 | + run: | |
| 133 | + sudo pkg install -y -f curl node libnghttp2 npm |
| 134 | + sudo npm install -g pnpm |
| 135 | + curl https://sh.rustup.rs -sSf --output rustup.sh |
| 136 | + sh rustup.sh -y --profile minimal --default-toolchain stable |
| 137 | + source "$HOME/.cargo/env" |
| 138 | + cd packages/es-module-lexer-rs |
| 139 | + pnpm build:rust --target x86_64-unknown-freebsd |
| 140 | +
|
| 141 | + - name: Upload artifact |
| 142 | + uses: actions/upload-artifact@v4 |
| 143 | + with: |
| 144 | + name: bindings-x86_64-unknown-freebsd |
| 145 | + path: packages/es-module-lexer-rs/*.node |
| 146 | + if-no-files-found: error |
| 147 | + |
| 148 | + test-bindings: |
| 149 | + name: Test bindings - ${{ matrix.settings.target }} |
| 150 | + needs: build |
| 151 | + runs-on: ${{ matrix.settings.host }} |
| 152 | + strategy: |
| 153 | + fail-fast: false |
| 154 | + matrix: |
| 155 | + settings: |
| 156 | + - host: ubuntu-latest |
| 157 | + target: x86_64-unknown-linux-gnu |
| 158 | + - host: macos-latest |
| 159 | + target: x86_64-apple-darwin |
| 160 | + - host: macos-latest |
| 161 | + target: aarch64-apple-darwin |
| 162 | + - host: windows-latest |
| 163 | + target: x86_64-pc-windows-msvc |
| 164 | + |
| 165 | + steps: |
| 166 | + - name: Checkout |
| 167 | + uses: actions/checkout@v4 |
| 168 | + |
| 169 | + - name: Setup pnpm |
| 170 | + uses: pnpm/action-setup@v2 |
| 171 | + with: |
| 172 | + version: 8 |
| 173 | + |
| 174 | + - name: Setup Node.js |
| 175 | + uses: actions/setup-node@v4 |
| 176 | + with: |
| 177 | + node-version: '20' |
| 178 | + cache: 'pnpm' |
| 179 | + |
| 180 | + - name: Install dependencies |
| 181 | + run: pnpm install |
| 182 | + |
| 183 | + - name: Download artifact |
| 184 | + uses: actions/download-artifact@v4 |
| 185 | + with: |
| 186 | + name: bindings-${{ matrix.settings.target }} |
| 187 | + path: packages/es-module-lexer-rs |
| 188 | + |
| 189 | + - name: List packages |
| 190 | + run: ls -R packages/es-module-lexer-rs |
| 191 | + shell: bash |
| 192 | + |
| 193 | + - name: Build TypeScript |
| 194 | + run: | |
| 195 | + cd packages/es-module-lexer-rs |
| 196 | + pnpm build:ts |
| 197 | +
|
| 198 | + - name: Test bindings |
| 199 | + run: | |
| 200 | + cd packages/es-module-lexer-rs |
| 201 | + pnpm test |
| 202 | +
|
| 203 | + universal-macOS: |
| 204 | + name: Build universal macOS binary |
| 205 | + needs: build |
| 206 | + runs-on: macos-latest |
| 207 | + steps: |
| 208 | + - name: Checkout |
| 209 | + uses: actions/checkout@v4 |
| 210 | + |
| 211 | + - name: Setup pnpm |
| 212 | + uses: pnpm/action-setup@v2 |
| 213 | + with: |
| 214 | + version: 8 |
| 215 | + |
| 216 | + - name: Setup Node.js |
| 217 | + uses: actions/setup-node@v4 |
| 218 | + with: |
| 219 | + node-version: '20' |
| 220 | + cache: 'pnpm' |
| 221 | + |
| 222 | + - name: Install dependencies |
| 223 | + run: pnpm install |
| 224 | + |
| 225 | + - name: Download x64 artifact |
| 226 | + uses: actions/download-artifact@v4 |
| 227 | + with: |
| 228 | + name: bindings-x86_64-apple-darwin |
| 229 | + path: packages/es-module-lexer-rs/artifacts/x64 |
| 230 | + |
| 231 | + - name: Download arm64 artifact |
| 232 | + uses: actions/download-artifact@v4 |
| 233 | + with: |
| 234 | + name: bindings-aarch64-apple-darwin |
| 235 | + path: packages/es-module-lexer-rs/artifacts/arm64 |
| 236 | + |
| 237 | + - name: Create universal binary |
| 238 | + run: | |
| 239 | + cd packages/es-module-lexer-rs |
| 240 | + lipo -create \ |
| 241 | + artifacts/x64/*.node \ |
| 242 | + artifacts/arm64/*.node \ |
| 243 | + -output es-module-lexer-rs-native.darwin-universal.node |
| 244 | +
|
| 245 | + - name: Upload artifact |
| 246 | + uses: actions/upload-artifact@v4 |
| 247 | + with: |
| 248 | + name: bindings-universal-apple-darwin |
| 249 | + path: packages/es-module-lexer-rs/*.node |
| 250 | + if-no-files-found: error |
| 251 | + |
| 252 | + publish: |
| 253 | + name: Publish to npm |
| 254 | + runs-on: ubuntu-latest |
| 255 | + needs: |
| 256 | + - test-bindings |
| 257 | + - universal-macOS |
| 258 | + if: startsWith(github.ref, 'refs/tags/v') |
| 259 | + steps: |
| 260 | + - name: Checkout |
| 261 | + uses: actions/checkout@v4 |
| 262 | + |
| 263 | + - name: Setup pnpm |
| 264 | + uses: pnpm/action-setup@v2 |
| 265 | + with: |
| 266 | + version: 8 |
| 267 | + |
| 268 | + - name: Setup Node.js |
| 269 | + uses: actions/setup-node@v4 |
| 270 | + with: |
| 271 | + node-version: '20' |
| 272 | + cache: 'pnpm' |
| 273 | + registry-url: 'https://registry.npmjs.org' |
| 274 | + |
| 275 | + - name: Install dependencies |
| 276 | + run: pnpm install |
| 277 | + |
| 278 | + - name: Download all artifacts |
| 279 | + uses: actions/download-artifact@v4 |
| 280 | + with: |
| 281 | + path: packages/es-module-lexer-rs/artifacts |
| 282 | + |
| 283 | + - name: Move artifacts |
| 284 | + run: | |
| 285 | + cd packages/es-module-lexer-rs |
| 286 | + for dir in artifacts/bindings-*; do |
| 287 | + if [ -d "$dir" ]; then |
| 288 | + cp "$dir"/*.node . 2>/dev/null || true |
| 289 | + fi |
| 290 | + done |
| 291 | + ls -la *.node |
| 292 | +
|
| 293 | + - name: Build TypeScript |
| 294 | + run: | |
| 295 | + cd packages/es-module-lexer-rs |
| 296 | + pnpm build:ts |
| 297 | +
|
| 298 | + - name: Publish to npm |
| 299 | + run: | |
| 300 | + cd packages/es-module-lexer-rs |
| 301 | + npm publish --access public |
| 302 | + env: |
| 303 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments