-
-
Notifications
You must be signed in to change notification settings - Fork 25
88 lines (84 loc) · 3.13 KB
/
bench.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: Bench
on:
pull_request:
branches: [ main ]
push:
branches: [ main ]
env:
RUST_NIGHTLY_TOOLCHAIN: nightly-2024-12-18
RUSTFLAGS: -Clinker=/usr/bin/clang -Clink-arg=--ld-path=/usr/local/bin/mold -Ctarget-cpu=native -Zshare-generics=y -Zthreads=0
jobs:
export:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
strategy:
matrix:
benchmark: [ general ] # Add your benchmarks here
steps:
- uses: actions/checkout@v4
- uses: rui314/setup-mold@v1
- name: Install cargo-export
uses: taiki-e/install-action@v2
with:
tool: cargo-export
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_NIGHTLY_TOOLCHAIN }}
- uses: Swatinem/rust-cache@v2
- name: Run cargo export
run: cargo export target/benchmarks -- bench --bench=${{ matrix.benchmark }}
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: bench_${{ matrix.benchmark }}
path: target/benchmarks/${{ matrix.benchmark }}
compare:
if: github.event_name == 'pull_request' && github.base_ref == 'main'
runs-on: ubuntu-latest
strategy:
matrix:
benchmark: [ general ] # Add your benchmarks here
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Download Artifact
id: download
uses: dawidd6/action-download-artifact@v7
continue-on-error: true
with:
commit: ${{ github.event.pull_request.base.sha }}
name: bench_${{ matrix.benchmark }}
path: /tmp/bench/
- uses: rui314/setup-mold@v1
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_NIGHTLY_TOOLCHAIN }}
- uses: Swatinem/rust-cache@v2
- name: Run cargo bench
if: steps.download.outcome == 'success'
run: cargo bench --bench=${{ matrix.benchmark }} -- compare /tmp/bench/${{ matrix.benchmark }} > bench_output_${{ matrix.benchmark }}.txt
- name: remove /tmp/bench
if: steps.download.outcome == 'success'
run: rm -rf /tmp/bench
- name: Post benchmark results as PR comment
if: steps.download.outcome == 'success'
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const path = `bench_output_${{ matrix.benchmark }}.txt`;
const output = fs.readFileSync(path, 'utf8');
const originalSha = context.payload.pull_request.base.sha;
const issue_number = context.issue.number;
if(issue_number) {
const comment = {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: `### Benchmark Results for ${{ matrix.benchmark }}\n\`\`\`\n${output}\`\`\`\n\nComparing to ${originalSha}`,
};
await github.rest.issues.createComment(comment);
} else {
console.log('This action must be run in the context of a pull request');
}