diff --git a/.github/workflows/build-wasm.yml b/.github/workflows/build-wasm.yml new file mode 100644 index 0000000000..6fc016ab26 --- /dev/null +++ b/.github/workflows/build-wasm.yml @@ -0,0 +1,58 @@ +# Build ruff_wasm for npm. +# +# Assumed to run as a subworkflow of .github/workflows/release.yml; specifically, as a local +# artifacts job within `cargo-dist`. +name: "Build wasm" + +on: + workflow_call: + inputs: + plan: + required: true + type: string + pull_request: + paths: + - .github/workflows/build-wasm.yml + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: {} + +env: + CARGO_INCREMENTAL: 0 + CARGO_NET_RETRY: 10 + CARGO_TERM_COLOR: always + RUSTUP_MAX_RETRIES: 10 + +jobs: + build: + if: ${{ !contains(github.event.pull_request.labels.*.name, 'no-build') }} + runs-on: ubuntu-latest + strategy: + matrix: + target: [web, bundler, nodejs] + fail-fast: false + steps: + - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 + with: + persist-credentials: false + - name: "Install Rust toolchain" + run: rustup target add wasm32-unknown-unknown + - uses: jetli/wasm-pack-action@0d096b08b4e5a7de8c28de67e11e945404e9eefa # v0.4.0 + with: + version: v0.13.1 + - uses: jetli/wasm-bindgen-action@20b33e20595891ab1a0ed73145d8a21fc96e7c29 # v0.2.0 + - name: "Run wasm-pack build" + run: wasm-pack build --target ${{ matrix.target }} crates/ruff_wasm + - name: "Rename generated package" + run: | # Replace the package name w/ jq + jq '.name="@astral-sh/ruff-wasm-${{ matrix.target }}"' crates/ruff_wasm/pkg/package.json > /tmp/package.json + mv /tmp/package.json crates/ruff_wasm/pkg + - run: cp LICENSE crates/ruff_wasm/pkg # wasm-pack does not put the LICENSE file in the pkg + - name: "Upload wasm artifact" + uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 + with: + name: artifacts-wasm-${{ matrix.target }} + path: crates/ruff_wasm/pkg diff --git a/.github/workflows/publish-wasm.yml b/.github/workflows/publish-wasm.yml index 84675bdc61..786225f920 100644 --- a/.github/workflows/publish-wasm.yml +++ b/.github/workflows/publish-wasm.yml @@ -1,25 +1,18 @@ -# Build and publish ruff-api for wasm. +# Publish ruff_wasm to npm. # # Assumed to run as a subworkflow of .github/workflows/release.yml; specifically, as a publish # job within `cargo-dist`. -name: "Build and publish wasm" +name: "Publish wasm" on: - workflow_dispatch: workflow_call: inputs: plan: required: true type: string -env: - CARGO_INCREMENTAL: 0 - CARGO_NET_RETRY: 10 - CARGO_TERM_COLOR: always - RUSTUP_MAX_RETRIES: 10 - jobs: - ruff_wasm: + publish: runs-on: ubuntu-latest permissions: contents: read @@ -29,31 +22,19 @@ jobs: target: [web, bundler, nodejs] fail-fast: false steps: - - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 + - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 with: - persist-credentials: false - - name: "Install Rust toolchain" - run: rustup target add wasm32-unknown-unknown - - uses: jetli/wasm-pack-action@0d096b08b4e5a7de8c28de67e11e945404e9eefa # v0.4.0 - with: - version: v0.13.1 - - uses: jetli/wasm-bindgen-action@20b33e20595891ab1a0ed73145d8a21fc96e7c29 # v0.2.0 - - name: "Run wasm-pack build" - run: wasm-pack build --target ${{ matrix.target }} crates/ruff_wasm - - name: "Rename generated package" - run: | # Replace the package name w/ jq - jq '.name="@astral-sh/ruff-wasm-${{ matrix.target }}"' crates/ruff_wasm/pkg/package.json > /tmp/package.json - mv /tmp/package.json crates/ruff_wasm/pkg - - run: cp LICENSE crates/ruff_wasm/pkg # wasm-pack does not put the LICENSE file in the pkg + name: artifacts-wasm-${{ matrix.target }} + path: pkg - uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 with: node-version: 24 registry-url: "https://registry.npmjs.org" - name: "Publish (dry-run)" if: ${{ inputs.plan == '' || fromJson(inputs.plan).announcement_tag_is_implicit }} - run: npm publish --dry-run crates/ruff_wasm/pkg + run: npm publish --dry-run pkg - name: "Publish" if: ${{ inputs.plan != '' && !fromJson(inputs.plan).announcement_tag_is_implicit }} - run: npm publish --provenance --access public crates/ruff_wasm/pkg + run: npm publish --provenance --access public pkg env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 51120aadb9..978a359e33 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -112,12 +112,22 @@ jobs: "contents": "read" "packages": "write" + custom-build-wasm: + needs: + - plan + if: ${{ needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload' || inputs.tag == 'dry-run' }} + uses: ./.github/workflows/build-wasm.yml + with: + plan: ${{ needs.plan.outputs.val }} + secrets: inherit + # Build and package all the platform-agnostic(ish) things build-global-artifacts: needs: - plan - custom-build-binaries - custom-build-docker + - custom-build-wasm runs-on: "depot-ubuntu-latest-4" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -165,9 +175,10 @@ jobs: - plan - custom-build-binaries - custom-build-docker + - custom-build-wasm - build-global-artifacts # Only run if we're "publishing", and only if plan, local and global didn't fail (skipped is fine) - if: ${{ always() && needs.plan.result == 'success' && needs.plan.outputs.publishing == 'true' && (needs.build-global-artifacts.result == 'skipped' || needs.build-global-artifacts.result == 'success') && (needs.custom-build-binaries.result == 'skipped' || needs.custom-build-binaries.result == 'success') && (needs.custom-build-docker.result == 'skipped' || needs.custom-build-docker.result == 'success') }} + if: ${{ always() && needs.plan.result == 'success' && needs.plan.outputs.publishing == 'true' && (needs.build-global-artifacts.result == 'skipped' || needs.build-global-artifacts.result == 'success') && (needs.custom-build-binaries.result == 'skipped' || needs.custom-build-binaries.result == 'success') && (needs.custom-build-docker.result == 'skipped' || needs.custom-build-docker.result == 'success') && (needs.custom-build-wasm.result == 'skipped' || needs.custom-build-wasm.result == 'success') }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} runs-on: "depot-ubuntu-latest-4" diff --git a/dist-workspace.toml b/dist-workspace.toml index 002337b47e..bcb3288f0b 100644 --- a/dist-workspace.toml +++ b/dist-workspace.toml @@ -50,7 +50,7 @@ github-release = "announce" # Whether CI should include auto-generated code to build local artifacts build-local-artifacts = false # Local artifacts jobs to run in CI -local-artifacts-jobs = ["./build-binaries", "./build-docker"] +local-artifacts-jobs = ["./build-binaries", "./build-docker", "./build-wasm"] # Publish jobs to run in CI publish-jobs = ["./publish-pypi", "./publish-wasm"] # Post-announce jobs to run in CI