Skip to content

Commit 9c87033

Browse files
authored
Merge branch 'master' into master
2 parents 0b26f99 + 09e76cb commit 9c87033

File tree

2 files changed

+103
-12
lines changed

2 files changed

+103
-12
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Credit to @aviastek, where this code comes from in JET.jl
2+
3+
# To workaroud https://github.com/actions/first-interaction/issues/10 in a secure way,
4+
# we take the following steps to generate and comment a performance benchmark result:
5+
# 1. first "performance tracking" workflow will generate the benchmark results in an unprivileged environment triggered on `pull_request` event
6+
# 2. then this "performance tracking (comment)" workflow will show the result to us as a PR comment in a privileged environment
7+
# Note that this workflow can only be modifed by getting checked-in to the default branch
8+
# and thus is secure even though this workflow is granted with write permissions, etc.
9+
# xref: https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
10+
11+
name: Post Benchmark Comments
12+
13+
on:
14+
workflow_run:
15+
workflows:
16+
- performance tracking
17+
types:
18+
- completed
19+
20+
jobs:
21+
comment:
22+
runs-on: ubuntu-latest
23+
if: >
24+
${{ github.event.workflow_run.event == 'pull_request' &&
25+
github.event.workflow_run.conclusion == 'success' }}
26+
steps:
27+
- uses: actions/checkout@v2
28+
# restore records from the artifacts
29+
- uses: dawidd6/action-download-artifact@v2
30+
with:
31+
workflow: benchmark.yml
32+
name: Benchmarking
33+
workflow_conclusion: success
34+
- name: output benchmark result
35+
id: output-result-markdown
36+
run: |
37+
echo ::set-output name=body::$(cat ./benchmark-result.artifact)
38+
- name: output pull request number
39+
id: output-pull-request-number
40+
run: |
41+
echo ::set-output name=body::$(cat ./pull-request-number.artifact)
42+
# check if the previous comment exists
43+
- name: find comment
44+
uses: peter-evans/find-comment@v1
45+
id: fc
46+
with:
47+
issue-number: ${{ steps.output-pull-request-number.outputs.body }}
48+
comment-author: 'github-actions[bot]'
49+
body-includes: Kernel Benchmark Result
50+
# create/update comment
51+
- name: create comment
52+
if: ${{ steps.fc.outputs.comment-id == 0 }}
53+
uses: peter-evans/create-or-update-comment@v1
54+
with:
55+
issue-number: ${{ steps.output-pull-request-number.outputs.body }}
56+
body: ${{ steps.output-result-markdown.outputs.body }}
57+
- name: update comment
58+
if: ${{ steps.fc.outputs.comment-id != 0 }}
59+
uses: peter-evans/create-or-update-comment@v1
60+
with:
61+
comment-id: ${{ steps.fc.outputs.comment-id }}
62+
body: ${{ steps.output-result-markdown.outputs.body }}

.github/workflows/benchmark.yml

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,52 @@ name: Run benchmarks
22

33
on:
44
pull_request:
5+
types: [opened, synchronize, reopened, labeled]
6+
7+
concurrency:
8+
# Skip intermediate builds: always.
9+
# Cancel intermediate builds: only if it is a pull request build.
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
512

613
jobs:
7-
Benchmark:
14+
Benchmarking:
815
runs-on: ubuntu-latest
916
if: contains(github.event.pull_request.labels.*.name, 'performance critical')
10-
env:
11-
JULIA_DEBUG: BenchmarkCI
1217
steps:
18+
# setup
1319
- uses: actions/checkout@v2
1420
- uses: julia-actions/setup-julia@latest
1521
with:
16-
version: 1.6
17-
- name: Install dependencies
18-
run: julia -e 'using Pkg; pkg"add PkgBenchmark BenchmarkCI"'
19-
- name: Run benchmarks
20-
run: julia -e "using BenchmarkCI; BenchmarkCI.judge()"
21-
- name: Post results
22-
run: julia -e "using BenchmarkCI; BenchmarkCI.postjudge()"
23-
env:
24-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
version: '1.7'
23+
- uses: julia-actions/julia-buildpkg@latest
24+
- name: install dependencies
25+
run: julia -e 'using Pkg; pkg"add PkgBenchmark [email protected]"'
26+
# run the benchmark suite
27+
- name: run benchmarks
28+
run: |
29+
using BenchmarkCI
30+
BenchmarkCI.judge()
31+
BenchmarkCI.displayjudgement()
32+
shell: julia --color=yes {0}
33+
# generate and record the benchmark result as markdown
34+
- name: generate benchmark result
35+
run: |
36+
using BenchmarkCI
37+
judgement = BenchmarkCI._loadjudge(BenchmarkCI.DEFAULT_WORKSPACE)
38+
title = "Kernel Benchmark Result"
39+
ciresult = BenchmarkCI.CIResult(; judgement, title)
40+
comment = sprint() do io
41+
return BenchmarkCI.printcommentmd(io, ciresult)
42+
end
43+
comment = replace(comment, "%" => "%25", "\\n" => "%0A", "\\r" => "%0D")
44+
write("benchmark-result.artifact", comment)
45+
shell: julia --color=yes {0}
46+
# record the pull request number
47+
- name: record pull request number
48+
run: echo ${{ github.event.pull_request.number }} > ./pull-request-number.artifact
49+
# save as artifacts (performance tracking (comment) workflow will use it)
50+
- uses: actions/upload-artifact@v2
51+
with:
52+
name: Benchmarking
53+
path: ./*.artifact

0 commit comments

Comments
 (0)