Skip to content

Commit 558c144

Browse files
authored
Merge pull request #340 from b-ma/chore/review-bench-workflow
Update bench bot behavior
2 parents b974404 + 0b546dc commit 558c144

File tree

3 files changed

+80
-58
lines changed

3 files changed

+80
-58
lines changed

.github/workflows/post-pr-result.yaml renamed to .github/workflows/benchmark-post-result.yaml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow
22

3-
name: Post benchmark results
3+
name: benchmark post results
44

55
# read-write repo token
66
# access to secrets
@@ -9,42 +9,37 @@ name: Post benchmark results
99
# see https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
1010
on:
1111
workflow_run:
12-
branches-ignore:
13-
- "main"
14-
workflows: ["Build"]
12+
workflows: ["benchmark"]
1513
types:
1614
- completed
1715

1816
jobs:
1917
upload:
2018
runs-on: ubuntu-latest
21-
if: >
22-
${{ github.event.workflow_run.event == 'pull_request' &&
23-
github.event.workflow_run.conclusion == 'success' }}
2419
steps:
2520
- name: "Download artifact"
26-
uses: actions/github-script@v3.1.0
21+
uses: actions/github-script@v6
2722
with:
2823
script: |
29-
const artifacts = await github.actions.listWorkflowRunArtifacts({
24+
const fs = require('fs');
25+
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
3026
owner: context.repo.owner,
3127
repo: context.repo.repo,
3228
run_id: ${{github.event.workflow_run.id }},
3329
});
34-
const matchArtifact = artifacts.data.artifacts.filter((artifact) => {
30+
const matchArtifact = artifacts.data.artifacts.find((artifact) => {
3531
return artifact.name == "pr"
36-
})[0];
37-
const download = await github.actions.downloadArtifact({
32+
});
33+
const download = await github.rest.actions.downloadArtifact({
3834
owner: context.repo.owner,
3935
repo: context.repo.repo,
4036
artifact_id: matchArtifact.id,
4137
archive_format: 'zip',
4238
});
43-
const fs = require('fs');
4439
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
4540
- run: unzip pr.zip
4641
- name: "Write result in PR"
47-
uses: actions/github-script@v3
42+
uses: actions/github-script@v6
4843
with:
4944
github-token: ${{ secrets.GITHUB_TOKEN }}
5045
script: |
@@ -54,7 +49,7 @@ jobs:
5449
5550
const message = '```\nBenchmark result:\n\n' + iai_feature + '\n```\n';
5651
57-
await github.issues.createComment({
52+
await github.rest.issues.createComment({
5853
owner: context.repo.owner,
5954
repo: context.repo.repo,
6055
issue_number: issue_number,

.github/workflows/rust.yaml renamed to .github/workflows/benchmark.yaml

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,37 @@
11
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow
22

3-
name: Build
3+
name: benchmark
44

55
# read-only repo token, no access to secrets
66
permissions:
77
contents: read
88

99
# no access to secrets
1010
on:
11-
push:
12-
branches: [main]
13-
pull_request:
11+
issue_comment:
12+
types: [created, edited]
1413

1514
env:
1615
CARGO_TERM_COLOR: always
1716

1817
jobs:
19-
verify-build:
18+
benchmark:
2019
runs-on: ubuntu-latest
20+
if: ${{ github.event.issue.pull_request }} && contains(github.event.comment.body, '/bench')
2121

2222
steps:
23-
- name: Install ALSA and Jack dependencies
24-
run: |
25-
sudo apt-get update && sudo apt-get install -y libasound2-dev libjack-jackd2-dev cmake
26-
27-
- name: Install Rust toolchain
28-
uses: dtolnay/rust-toolchain@stable
29-
with:
30-
components: clippy, rustfmt
31-
32-
- name: Check out repository
23+
# the workflow is triggered from main branch
24+
# cf. https://github.com/actions/checkout/issues/331
25+
# need this first step to init the git repo
26+
- name: Checkout
3327
uses: actions/checkout@v3
3428

35-
- name: Generate Cargo.lock
36-
run: cargo generate-lockfile
37-
38-
# restore cargo cache from previous runs
39-
- name: Rust Cache
40-
uses: Swatinem/rust-cache@v2
41-
with:
42-
# Distinguished by the action name to avoid sharing!
43-
shared-key: "rust"
44-
45-
# check it builds
46-
- name: Build
47-
run: cargo build --verbose --all-targets --all-features
48-
49-
# run tests
50-
- name: Run tests
51-
run: cargo test --verbose --all-features
52-
53-
benchmark:
54-
runs-on: ubuntu-latest
55-
if: github.ref != 'refs/heads/main'
56-
57-
steps:
58-
# checkout repo, install dependencies
59-
- uses: actions/checkout@v3
60-
with:
61-
fetch-depth: 0
29+
- name: Checkout Pull Request
30+
run: hub pr checkout ${{ github.event.issue.number }}
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6233

34+
# install dependencies
6335
- name: Install Rust toolchain
6436
uses: dtolnay/rust-toolchain@stable
6537

@@ -83,12 +55,16 @@ jobs:
8355
- name: Run bench against baseline
8456
run: cargo bench --no-default-features | sed '0,/^test result:/d' | tee bench.txt
8557

58+
# for testing
59+
# - name: create mock results
60+
# run: echo "my bench results" > bench.txt
61+
8662
## Save results
8763
## see https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
8864
- name: Save PR number and bench results
8965
run: |
9066
mkdir -p ./pr
91-
echo ${{ github.event.number }} > ./pr/pr_number.txt
67+
echo ${{ github.event.issue.number }} > ./pr/pr_number.txt
9268
mv bench.txt ./pr/bench.txt
9369
- uses: actions/upload-artifact@v2
9470
with:

.github/workflows/build.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow
2+
3+
name: build
4+
5+
# read-only repo token, no access to secrets
6+
permissions:
7+
contents: read
8+
9+
# no access to secrets
10+
on:
11+
push:
12+
branches: [main]
13+
pull_request:
14+
15+
env:
16+
CARGO_TERM_COLOR: always
17+
18+
jobs:
19+
verify-build:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Install ALSA and Jack dependencies
24+
run: |
25+
sudo apt-get update && sudo apt-get install -y libasound2-dev libjack-jackd2-dev cmake
26+
27+
- name: Install Rust toolchain
28+
uses: dtolnay/rust-toolchain@stable
29+
with:
30+
components: clippy, rustfmt
31+
32+
- name: Check out repository
33+
uses: actions/checkout@v3
34+
35+
- name: Generate Cargo.lock
36+
run: cargo generate-lockfile
37+
38+
# restore cargo cache from previous runs
39+
- name: Rust Cache
40+
uses: Swatinem/rust-cache@v2
41+
with:
42+
# Distinguished by the action name to avoid sharing!
43+
shared-key: "rust"
44+
45+
# check it builds
46+
- name: Build
47+
run: cargo build --verbose --all-targets --all-features
48+
49+
# run tests
50+
- name: Run tests
51+
run: cargo test --verbose --all-features

0 commit comments

Comments
 (0)