Skip to content

Commit 0e9b69f

Browse files
authored
Merge pull request #2848 from ClickHouse/05/11/26/benchmark_for_pr
Added workflow to trigger benchmark from PR
2 parents 8377a8d + f27d02c commit 0e9b69f

1 file changed

Lines changed: 82 additions & 4 deletions

File tree

.github/workflows/benchmarks.yml

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,110 @@ on:
99
pr:
1010
description: "Pull request#"
1111
required: false
12+
issue_comment:
13+
types: [created]
1214

1315
env:
1416
CHC_BRANCH: "main"
1517
CH_VERSION: "25.3"
1618
JAVA_VERSION: 17
1719

20+
# One run per PR (cancel any in-progress run when a newer /benchmark arrives
21+
# for the same PR). Scheduled runs are grouped by SHA so they don't fight
22+
# with PR runs.
1823
concurrency:
19-
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.number || github.sha }}
24+
group: ${{ github.workflow }}-${{ github.event.issue.number || github.event.inputs.pr || github.sha }}
2025
cancel-in-progress: true
2126

2227
jobs:
28+
# Gate: only run for `issue_comment` events when the comment is on a PR,
29+
# starts with `/benchmark`, is not from a bot, and the commenter is a
30+
# repo OWNER/MEMBER/COLLABORATOR. For schedule and workflow_dispatch this
31+
# job is skipped and the benchmark job runs unconditionally.
32+
trigger-check:
33+
if: github.event_name == 'issue_comment'
34+
name: "Check /benchmark trigger"
35+
runs-on: ubuntu-latest
36+
permissions:
37+
pull-requests: write
38+
issues: write
39+
outputs:
40+
pr_number: ${{ steps.resolve.outputs.pr_number }}
41+
steps:
42+
- name: Validate comment
43+
id: validate
44+
if: |
45+
github.event.issue.pull_request != null &&
46+
github.event.sender.type != 'Bot' &&
47+
startsWith(github.event.comment.body, '/benchmark') &&
48+
contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association)
49+
run: echo "ok=true" >> $GITHUB_OUTPUT
50+
# Note: we deliberately use `startsWith` (not `contains`) so the
51+
# instruction comment posted by the PR-open bot, which mentions
52+
# `/benchmark` mid-sentence, does not re-trigger this workflow.
53+
54+
- name: Reject unauthorized trigger
55+
if: steps.validate.outputs.ok != 'true'
56+
env:
57+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
run: |
59+
# If it looks like a /benchmark attempt by someone without
60+
# permission, leave a -1 reaction so they get feedback.
61+
if [[ "${{ github.event.issue.pull_request != null }}" == "true" ]] \
62+
&& [[ "${{ startsWith(github.event.comment.body, '/benchmark') }}" == "true" ]]; then
63+
gh api -X POST \
64+
"repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions" \
65+
-f content='-1' || true
66+
fi
67+
exit 1
68+
69+
- name: Acknowledge trigger
70+
env:
71+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72+
run: |
73+
gh api -X POST \
74+
"repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions" \
75+
-f content='rocket' || true
76+
77+
- name: Resolve PR number
78+
id: resolve
79+
run: echo "pr_number=${{ github.event.issue.number }}" >> $GITHUB_OUTPUT
80+
2381
jmh:
24-
if: ${{ startsWith(github.repository, 'ClickHouse/') }}
82+
needs: [trigger-check]
83+
if: |
84+
always() &&
85+
startsWith(github.repository, 'ClickHouse/') &&
86+
(needs.trigger-check.result == 'success' || needs.trigger-check.result == 'skipped')
2587
name: "Mininal JMH Benchmarks"
2688
runs-on: "ubuntu-latest"
2789
timeout-minutes: 30
2890
steps:
91+
- name: Resolve PR number
92+
id: pr
93+
run: |
94+
case "${{ github.event_name }}" in
95+
issue_comment) echo "number=${{ needs.trigger-check.outputs.pr_number }}" >> $GITHUB_OUTPUT ;;
96+
workflow_dispatch) echo "number=${{ github.event.inputs.pr }}" >> $GITHUB_OUTPUT ;;
97+
*) echo "number=" >> $GITHUB_OUTPUT ;;
98+
esac
99+
- name: Post "started" comment
100+
if: github.event_name == 'issue_comment' && steps.pr.outputs.number != ''
101+
env:
102+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
103+
run: |
104+
gh api -X POST \
105+
"repos/${{ github.repository }}/issues/${{ steps.pr.outputs.number }}/comments" \
106+
-f body="JMH benchmark run started: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" || true
29107
- name: Check out Git repository
30108
uses: actions/checkout@v4
31109
with:
32110
ref: ${{ env.CHC_BRANCH }}
33111
- name: Check out PR
112+
if: steps.pr.outputs.number != ''
34113
run: |
35114
git fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 \
36-
origin pull/${{ github.event.inputs.pr }}/merge:merged-pr && git checkout merged-pr
37-
if: github.event.inputs.pr != ''
115+
origin pull/${{ steps.pr.outputs.number }}/merge:merged-pr && git checkout merged-pr
38116
- name: Install JDK and Maven
39117
uses: actions/setup-java@v4
40118
with:

0 commit comments

Comments
 (0)