|
| 1 | +name: PR Commands |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + pull-requests: write |
| 10 | + actions: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + handle-command: |
| 14 | + if: github.event.issue.pull_request && (contains(github.event.comment.body, '/validate') || contains(github.event.comment.body, '/benchmark')) |
| 15 | + runs-on: self-hosted |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + ref: refs/pull/${{ github.event.issue.number }}/head |
| 20 | + fetch-depth: 1 |
| 21 | + |
| 22 | + - name: Parse command |
| 23 | + id: parse |
| 24 | + run: | |
| 25 | + COMMENT="${{ github.event.comment.body }}" |
| 26 | + PR=${{ github.event.issue.number }} |
| 27 | + echo "pr=$PR" >> "$GITHUB_OUTPUT" |
| 28 | +
|
| 29 | + # Detect changed frameworks from the PR |
| 30 | + FRAMEWORKS=$(gh pr diff "$PR" --name-only | grep '^frameworks/' | cut -d'/' -f2 | sort -u | head -1) |
| 31 | + echo "framework=$FRAMEWORKS" >> "$GITHUB_OUTPUT" |
| 32 | +
|
| 33 | + if echo "$COMMENT" | grep -q '/benchmark'; then |
| 34 | + echo "command=benchmark" >> "$GITHUB_OUTPUT" |
| 35 | + # Extract optional profile: /benchmark baseline |
| 36 | + PROFILE=$(echo "$COMMENT" | grep -oP '/benchmark\s+\K\S+' || echo "") |
| 37 | + echo "profile=$PROFILE" >> "$GITHUB_OUTPUT" |
| 38 | + elif echo "$COMMENT" | grep -q '/validate'; then |
| 39 | + echo "command=validate" >> "$GITHUB_OUTPUT" |
| 40 | + fi |
| 41 | + env: |
| 42 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + |
| 44 | + - name: React to comment |
| 45 | + run: | |
| 46 | + gh api "/repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions" -f content="rocket" |
| 47 | + env: |
| 48 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 49 | + |
| 50 | + - name: Run validate |
| 51 | + if: steps.parse.outputs.command == 'validate' && steps.parse.outputs.framework != '' |
| 52 | + run: | |
| 53 | + FRAMEWORK="${{ steps.parse.outputs.framework }}" |
| 54 | + echo "Validating $FRAMEWORK..." |
| 55 | + if ./scripts/validate.sh "$FRAMEWORK" 2>&1 | tee /tmp/validate.log; then |
| 56 | + STATUS="✅ Validation **passed** for \`$FRAMEWORK\`" |
| 57 | + else |
| 58 | + STATUS="❌ Validation **failed** for \`$FRAMEWORK\`" |
| 59 | + fi |
| 60 | +
|
| 61 | + BODY="$STATUS"$'\n\n'"<details><summary>Full log</summary>"$'\n\n```\n'"$(tail -100 /tmp/validate.log)"$'\n```\n</details>' |
| 62 | + gh pr comment "${{ steps.parse.outputs.pr }}" --body "$BODY" |
| 63 | + env: |
| 64 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 65 | + |
| 66 | + - name: Run benchmark |
| 67 | + if: steps.parse.outputs.command == 'benchmark' && steps.parse.outputs.framework != '' |
| 68 | + run: | |
| 69 | + gh workflow run benchmark-pr.yml \ |
| 70 | + -f pr=${{ steps.parse.outputs.pr }} \ |
| 71 | + -f framework=${{ steps.parse.outputs.framework }} \ |
| 72 | + -f profile="${{ steps.parse.outputs.profile }}" |
| 73 | +
|
| 74 | + gh pr comment "${{ steps.parse.outputs.pr }}" --body "🚀 Benchmark run triggered for \`${{ steps.parse.outputs.framework }}\`${{ steps.parse.outputs.profile && format(' (profile: {0})', steps.parse.outputs.profile) || ' (all profiles)' }}. Results will be posted here when done." |
| 75 | + env: |
| 76 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 77 | + |
| 78 | + - name: No framework detected |
| 79 | + if: steps.parse.outputs.framework == '' |
| 80 | + run: | |
| 81 | + gh pr comment "${{ steps.parse.outputs.pr }}" --body "⚠️ Couldn't detect which framework to test. Make sure the PR modifies files under \`frameworks/<name>/\`." |
| 82 | + env: |
| 83 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments