Skip to content

Commit 098bd35

Browse files
committed
Add Lean PR comment benchmark
1 parent ca38b97 commit 098bd35

File tree

16 files changed

+399
-3
lines changed

16 files changed

+399
-3
lines changed

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.github/workflows/bench.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Creates a PR benchmark comment with a comparison to main
2+
name: Benchmark pull requests
3+
4+
on:
5+
issue_comment:
6+
types: [created]
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
setup:
14+
name: Comparative PR benchmark comment
15+
if:
16+
github.event.issue.pull_request
17+
&& github.event.issue.state == 'open'
18+
&& (contains(github.event.comment.body, '!benchmark'))
19+
&& (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER')
20+
runs-on: ubuntu-latest
21+
outputs:
22+
benches: ${{ steps.bench-params.outputs.benches }}
23+
env-vars: ${{ steps.bench-params.outputs.env-vars }}
24+
steps:
25+
- uses: actions/checkout@v5
26+
- name: Parse PR comment body
27+
id: bench-params
28+
run: |
29+
# Parse `issue_comment` body
30+
printf '${{ github.event.comment.body }}' > comment.txt
31+
BENCH_COMMAND=$(head -n 1 comment.txt)
32+
echo "$BENCH_COMMAND"
33+
34+
BENCHES=$(echo $BENCH_COMMAND | awk -F'!benchmark ' '{ print $2 }')
35+
echo "BENCHES\n$BENCHES"
36+
JSON=$(echo $BENCHES | jq -R -c 'split(" ")')
37+
38+
#echo "benches<<EOF" >> $GITHUB_OUTPUT
39+
#echo "$JSON" | tee -a $GITHUB_OUTPUT
40+
#echo "EOF" >> $GITHUB_OUTPUT
41+
echo "JSON\n$JSON"
42+
43+
echo "benches=$JSON" | tee -a $GITHUB_OUTPUT
44+
45+
# Can't persist env vars between jobs, so we pass them as an output and set them in the next job
46+
echo "env-vars=$(tail -n +2 comment.txt)" | tee -a $GITHUB_OUTPUT
47+
48+
benchmark:
49+
needs: [ setup ]
50+
runs-on: warp-ubuntu-latest-x64-16x
51+
strategy:
52+
matrix:
53+
# Runs a job for each benchmark specified in the `issue_comment` input
54+
bench: ${{ fromJSON(needs.setup.outputs.benches) }}
55+
steps:
56+
- name: Set env vars
57+
run: |
58+
# Trims newlines that may arise from `$GITHUB_OUTPUT`
59+
for var in ${{ inputs.default-env }}
60+
do
61+
echo "$(echo $var | tr -d '\n')" | tee -a $GITHUB_ENV
62+
done
63+
# Overrides default env vars with those specified in the `issue_comment` input if identically named
64+
for var in ${{ needs.setup.outputs.env-vars }}
65+
do
66+
echo "$(echo $var | tr -d '\n')" | tee -a $GITHUB_ENV
67+
done
68+
- uses: actions/checkout@v5
69+
# Get base branch of the PR
70+
#- uses: xt0rted/pull-request-comment-branch@v2
71+
# id: comment-branch
72+
- name: Checkout PR branch
73+
run: gh pr checkout $PR_NUMBER
74+
env:
75+
GH_TOKEN: ${{ github.token }}
76+
PR_NUMBER: ${{ github.event.issue.number }}
77+
- uses: leanprover/lean-action@v1
78+
with:
79+
test: false
80+
- name: Run bench
81+
run: |
82+
lake exe ${{ matrix.bench }} | tee out.txt 2>&1
83+
- name: Comment on successful run
84+
if: success()
85+
uses: peter-evans/create-or-update-comment@v4
86+
with:
87+
issue-number: ${{ github.event.issue.number }}
88+
body: |
89+
`!${{ needs.setup.outputs.command }}` action succeeded! :rocket:
90+
91+
Bench output:
92+
$(cat out.txt)
93+
94+
https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
95+
96+
- name: Comment on failing run
97+
if: failure()
98+
uses: peter-evans/create-or-update-comment@v4
99+
with:
100+
issue-number: ${{ github.event.issue.number }}
101+
body: |
102+
`!${{ needs.setup.outputs.command }}` action failed :x:
103+
104+
https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Lean Action CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: leanprover/lean-action@v1

.gitignore

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
target/
2-
Cargo.lock
1+
# Lean
2+
/.lake
3+
4+
# Rust
5+
/target
6+
7+
# Nix
8+
result*
9+
.direnv/

Benchmarks/Main.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def main (_args: List String) : IO Unit := do
2+
IO.println "Hello bench"

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Main.lean

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Template
2+
import Ix.Benchmark.Bench
3+
4+
def add (input: Nat): IO Nat := do
5+
pure $ input + 1
6+
7+
def addBench := bgroup "Add" [
8+
benchIO "add 1" add 1
9+
] { report := true }
10+
11+
def main : IO Unit := do
12+
--IO.println "hello"
13+
let _result ← addBench

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# template

Template.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- This module serves as the root of the `Template` library.
2+
-- Import modules here that should be built as part of the library.
3+
import Template.Basic

Template/Basic.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def hello := "world"

0 commit comments

Comments
 (0)