-
Notifications
You must be signed in to change notification settings - Fork 32
131 lines (116 loc) · 5.76 KB
/
pr-commands.yml
File metadata and controls
131 lines (116 loc) · 5.76 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: PR Commands
on:
issue_comment:
types: [created]
permissions:
contents: read
pull-requests: write
actions: write
jobs:
runner-busy:
if: github.event.issue.pull_request && contains(github.event.comment.body, '/benchmark') && vars.RUNNER_LOCAL == 'true'
runs-on: ubuntu-latest
steps:
- name: Post runner-busy notice
run: |
gh api "/repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions" -f content="eyes"
gh pr comment "${{ github.event.issue.number }}" \
--repo "${{ github.repository }}" \
--body "⏸️ Runner is currently performing local benchmark runs and is disabled for GitHub Actions, please try later or check our Discord announcements on runner state for more info."
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ── /benchmark — requires collaborator approval ──
acknowledge-benchmark:
if: github.event.issue.pull_request && contains(github.event.comment.body, '/benchmark') && vars.RUNNER_LOCAL != 'true'
runs-on: ubuntu-latest
steps:
- name: Acknowledge command
run: |
gh api "/repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions" -f content="eyes"
gh pr comment "${{ github.event.issue.number }}" \
--repo "${{ github.repository }}" \
--body "👋 \`/benchmark\` request received. A collaborator will review and approve the run."
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
handle-benchmark:
needs: acknowledge-benchmark
if: github.event.issue.pull_request && contains(github.event.comment.body, '/benchmark') && vars.RUNNER_LOCAL != 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
ref: refs/pull/${{ github.event.issue.number }}/head
fetch-depth: 0
- name: Parse command
id: parse
run: |
PR="$PR_NUMBER"
echo "pr=$PR" >> "$GITHUB_OUTPUT"
AUTO_FRAMEWORK=$(gh api "/repos/$REPO/pulls/$PR/files" --paginate --jq '.[].filename' | grep '^frameworks/' | cut -d'/' -f2 | sort -u | head -1)
# Parse flags: -f <framework> -t <test>
EXPLICIT_FW=$(echo "$COMMENT_BODY" | grep -oP '/benchmark\s+.*-f\s+\K\S+' || echo "")
EXPLICIT_TEST=$(echo "$COMMENT_BODY" | grep -oP '/benchmark\s+.*-t\s+\K\S+' || echo "")
# Fallback: positional arg (legacy: /benchmark baseline)
if [ -z "$EXPLICIT_FW" ] && [ -z "$EXPLICIT_TEST" ]; then
EXPLICIT_TEST=$(echo "$COMMENT_BODY" | grep -oP '/benchmark\s+\K[^-]\S*' || echo "")
fi
# Parse --save flag
SAVE_FLAG=""
if echo "$COMMENT_BODY" | grep -q '\-\-save'; then
SAVE_FLAG="true"
fi
FRAMEWORK="${EXPLICIT_FW:-$AUTO_FRAMEWORK}"
echo "framework=$FRAMEWORK" >> "$GITHUB_OUTPUT"
echo "profile=$EXPLICIT_TEST" >> "$GITHUB_OUTPUT"
echo "save=$SAVE_FLAG" >> "$GITHUB_OUTPUT"
echo "Detected framework: $FRAMEWORK (auto: $AUTO_FRAMEWORK, explicit: $EXPLICIT_FW)"
echo "Profile: $EXPLICIT_TEST, Save: $SAVE_FLAG"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMENT_BODY: ${{ github.event.comment.body }}
PR_NUMBER: ${{ github.event.issue.number }}
REPO: ${{ github.repository }}
# Pre-check that origin/main can auto-merge into the PR. The actual
# merge happens inside benchmark-pr.yml after maintainer approval;
# doing the dry-run here lets us reject conflicting PRs before
# asking a maintainer to approve a run that's guaranteed to abort.
# Skipped for non-save runs since they don't push back.
- name: Check main merges into PR
if: steps.parse.outputs.save == 'true' && steps.parse.outputs.framework != ''
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git fetch origin main --depth=1
if ! git merge --no-commit --no-ff origin/main; then
git merge --abort 2>/dev/null || true
gh pr comment "${{ steps.parse.outputs.pr }}" \
--repo "${{ github.repository }}" \
--body "⚠️ \`/benchmark --save\` cannot start: \`main\` has diverged and cannot be auto-merged into this branch. Please merge or rebase \`main\` manually, push, and re-run \`/benchmark --save\`."
exit 1
fi
# Discard the merged state — actual merge runs in benchmark-pr.yml
# after maintainer approval. main may move between now and then.
git merge --abort 2>/dev/null || true
- name: React to comment
run: |
gh api "/repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions" -f content="rocket"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run benchmark
if: steps.parse.outputs.framework != ''
run: |
gh workflow run benchmark-pr.yml \
-f pr=${{ steps.parse.outputs.pr }} \
-f framework=${{ steps.parse.outputs.framework }} \
-f profile="${{ steps.parse.outputs.profile }}" \
-f save="${{ steps.parse.outputs.save }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: No framework detected
if: steps.parse.outputs.framework == ''
run: |
gh pr comment "${{ steps.parse.outputs.pr }}" --body "⚠️ Couldn't detect which framework to test. Either modify files under \`frameworks/<name>/\` or specify explicitly: \`/benchmark -f <framework> -t <test>\`"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}