|
| 1 | +name: Release NAPI transform |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - npm/oxc-transform/package.json # Please only commit this file, so we don't need to wait for test CI to pass. |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 12 | + cancel-in-progress: true |
| 13 | + |
| 14 | +defaults: |
| 15 | + run: |
| 16 | + shell: bash |
| 17 | + |
| 18 | +jobs: |
| 19 | + check: |
| 20 | + name: Check version |
| 21 | + runs-on: ubuntu-latest |
| 22 | + outputs: |
| 23 | + version: ${{ env.version }} |
| 24 | + version_changed: ${{ steps.version.outputs.changed }} |
| 25 | + steps: |
| 26 | + - uses: taiki-e/checkout-action@v1 |
| 27 | + |
| 28 | + - name: Check version changes |
| 29 | + uses: EndBug/version-check@v2 |
| 30 | + id: version |
| 31 | + with: |
| 32 | + static-checking: localIsNew |
| 33 | + file-url: https://unpkg.com/oxc-transform@latest/package.json |
| 34 | + file-name: npm/oxc-transform/package.json |
| 35 | + |
| 36 | + - name: Set version name |
| 37 | + if: steps.version.outputs.changed == 'true' |
| 38 | + run: | |
| 39 | + echo "Version change found! New version: ${{ steps.version.outputs.version }} (${{ steps.version.outputs.version_type }})" |
| 40 | + echo "version=${{ steps.version.outputs.version }}" >> $GITHUB_ENV |
| 41 | +
|
| 42 | + build: |
| 43 | + needs: check |
| 44 | + if: needs.check.outputs.version_changed == 'true' |
| 45 | + env: |
| 46 | + version: ${{ needs.check.outputs.version }} |
| 47 | + outputs: |
| 48 | + version: ${{ env.version }} |
| 49 | + strategy: |
| 50 | + fail-fast: false |
| 51 | + matrix: |
| 52 | + include: |
| 53 | + - os: windows-latest |
| 54 | + target: x86_64-pc-windows-msvc |
| 55 | + code-target: win32-x64-msvc |
| 56 | + |
| 57 | + - os: windows-latest |
| 58 | + target: aarch64-pc-windows-msvc |
| 59 | + code-target: win32-arm64-msvc |
| 60 | + |
| 61 | + - os: ubuntu-latest |
| 62 | + target: x86_64-unknown-linux-gnu |
| 63 | + code-target: linux-x64-gnu |
| 64 | + |
| 65 | + - os: ubuntu-latest |
| 66 | + target: aarch64-unknown-linux-gnu |
| 67 | + code-target: linux-arm64-gnu |
| 68 | + |
| 69 | + - os: ubuntu-latest |
| 70 | + target: x86_64-unknown-linux-musl |
| 71 | + code-target: linux-x64-musl |
| 72 | + |
| 73 | + - os: ubuntu-latest |
| 74 | + target: aarch64-unknown-linux-musl |
| 75 | + code-target: linux-arm64-musl |
| 76 | + |
| 77 | + - os: macos-13 |
| 78 | + target: x86_64-apple-darwin |
| 79 | + code-target: darwin-x64 |
| 80 | + |
| 81 | + - os: macos-14 # M1 |
| 82 | + target: aarch64-apple-darwin |
| 83 | + code-target: darwin-arm64 |
| 84 | + |
| 85 | + name: Package ${{ matrix.target }} |
| 86 | + runs-on: ${{ matrix.os }} |
| 87 | + steps: |
| 88 | + - uses: taiki-e/checkout-action@v1 |
| 89 | + |
| 90 | + ### install musl dependencies ### |
| 91 | + |
| 92 | + - uses: goto-bus-stop/setup-zig@v2 |
| 93 | + if: ${{ contains(matrix.target, 'musl') }} |
| 94 | + with: |
| 95 | + version: 0.11.0 |
| 96 | + |
| 97 | + - name: Install cargo-zigbuild |
| 98 | + if: ${{ contains(matrix.target, 'musl') }} |
| 99 | + uses: taiki-e/install-action@v2 |
| 100 | + with: |
| 101 | + tool: cargo-zigbuild |
| 102 | + |
| 103 | + ### install non-musl dependencies ### |
| 104 | + |
| 105 | + - name: Install cross |
| 106 | + if: ${{ !contains(matrix.target, 'musl') }} |
| 107 | + uses: taiki-e/install-action@cross |
| 108 | + |
| 109 | + ### Build |
| 110 | + |
| 111 | + - name: Add Rust Target |
| 112 | + run: rustup target add ${{ matrix.target }} |
| 113 | + |
| 114 | + - name: Build with cross |
| 115 | + if: ${{ !contains(matrix.target, 'musl') }} |
| 116 | + run: cross build --release -p oxc_transform_napi --target=${{ matrix.target }} |
| 117 | + |
| 118 | + - name: Build with zig |
| 119 | + if: ${{ contains(matrix.target, 'musl') }} |
| 120 | + env: |
| 121 | + RUSTFLAGS: "-C target-feature=-crt-static" |
| 122 | + run: cargo zigbuild --release -p oxc_transform_napi --target=${{ matrix.target }} |
| 123 | + |
| 124 | + ### Build Done |
| 125 | + |
| 126 | + - name: Move file on ${{ matrix.os }} |
| 127 | + run: | |
| 128 | + shopt -s extglob |
| 129 | + ls target/${{ matrix.target }}/release/*.@(so|dll|dylib) |
| 130 | + mv target/${{ matrix.target }}/release/*.@(so|dll|dylib) napi/transform/transform.${{ matrix.code-target }}.node |
| 131 | + ls napi/transform |
| 132 | +
|
| 133 | + - name: Test |
| 134 | + working-directory: napi/transform |
| 135 | + if: ${{ contains(matrix.target, 'x86') && !contains(matrix.target, 'musl') }} # Need docker for aarch64 |
| 136 | + run: | |
| 137 | + ls |
| 138 | + node test.mjs |
| 139 | +
|
| 140 | + # The binary is zipped to fix permission loss https://github.com/actions/upload-artifact#permission-loss |
| 141 | + - name: Archive Binary |
| 142 | + if: runner.os == 'Windows' |
| 143 | + run: 7z a ${{ matrix.code-target }}.zip napi/transform/transform.${{ matrix.code-target }}.node |
| 144 | + |
| 145 | + # The binary is zipped to fix permission loss https://github.com/actions/upload-artifact#permission-loss |
| 146 | + - name: Archive Binary |
| 147 | + if: runner.os != 'Windows' |
| 148 | + run: tar czf ${{ matrix.code-target }}.tar.gz napi/transform/transform.${{ matrix.code-target }}.node |
| 149 | + |
| 150 | + - name: Upload artifact |
| 151 | + uses: actions/upload-artifact@v4 |
| 152 | + with: |
| 153 | + if-no-files-found: error |
| 154 | + name: binaries-${{ matrix.code-target }} |
| 155 | + path: | |
| 156 | + *.zip |
| 157 | + *.tar.gz |
| 158 | +
|
| 159 | + publish: |
| 160 | + name: Publish NAPI |
| 161 | + runs-on: ubuntu-latest |
| 162 | + permissions: |
| 163 | + id-token: write # for `npm publish --provenance` |
| 164 | + needs: |
| 165 | + - build |
| 166 | + steps: |
| 167 | + - uses: taiki-e/checkout-action@v1 |
| 168 | + |
| 169 | + - name: Install Node.js |
| 170 | + uses: actions/setup-node@v4 |
| 171 | + with: |
| 172 | + node-version-file: .node-version |
| 173 | + registry-url: 'https://registry.npmjs.org' |
| 174 | + |
| 175 | + - name: Download Artifacts |
| 176 | + uses: actions/download-artifact@v4 |
| 177 | + with: |
| 178 | + merge-multiple: true |
| 179 | + |
| 180 | + - name: Unzip |
| 181 | + uses: montudor/action-zip@v1 |
| 182 | + with: |
| 183 | + args: unzip -qq *.zip -d . |
| 184 | + |
| 185 | + - name: Untar |
| 186 | + run: ls *.gz | xargs -i tar xvf {} |
| 187 | + |
| 188 | + - name: Generate npm packages |
| 189 | + run: | |
| 190 | + ls |
| 191 | + ls napi/transform |
| 192 | + node npm/oxc-transform/scripts/generate-packages.mjs |
| 193 | + cat npm/oxc-transform/package.json |
| 194 | + for package in npm/oxc-transform* |
| 195 | + do |
| 196 | + ls $package |
| 197 | + cat $package/package.json |
| 198 | + echo '----' |
| 199 | + done |
| 200 | +
|
| 201 | + - name: Publish npm packages as latest |
| 202 | + env: |
| 203 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 204 | + # NOTE: The trailing slash on $package/ changes it to publishing the directory |
| 205 | + run: | |
| 206 | + # publish subpackages first |
| 207 | + for package in npm/oxc-transform-* |
| 208 | + do |
| 209 | + npm publish $package/ --tag latest --provenance --access public |
| 210 | + done |
| 211 | + # publish root package last |
| 212 | + npm publish npm/oxc-transform/ --provenance --access public --tag latest |
0 commit comments