site: /match/, a weighted matcher that ranks entries by what the reader needs #3452
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | |
| # Which command? Longest name first — they all share the /benchmark prefix. | |
| if echo "$COMMENT_BODY" | grep -q '/benchmark-multiple'; then | |
| COMMAND="multiple" | |
| elif echo "$COMMENT_BODY" | grep -q '/benchmark-test'; then | |
| COMMAND="test" | |
| else | |
| COMMAND="single" | |
| fi | |
| # Frameworks this PR touches — the auto-detect fallback when -f is omitted. | |
| CHANGED=$(gh api "/repos/$REPO/pulls/$PR/files" --paginate --jq '.[].filename' | grep '^frameworks/' | cut -d'/' -f2 | sort -u || true) | |
| # Shared flags: -t <test>, --save | |
| EXPLICIT_TEST=$(echo "$COMMENT_BODY" | grep -oP '/benchmark[a-z-]*\s+.*-t\s+\K\S+' || echo "") | |
| SAVE_FLAG="" | |
| if echo "$COMMENT_BODY" | grep -q '\-\-save'; then | |
| SAVE_FLAG="true" | |
| fi | |
| # These values come from a PR comment, which anyone can write, and are | |
| # interpolated into later steps. Restrict them to the characters a | |
| # framework directory or profile name can actually contain, so a | |
| # crafted comment cannot smuggle shell syntax through | |
| # (e.g. `--compare a";touch${IFS}/tmp/x;#`). Anything else becomes empty. | |
| safe() { printf '%s' "$1" | grep -oP '^[A-Za-z0-9._-]{1,64}$' || true; } | |
| EXPLICIT_TEST=$(safe "$EXPLICIT_TEST") | |
| COMPARE_FW="" | |
| case "$COMMAND" in | |
| single) | |
| # Parse flags: -f <framework> | |
| EXPLICIT_FW=$(echo "$COMMENT_BODY" | grep -oP '/benchmark\s+.*-f\s+\K\S+' || echo "") | |
| # Fallback: positional arg (legacy: /benchmark baseline) | |
| if [ -z "$EXPLICIT_FW" ] && [ -z "$EXPLICIT_TEST" ]; then | |
| EXPLICIT_TEST=$(safe "$(echo "$COMMENT_BODY" | grep -oP '/benchmark\s+\K[^-]\S*' || echo "")") | |
| fi | |
| # Parse --compare <framework>: baseline the deltas on another entry's | |
| # published results instead of this framework's own (#741). | |
| COMPARE_FW=$(safe "$(echo "$COMMENT_BODY" | grep -oP '/benchmark\s+.*--compare[= ]\K\S+' || echo "")") | |
| FRAMEWORK=$(safe "${EXPLICIT_FW:-$(echo "$CHANGED" | head -1)}") | |
| ;; | |
| multiple) | |
| # /benchmark-multiple -f a,b,c — or, with no -f, every framework the | |
| # PR touches. One run, one results commit at the end (#1084). | |
| RAW=$(echo "$COMMENT_BODY" | grep -oP '/benchmark-multiple\s+.*-f\s+\K\S+' || echo "") | |
| [ -n "$RAW" ] || RAW=$(echo "$CHANGED" | paste -sd, -) | |
| FRAMEWORK="" | |
| for fw in $(echo "$RAW" | tr ',' ' '); do | |
| fw=$(safe "$fw") | |
| [ -z "$fw" ] && continue | |
| case ",$FRAMEWORK," in | |
| *",$fw,"*) ;; | |
| *) FRAMEWORK="${FRAMEWORK:+$FRAMEWORK,}$fw" ;; | |
| esac | |
| done | |
| ;; | |
| test) | |
| # /benchmark-test -t <test> — every enabled framework subscribed to | |
| # the test; always saves. The list is resolved in benchmark-pr.yml | |
| # from the meta.json files on the PR head. | |
| if [ -z "$EXPLICIT_TEST" ]; then | |
| gh pr comment "$PR" --repo "$REPO" \ | |
| --body "⚠️ \`/benchmark-test\` needs a test: \`/benchmark-test -t <test>\`. It benchmarks every enabled framework subscribed to that test and saves the results." | |
| exit 1 | |
| fi | |
| FRAMEWORK="all" | |
| SAVE_FLAG="true" | |
| ;; | |
| esac | |
| echo "framework=$FRAMEWORK" >> "$GITHUB_OUTPUT" | |
| echo "profile=$EXPLICIT_TEST" >> "$GITHUB_OUTPUT" | |
| echo "save=$SAVE_FLAG" >> "$GITHUB_OUTPUT" | |
| echo "compare=$COMPARE_FW" >> "$GITHUB_OUTPUT" | |
| echo "Command: $COMMAND" | |
| echo "Framework(s): $FRAMEWORK" | |
| echo "Profile: $EXPLICIT_TEST, Save: $SAVE_FLAG, Compare: ${COMPARE_FW:-<own published results>}" | |
| 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 != '' | |
| # Values reach the shell as environment variables rather than being | |
| # pasted into the script text, so nothing in them can be parsed as code. | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| PR_NUMBER: ${{ steps.parse.outputs.pr }} | |
| FRAMEWORK: ${{ steps.parse.outputs.framework }} | |
| PROFILE: ${{ steps.parse.outputs.profile }} | |
| SAVE: ${{ steps.parse.outputs.save }} | |
| COMPARE: ${{ steps.parse.outputs.compare }} | |
| run: | | |
| gh workflow run benchmark-pr.yml \ | |
| -f pr="$PR_NUMBER" \ | |
| -f framework="$FRAMEWORK" \ | |
| -f profile="$PROFILE" \ | |
| -f save="$SAVE" \ | |
| -f compare="$COMPARE" | |
| - 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>\` (or \`/benchmark-multiple -f <fw1>,<fw2>\` for several)." | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |