Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve ci perf #21

Merged
merged 25 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/actions/build-rspack/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: "Build Rspack"
description: "Checkout, download rspack binding, and build rspack js"

inputs:
repository:
description: "The rspack repository to use"
required: true
default: "web-infra-dev/rspack"
path:
description: "Destination path to the rspack repository"
required: true
default: ".rspack"
ref:
description: "The branch, tag or SHA to checkout"
required: true
default: "main"
node-version:
description: "The version of Node.js to set up"
required: true
default: "18"

outputs:
artifact-name:
description: "The name of the uploaded artifact"

runs:
using: composite
steps:
- shell: bash
run: |
npm install -g corepack@0.24.1
echo "Corepack version: $(corepack --version)"
corepack enable
- shell: bash
run: pnpm --version
- shell: bash
run: pnpm install --prefer-frozen-lockfile --prefer-offline
- name: Build Rspack JS
shell: bash
run: >-
node bin/cli.js build
--repository ${{ inputs.repository }}
--ref ${{ inputs.ref }}
--binding false
--js true
- uses: actions/download-artifact@v4
with:
name: binding-linux-x64-gnu
path: ${{ inputs.path }}/crates/node_binding
- name: Show restored binding
shell: bash
run: ls -lah ${{ inputs.path }}/crates/node_binding/*.node
4 changes: 2 additions & 2 deletions .github/actions/env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ runs:
using: composite
steps:
- name: Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20
- name: Activate corepack
Expand All @@ -19,7 +19,7 @@ runs:
corepack enable
- name: Install dependencies with pnpm
shell: bash
run: pnpm install
run: pnpm install --prefer-frozen-lockfile --prefer-offline
- name: Set Rspack Dir
shell: bash
run: |
Expand Down
41 changes: 41 additions & 0 deletions .github/actions/prepare-rspack-binding/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: "Prepare Rspack Binding"
description: "Checkout, build, and upload rspack native bindings"

inputs:
repository:
description: "The rspack repository to use"
required: true
default: "web-infra-dev/rspack"
path:
description: "Destination path to clone"
required: true
default: ".rspack"
ref:
description: "The branch, tag or SHA to checkout"
required: true
default: "main"
node-version:
description: "The version of Node.js to set up"
required: true
default: "18"

outputs:
artifact-name:
description: "The name of the uploaded artifact"

runs:
using: composite
steps:
- name: Build Rspack
shell: bash
run: >-
node bin/cli.js build
--repository ${{ inputs.repository }}
--ref ${{ inputs.ref }}
--binding true
--js false
- uses: actions/upload-artifact@v4
with:
name: binding-linux-x64-gnu
path: ${{ inputs.path }}/crates/node_binding/*.node
compression-level: 9
65 changes: 46 additions & 19 deletions .github/workflows/bench_rspack_commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,70 @@ on:
type: string

jobs:
run-bench:
prepare-binding:
name: Prepare Rspack Binding
runs-on: [self-hosted, benchmark]
outputs:
diff-result: ${{ steps.print-results.outputs.diff-result }}
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Init env
uses: ./.github/actions/env
- name: Build rspack
run: node bin/build-rspack.js origin ${{ inputs.commit_sha }}
- uses: ./.github/actions/prepare-rspack-binding
with:
path: ${{ env.RSPACK_DIR }}

bench:
runs-on: [self-hosted, benchmark]
needs: prepare-binding
timeout-minutes: 30
strategy:
matrix:
shardIndex: [1, 2, 3]
shardTotal: [3]
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Init env
uses: ./.github/actions/env
- uses: ./.github/actions/build-rspack
with:
path: ${{ env.RSPACK_DIR }}
- name: Run benchmark
run: node bin/bench.js
run: node bin/cli.js bench --shard ${{ matrix.shardIndex }}/${{ smatrix.shardTotal }}
- uses: actions/upload-artifact@v4
with:
name: benchmark-artifacts-${{ matrix.shardIndex }}-${{ matrix.shardTotal }}
path: output

comment-compare-results:
runs-on: ubuntu-latest
needs: bench
if: always()
steps:
- uses: actions/checkout@v4
- name: Init env
uses: ./.github/actions/env
- uses: actions/download-artifact@v4
with:
pattern: benchmark-artifacts-*
path: output
merge-multiple: true
- id: print-results
name: Print results
run: |
result=$(node bin/compare-bench.js latest current)
result=$(node bin/cli.js compare --base latest --current current)
echo "$result"
echo "diff-result=${result//$'\n'/'@@'}" >> $GITHUB_OUTPUT
if [[ $result =~ "Threshold exceeded" ]]; then
echo "Some benchmark cases exceed the threshold, please visit the previous step for more information"
exit 1
fi

create-comment:
runs-on: ubuntu-latest
needs: [run-bench]
if: always()
steps:
- id: create-comment
uses: actions/github-script@v6
- uses: actions/github-script@v6
with:
github-token: ${{ secrets.RSPACK_BOT_ACCESS_TOKEN }}
result-encoding: string
script: |
const diffResult = `${{ needs.run-bench.outputs.diff-result }}`
let result = "task ${{ needs.run-bench.result }}"
const diffResult = `${{ steps.print-results.outputs.diff-result }}`
let result = "task ${{ needs.bench.result }}"
if (diffResult) {
result = diffResult.replace(/@@/g, "\n");
}
Expand Down
62 changes: 46 additions & 16 deletions .github/workflows/bench_rspack_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,42 +31,72 @@ jobs:
})
return comment.id

run-bench:
prepare-binding:
name: Prepare Rspack Binding
runs-on: [self-hosted, benchmark]
needs: create-comment
steps:
- uses: actions/checkout@v4
- name: Init env
uses: ./.github/actions/env
- uses: ./.github/actions/prepare-rspack-binding
with:
path: ${{ env.RSPACK_DIR }}

bench:
runs-on: [self-hosted, benchmark]
needs: [create-comment, prepare-binding]
timeout-minutes: 30
strategy:
matrix:
shardIndex: [1, 2, 3]
shardTotal: [3]
fail-fast: false
outputs:
diff-result: ${{ steps.print-results.outputs.diff-result }}
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Init env
uses: ./.github/actions/env
- name: Build rspack
run: node bin/build-rspack.js origin pull/${{ inputs.prNumber }}/head
- uses: ./.github/actions/build-rspack
with:
path: ${{ env.RSPACK_DIR }}
ref: pull/${{ inputs.prNumber }}/head
- name: Run benchmark
run: node bin/bench.js
run: node bin/cli.js bench --shard ${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
- uses: actions/upload-artifact@v4
with:
name: benchmark-artifacts-${{ matrix.shardIndex }}-${{ matrix.shardTotal }}
path: output

comment-compare-results:
runs-on: ubuntu-latest
needs: [create-comment, bench]
if: always()
steps:
- uses: actions/checkout@v4
- name: Init env
uses: ./.github/actions/env
- uses: actions/download-artifact@v4
with:
pattern: benchmark-artifacts-*
path: output
merge-multiple: true
- id: print-results
name: Print results
run: |
result=$(node bin/compare-bench.js latest current)
result=$(node bin/cli.js compare --base latest --current current)
echo "$result"
echo "diff-result=${result//$'\n'/'@@'}" >> $GITHUB_OUTPUT
if [[ $result =~ "Threshold exceeded" ]]; then
echo "Some benchmark cases exceed the threshold, please visit the previous step for more information"
exit 1
fi

update-comment:
runs-on: ubuntu-latest
needs: [create-comment, run-bench]
if: always()
steps:
- uses: actions/github-script@v6
with:
github-token: ${{ secrets.RSPACK_BOT_ACCESS_TOKEN }}
script: |
const diffResult = `${{ needs.run-bench.outputs.diff-result }}`
let result = "task ${{ needs.run-bench.result }}"
const diffResult = `${{ steps.print-results.outputs.diff-result }}`
let result = "task ${{ needs.bench.result }}"
if (diffResult) {
result = diffResult.replace(/@@/g, "\n");
}
Expand Down
33 changes: 26 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- "**/*.md"
pull_request:
types: [opened, synchronize]
branches: [ main ]
branches: [main]
paths-ignore:
- "**/*.md"

