Skip to content

Commit

Permalink
Skip commenting memory/perf benches on draft PRs (#1694)
Browse files Browse the repository at this point in the history
This should help reduce some of the comment noise until we have time to
customize that action some more.

I tested that this works on this PR -- the benches are not run when the
PR is a draft.

I had to pull the two relevant jobs out into a different workflow file,
because the triggers are different. For the reporting benches stage (the
memory and perf comments that show up on PRs), they'll only run if the
PR is in a draft. But, and this is the different part that required them
being in a separate file, they also need to trigger when a PR is marked
"ready for review".
  • Loading branch information
sezna authored Jul 3, 2024
1 parent c763f6e commit c023200
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 69 deletions.
90 changes: 90 additions & 0 deletions .github/workflows/bench-reports.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Benchmark Reports

on:
pull_request:
branches: "main"
types:
- opened
- reopened
- synchronize
- ready_for_review
merge_group:
workflow_dispatch:

env:
CARGO_TERM_COLOR: always
NODE_VERSION: "18.17.1"
PYTHON_VERSION: "3.11"
RUST_TOOLCHAIN_VERSION: "1.78"
RUST_TOOLCHAIN_COMPONENTS: rustfmt clippy

jobs:
runBenchmark:
if: ${{ !github.event.pull_request.draft }}
name: run benchmark
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v3
- uses: boa-dev/criterion-compare-action@v3
with:
branchName: ${{ github.base_ref }}
cwd: "compiler/qsc"
if: ${{ github.base_ref != null }}

runMemoryProfile:
if: ${{ !github.event.pull_request.draft }}
name: run memory profile
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v2
with:
ref: main
- uses: Swatinem/rust-cache@v2
- run: |
MAIN_MEASUREMENT=$(cargo run --bin memtest)
echo "MAIN_MEASUREMENT<<EOF" >> $GITHUB_ENV
echo "$MAIN_MEASUREMENT" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- run: |
echo "${{env.MAIN_MEASUREMENT}}"
echo $MAIN_MEASUREMENT
- uses: actions/checkout@v2
- run: |
BRANCH_MEASUREMENT=$(cargo run --bin memtest)
echo "BRANCH_MEASUREMENT<<EOF" >> $GITHUB_ENV
echo "$BRANCH_MEASUREMENT" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- run: |
echo "${{env.BRANCH_MEASUREMENT}}"
echo $BRANCH_MEASUREMENT
- uses: actions/github-script@v6
with:
script: |
if (${{ env.BRANCH_MEASUREMENT }} !== ${{ env.MAIN_MEASUREMENT }}) {
const difference = ${{ env.BRANCH_MEASUREMENT }} - ${{ env.MAIN_MEASUREMENT }};
try {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `_Change in memory usage detected by benchmark._
## Memory Report for ${{ github.sha }}
| Test | This Branch | On Main | Difference |
|-----------------------------|-------------|----------| ---------- |
| compile core + standard lib | ${{ env.BRANCH_MEASUREMENT }} bytes | ${{ env.MAIN_MEASUREMENT }} bytes | ${difference} bytes`
})
} catch (err) {
core.warning(`Failed writing comment on GitHub issue: ${err}`)
}
} else {
console.log("no change in memory usage detected by benchmark");
}
if: ${{ github.base_ref != null }}
70 changes: 1 addition & 69 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,77 +185,9 @@ jobs:
- name: Run integration tests
run: python ./build.py --no-check --no-test --wasm --npm --vscode --pip --widgets --integration-tests

runBenchmark:
name: run benchmark
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v3
- uses: boa-dev/criterion-compare-action@v3
with:
branchName: ${{ github.base_ref }}
cwd: "compiler/qsc"
if: ${{ github.base_ref != null }}

runMemoryProfile:
name: run memory profile
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v2
with:
ref: main
- uses: Swatinem/rust-cache@v2
- run: |
MAIN_MEASUREMENT=$(cargo run --bin memtest)
echo "MAIN_MEASUREMENT<<EOF" >> $GITHUB_ENV
echo "$MAIN_MEASUREMENT" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- run: |
echo "${{env.MAIN_MEASUREMENT}}"
echo $MAIN_MEASUREMENT
- uses: actions/checkout@v2
- run: |
BRANCH_MEASUREMENT=$(cargo run --bin memtest)
echo "BRANCH_MEASUREMENT<<EOF" >> $GITHUB_ENV
echo "$BRANCH_MEASUREMENT" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- run: |
echo "${{env.BRANCH_MEASUREMENT}}"
echo $BRANCH_MEASUREMENT
- uses: actions/github-script@v6
with:
script: |
if (${{ env.BRANCH_MEASUREMENT }} !== ${{ env.MAIN_MEASUREMENT }}) {
const difference = ${{ env.BRANCH_MEASUREMENT }} - ${{ env.MAIN_MEASUREMENT }};
try {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `_Change in memory usage detected by benchmark._
## Memory Report for ${{ github.sha }}
| Test | This Branch | On Main | Difference |
|-----------------------------|-------------|----------| ---------- |
| compile core + standard lib | ${{ env.BRANCH_MEASUREMENT }} bytes | ${{ env.MAIN_MEASUREMENT }} bytes | ${difference} bytes`
})
} catch (err) {
core.warning(`Failed writing comment on GitHub issue: ${err}`)
}
} else {
console.log("no change in memory usage detected by benchmark");
}
if: ${{ github.base_ref != null }}

status-check:
name: Status Check
needs: [format, clippy, web-check, build, unit-tests, format-qsc, integration-tests, runBenchmark, runMemoryProfile]
needs: [format, clippy, web-check, build, unit-tests, format-qsc, integration-tests]
runs-on: ubuntu-latest
if: failure()
steps:
Expand Down

0 comments on commit c023200

Please sign in to comment.