|
9 | 9 | pr: |
10 | 10 | description: "Pull request#" |
11 | 11 | required: false |
| 12 | + issue_comment: |
| 13 | + types: [created] |
12 | 14 |
|
13 | 15 | env: |
14 | 16 | CHC_BRANCH: "main" |
15 | 17 | CH_VERSION: "25.3" |
16 | 18 | JAVA_VERSION: 17 |
17 | 19 |
|
| 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. |
18 | 23 | 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 }} |
20 | 25 | cancel-in-progress: true |
21 | 26 |
|
22 | 27 | 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 | + |
23 | 81 | 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') |
25 | 87 | name: "Mininal JMH Benchmarks" |
26 | 88 | runs-on: "ubuntu-latest" |
27 | 89 | timeout-minutes: 30 |
28 | 90 | 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 |
29 | 107 | - name: Check out Git repository |
30 | 108 | uses: actions/checkout@v4 |
31 | 109 | with: |
32 | 110 | ref: ${{ env.CHC_BRANCH }} |
33 | 111 | - name: Check out PR |
| 112 | + if: steps.pr.outputs.number != '' |
34 | 113 | run: | |
35 | 114 | 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 |
38 | 116 | - name: Install JDK and Maven |
39 | 117 | uses: actions/setup-java@v4 |
40 | 118 | with: |
|
0 commit comments