Expand All @@ -17,21 +17,40 @@ concurrency:
cancel-in-progress: ${{ github.ref_name != 'main' }}

jobs:
ci:
prepare-binding:
name: Prepare Rspack Binding
runs-on: [self-hosted, benchmark]
steps:
- uses: actions/checkout@v4
- name: Init env
uses: ./.github/actions/env
- uses: ./.github/actions/prepare-rspack-binding
with:
path: ${{ env.RSPACK_DIR }}

bench:
needs: prepare-binding
runs-on: [self-hosted, benchmark]
timeout-minutes: 30
strategy:
matrix:
shardIndex: [1, 2, 3]
shardTotal: [3]
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Init env
uses: ./.github/actions/env
- name: Build rspack
run: node bin/build-rspack.js
- uses: ./.github/actions/build-rspack
with:
path: ${{ env.RSPACK_DIR }}
- name: Run benchmark
run: node bin/bench.js
run: node bin/cli.js bench --shard ${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
- id: print-compare-results
name: Print compare results
run: |
result=$(node bin/compare-bench.js latest current)
result=$(node bin/cli.js compare --base latest --current current)
echo "$result"
echo "diff-result=${result//$'\n'/'@@'}" >> $GITHUB_OUTPUT
- name: Check Threshold
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/scheduled_bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ jobs:
bench:
runs-on: [self-hosted, benchmark]
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Init env
uses: ./.github/actions/env
- name: Build rspack
run: node bin/build-rspack.js
run: node bin/cli.js build
- name: Run benchmark
run: node bin/bench.js
run: node bin/cli.js bench
- id: print-compare-results
name: Print compare results
run: |
result=$(node bin/compare-bench.js latest current)
result=$(node bin/cli.js compare --base latest --current current)
echo "$result"
echo "diff-result=${result//$'\n'/'@@'}" >> $GITHUB_OUTPUT
- name: Setup git user
Expand Down
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.rspack/**
output/**
cases/**
pnpm-lock.yaml
pnpm-workspace.yaml
Loading
Loading