-
Notifications
You must be signed in to change notification settings - Fork 550
96 lines (84 loc) · 3.25 KB
/
benchmark-bot.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
89
90
91
92
93
94
95
96
# from https://github.com/pandas-dev/pandas/blob/d42a148cd83e06b5e5ef1fb6424e337d5b5efaa5/.github/workflows/asv-bot.yml
name: "Benchmark Bot"
on:
issue_comment: # Pull requests are also issues
types:
- created
env:
COMMENT: ${{github.event.comment.body}}
jobs:
benchmarks:
name: "Run benchmarks"
if: startsWith(github.event.comment.body, '@benchmark')
runs-on: ubuntu-latest
defaults:
run:
shell: bash -el {0}
concurrency:
# Set concurrency to prevent abuse(full runs are ~5.5 hours !!!)
# each user can only run one concurrent benchmark bot at a time
# We don't cancel in progress jobs, but if you want to benchmark multiple PRs,
# you're gonna have to wait
group: ${{ github.actor }}-benchmarks
cancel-in-progress: false
steps:
- name: Install hub
run: sudo apt-get install -y hub
- name: Setup git
uses: actions/checkout@v3
# Since this was triggered by a comment, not a PR,
# the `actions/checkout` action will pull
# the default branch (AKA main). We need to checkout the PR branch.
# From https://github.com/actions/checkout/issues/331#issuecomment-925405415
- name: Checkout Pull Request
run: |
hub pr checkout ${{ github.event.issue.number }}
echo "Checked out SHA:"
git log -1 --format='%H'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
pip install --upgrade pip
pip install -r requirements.txt
pip install .
- name: Run benchmarks
id: bench
continue-on-error: true # This is a fake failure, asv will exit code 1 for regressions
run: |
# extracting the regex, see https://stackoverflow.com/a/36798723
REGEX=$(echo "$COMMENT" | sed -n "s/^@benchmark\s\+-b\s*\(\S*\).*$/\1/p")
if [ -z "$REGEX" ]; then
BENCHMARKS=""
else
BENCHMARKS="-b $REGEX"
fi
cd benchmarks
asv check -E existing
git remote add upstream https://github.com/dedupeio/dedupe.git
git fetch upstream
asv machine --yes
asv continuous --show-stderr -f 1.1 $BENCHMARKS upstream/main HEAD | cat
echo 'BENCH_OUTPUT<<EOF' >> $GITHUB_ENV
asv compare -f 1.1 upstream/main HEAD | python ../.github/scripts/asv_markdown.py >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
echo "REGEX=$REGEX" >> $GITHUB_ENV
- name: Add comment with results
uses: actions/github-script@v6
env:
BENCH_OUTPUT: ${{env.BENCH_OUTPUT}}
REGEX: ${{env.REGEX}}
with:
script: |
const ENV_VARS = process.env
const run_url = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: ENV_VARS["BENCH_OUTPUT"] + '\n\n[(logs)](' + run_url + ')'
})