|
| 1 | +name: Perf |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + merge_group: # (a merge queue's) |
| 6 | + push: |
| 7 | + branches: [master] # (and any other branch to guard, a stable one, say) |
| 8 | + schedule: |
| 9 | + - cron: "0 4 * * *" |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +# A pull request's newer push cancels its run, if that's still going, as |
| 13 | +# only its newest commit's result counts. Every other run (a push's, say) |
| 14 | +# runs to the end, so that each push is compared. |
| 15 | +concurrency: |
| 16 | + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.run_id }} |
| 17 | + cancel-in-progress: ${{ github.event_name == 'pull_request' }} |
| 18 | + |
| 19 | +# The Duel job runs the branch's code (its benchmarks too), so it only |
| 20 | +# reads. Commenting on a commit is the Comment on the commit job's, which |
| 21 | +# runs none of it, and commenting on a pull request is the Perf comment |
| 22 | +# workflow's. |
| 23 | +permissions: |
| 24 | + contents: read |
| 25 | + pull-requests: read # for the pull request's labels (see c.accept_label) |
| 26 | + |
| 27 | +jobs: |
| 28 | + duel: |
| 29 | + name: Duel |
| 30 | + runs-on: ubuntu-latest |
| 31 | + # Whether to comment (post, change or none), the run's status (passed, |
| 32 | + # failed or neutral), and whether to mark a push passed (true, or |
| 33 | + # nothing), from Duel. |
| 34 | + outputs: |
| 35 | + comment: ${{ steps.compare.outputs.comment }} |
| 36 | + status: ${{ steps.compare.outputs.status }} |
| 37 | + passed: ${{ steps.compare.outputs.passed }} |
| 38 | + steps: |
| 39 | + - uses: actions/checkout@v7 |
| 40 | + with: |
| 41 | + fetch-depth: 0 # the baseline comes from history, tags included |
| 42 | + persist-credentials: false |
| 43 | + # The labels of the pull request (or for a push, of the one that |
| 44 | + # merged it), for c.accept_label in .duel.rb, as a JSON array. They're |
| 45 | + # read as the job runs, and adding the label (or taking it off) runs |
| 46 | + # the job again: see the Perf comment workflow. |
| 47 | + - name: Find the pull request's labels |
| 48 | + id: labels |
| 49 | + if: github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'push' |
| 50 | + continue-on-error: true # (without them, nothing's accepted) |
| 51 | + env: |
| 52 | + GH_TOKEN: ${{ github.token }} |
| 53 | + PR: ${{ github.event.pull_request.number }} |
| 54 | + QUEUED: ${{ github.event.merge_group.head_ref }} |
| 55 | + run: | |
| 56 | + # (In a merge queue, the last pull request queued, which the queue's |
| 57 | + # branch names: gh-readonly-queue/master/pr-123-<sha>.) |
| 58 | + if [ -n "$QUEUED" ]; then |
| 59 | + PR=${QUEUED##*/pr-} |
| 60 | + PR=${PR%%-*} |
| 61 | + fi |
| 62 | + if [ -n "$PR" ]; then |
| 63 | + labels=$(gh api "repos/$GITHUB_REPOSITORY/issues/$PR/labels" --jq '[.[].name]') |
| 64 | + else |
| 65 | + labels=$(gh api "repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/pulls" --jq '[.[0].labels[]?.name]') |
| 66 | + fi |
| 67 | + echo "labels=$labels" >> "$GITHUB_OUTPUT" |
| 68 | + - uses: ruby/setup-ruby@v1 |
| 69 | + with: |
| 70 | + ruby-version: "4.0" # the newest Ruby, which those who care most about speed run |
| 71 | + bundler-cache: true |
| 72 | + # Against the branch it targets for a pull request, the queue's base |
| 73 | + # for a merge queue, what was there before for a push (or as |
| 74 | + # c.push_base in .duel.rb says, the last commit Duel passed), and the |
| 75 | + # last release on a schedule (slow creep). Duel adds its report to |
| 76 | + # the job's summary, writes it to duel.md for the comment, and sets |
| 77 | + # the step's outputs to say whether to comment, as c.comment in |
| 78 | + # .duel.rb says, whatever the outcome. |
| 79 | + - name: Compare |
| 80 | + id: compare |
| 81 | + env: |
| 82 | + DUEL_BASE: ${{ github.event_name == 'schedule' && 'last-release' || github.event_name == 'push' && github.event.before || github.event_name == 'merge_group' && github.event.merge_group.base_sha || '' }} |
| 83 | + # (Run by hand, it compares anyway: with nothing changed, the code |
| 84 | + # with itself, which checks the setup.) |
| 85 | + DUEL_FORCE: ${{ github.event_name == 'workflow_dispatch' && '1' || '' }} |
| 86 | + DUEL_LABELS: ${{ steps.labels.outputs.labels }} |
| 87 | + run: bundle exec duel --markdown "$RUNNER_TEMP/duel/duel.md" |
| 88 | + # For a pull request, what Duel said, for the Perf comment workflow, |
| 89 | + # which can't see this job's outputs. |
| 90 | + - name: Say whether to comment |
| 91 | + if: ${{ !cancelled() && github.event_name == 'pull_request' }} |
| 92 | + env: |
| 93 | + PR: ${{ github.event.pull_request.number }} |
| 94 | + COMMENT: ${{ steps.compare.outputs.comment }} |
| 95 | + STATUS: ${{ steps.compare.outputs.status }} |
| 96 | + run: | |
| 97 | + mkdir -p "$RUNNER_TEMP/duel" |
| 98 | + printf 'pr=%s\ncomment=%s\nstatus=%s\n' "$PR" "$COMMENT" "$STATUS" > "$RUNNER_TEMP/duel/comment.env" |
| 99 | + # The report, for the comments. |
| 100 | + - name: Keep the report |
| 101 | + if: ${{ !cancelled() && (github.event_name == 'pull_request' || github.event_name == 'push') }} |
| 102 | + uses: actions/upload-artifact@v7 |
| 103 | + with: |
| 104 | + name: duel-report |
| 105 | + path: ${{ runner.temp }}/duel/ |
| 106 | + if-no-files-found: ignore # none when Duel didn't get to compare |
| 107 | + retention-days: 1 |
0 commit comments