|
25 | 25 | type: number |
26 | 26 | default: 30 |
27 | 27 | description: How many times to repeat each benchmark |
| 28 | + post-comment: |
| 29 | + type: boolean |
| 30 | + description: Post a comment linking to the run, with the aggregated result once known. |
| 31 | + token: |
| 32 | + type: string |
| 33 | + description: A GitHub token to post comments cross repository (not recommended) |
28 | 34 |
|
29 | 35 | permissions: |
30 | 36 | contents: read |
31 | 37 |
|
32 | 38 | jobs: |
| 39 | + post-comment: |
| 40 | + if: inputs.post-comment |
| 41 | + outputs: |
| 42 | + body: ${{ steps.comment.outputs.COMMENT_BODY }} |
| 43 | + url: ${{ steps.comment.outputs.COMMENT_URL }} |
| 44 | + runs-on: ubuntu-slim |
| 45 | + permissions: |
| 46 | + pull-requests: write |
| 47 | + steps: |
| 48 | + - name: Mark token input as sensitive |
| 49 | + if: inputs.token != '' |
| 50 | + run: echo "::add-mask::${{ inputs.token }}" |
| 51 | + - name: Add link to the current run |
| 52 | + id: comment |
| 53 | + run: | |
| 54 | + FILTER_IF_SET= |
| 55 | + [ -z "$FILTER" ] || FILTER_IF_SET=" / $FILTER" |
| 56 | + COMMENT_BODY="Benchmark GHA (${CATEGORIES}${FILTER_IF_SET}): ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" |
| 57 | + echo "COMMENT_BODY=$COMMENT_BODY" >> "$GITHUB_OUTPUT" |
| 58 | + echo "COMMENT_URL=$(gh pr comment -R "${REPO:-$GITHUB_REPOSITORY}" "$PR_ID" --body "$COMMENT_BODY")" >> "$GITHUB_OUTPUT" |
| 59 | + env: |
| 60 | + CATEGORIES: ${{ inputs.category }} |
| 61 | + FILTER: ${{ inputs.filter }} |
| 62 | + GH_TOKEN: ${{ inputs.token || github.token }} |
| 63 | + REPO: ${{ inputs.repo }} |
| 64 | + PR_ID: ${{ inputs.pr_id }} |
33 | 65 | build: |
34 | 66 | strategy: |
35 | 67 | fail-fast: true |
@@ -155,9 +187,13 @@ jobs: |
155 | 187 | path: ${{ matrix.system }}.csv |
156 | 188 |
|
157 | 189 | aggregate-results: |
158 | | - needs: build |
| 190 | + needs: [build, post-comment] |
| 191 | + if: ${{ always() && needs.build.result == 'success' && needs.post-comment.result == (inputs.post-comment && 'success' || 'skipped') }} |
159 | 192 | name: Aggregate benchmark results |
160 | 193 | runs-on: ubuntu-slim |
| 194 | + permissions: |
| 195 | + contents: read |
| 196 | + pull-requests: write |
161 | 197 | steps: |
162 | 198 | - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
163 | 199 | with: |
@@ -200,4 +236,30 @@ jobs: |
200 | 236 | echo "> [!WARNING] " |
201 | 237 | echo "> Do not take GHA benchmark results as face value, always confirm them" |
202 | 238 | echo "> using a dedicated machine, e.g. Jenkins CI." |
203 | | - ' | tee /dev/stderr >> "$GITHUB_STEP_SUMMARY" |
| 239 | + ' | tee /dev/stderr ${{ inputs.post-comment && 'body.txt' || '' }} >> "$GITHUB_STEP_SUMMARY" |
| 240 | + - name: Mark token input as sensitive |
| 241 | + if: inputs.token != '' |
| 242 | + run: echo "::add-mask::${{ inputs.token }}" |
| 243 | + - name: Edit comment |
| 244 | + if: inputs.post-comment |
| 245 | + run: | |
| 246 | + { |
| 247 | + echo "$COMMENT_BODY" |
| 248 | + echo |
| 249 | + echo '<details><summary>Results</summary>' |
| 250 | + echo |
| 251 | + cat body.txt |
| 252 | + echo |
| 253 | + echo '</details>' |
| 254 | + } | jq -Rrcs '{ body: . }' | gh api \ |
| 255 | + --method PATCH \ |
| 256 | + -H "Accept: application/vnd.github+json" \ |
| 257 | + -H "X-GitHub-Api-Version: 2026-03-10" \ |
| 258 | + "/repos/${REPO:-$GITHUB_REPOSITORY}/issues/comments/${COMMENT_URL##*-}" \ |
| 259 | + --input - |
| 260 | + env: |
| 261 | + GH_TOKEN: ${{ inputs.token || github.token }} |
| 262 | + REPO: ${{ inputs.repo }} |
| 263 | + COMMENT_BODY: ${{ needs.post-comment.outputs.body }} |
| 264 | + COMMENT_URL: ${{ needs.post-comment.outputs.url }} |
| 265 | + PR_ID: ${{ inputs.pr_id }} |
0 commit comments