|
6 | 6 | types: [created] |
7 | 7 | push: |
8 | 8 | branches: [main] |
| 9 | + pull_request: |
| 10 | + types: |
| 11 | + - opened |
| 12 | + - synchronize |
9 | 13 | # Cancel the job if new commits are pushed |
10 | 14 | # https://stackoverflow.com/questions/66335225/how-to-cancel-previous-runs-in-the-pr-when-you-push-new-commitsupdate-the-curre |
11 | 15 | concurrency: |
12 | | - group: ${{ github.workflow }}-${{ github.event.issue.number || github.ref }} |
| 16 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.issue.number || github.ref }} |
13 | 17 | cancel-in-progress: true |
14 | 18 | jobs: |
| 19 | + set-pending: |
| 20 | + name: GPU Tests Pending |
| 21 | + if: github.event_name == 'pull_request' |
| 22 | + runs-on: ubuntu-latest |
| 23 | + permissions: |
| 24 | + statuses: write |
| 25 | + steps: |
| 26 | + - name: Set pending status on PR |
| 27 | + run: | |
| 28 | + for context in "CI-Pass" "All Tests Green"; do |
| 29 | + gh api repos/${{ github.repository }}/statuses/${{ github.event.pull_request.head.sha }} \ |
| 30 | + -f state=pending \ |
| 31 | + -f context="$context" \ |
| 32 | + -f description="Waiting for /test-gpu command..." |
| 33 | + done |
| 34 | + env: |
| 35 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 36 | + |
15 | 37 | check: |
16 | 38 | runs-on: ubuntu-latest |
17 | | - # Skip issue_comment unless it's /test-gpu on a PR |
| 39 | + # Skip pull_request (handled by set-pending) and issue_comment unless /test-gpu |
18 | 40 | if: >- |
19 | | - github.event_name != 'issue_comment' || |
20 | | - (github.event.issue.pull_request && startsWith(github.event.comment.body, '/test-gpu')) |
| 41 | + github.event_name != 'pull_request' && ( |
| 42 | + github.event_name != 'issue_comment' || |
| 43 | + (github.event.issue.pull_request && startsWith(github.event.comment.body, '/test-gpu')) |
| 44 | + ) |
| 45 | + outputs: |
| 46 | + head-sha: ${{ steps.get-sha.outputs.sha }} |
21 | 47 | permissions: |
22 | 48 | pull-requests: write |
| 49 | + statuses: write |
23 | 50 | steps: |
24 | 51 | - name: Check permissions |
25 | 52 | if: github.event_name == 'issue_comment' || github.event_name == 'workflow_dispatch' |
|
39 | 66 | env: |
40 | 67 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
41 | 68 |
|
| 69 | + - name: Get PR head SHA |
| 70 | + id: get-sha |
| 71 | + if: github.event_name == 'issue_comment' |
| 72 | + run: | |
| 73 | + SHA=$(gh pr view ${{ github.event.issue.number }} --repo ${{ github.repository }} --json headRefOid -q .headRefOid) |
| 74 | + echo "sha=$SHA" >> $GITHUB_OUTPUT |
| 75 | + env: |
| 76 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 77 | + |
| 78 | + - name: Set pending status on PR |
| 79 | + if: github.event_name == 'issue_comment' |
| 80 | + run: | |
| 81 | + for context in "CI-Pass" "All Tests Green"; do |
| 82 | + gh api repos/${{ github.repository }}/statuses/${{ steps.get-sha.outputs.sha }} \ |
| 83 | + -f state=pending \ |
| 84 | + -f context="$context" \ |
| 85 | + -f description="GPU tests running..." \ |
| 86 | + -f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 87 | + done |
| 88 | + env: |
| 89 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
42 | 90 |
|
43 | 91 | get-envs: |
44 | 92 | runs-on: ubuntu-latest |
@@ -170,26 +218,76 @@ jobs: |
170 | 218 |
|
171 | 219 | stable-dev-green: |
172 | 220 | name: CI-Pass |
173 | | - if: always() |
| 221 | + if: always() && github.event_name != 'pull_request' |
174 | 222 | needs: |
| 223 | + - check |
175 | 224 | - get-envs |
176 | 225 | - test-stable-dev |
177 | 226 | runs-on: ubuntu-latest |
| 227 | + permissions: |
| 228 | + statuses: write |
178 | 229 | steps: |
179 | 230 | - uses: re-actors/alls-green@release/v1 |
180 | 231 | with: |
181 | 232 | jobs: ${{ toJSON(needs) }} |
182 | 233 |
|
| 234 | + - name: Set success status on PR |
| 235 | + if: success() && github.event_name == 'issue_comment' |
| 236 | + run: | |
| 237 | + gh api repos/${{ github.repository }}/statuses/${{ needs.check.outputs.head-sha }} \ |
| 238 | + -f state=success \ |
| 239 | + -f context="CI-Pass" \ |
| 240 | + -f description="GPU tests passed" \ |
| 241 | + -f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 242 | + env: |
| 243 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 244 | + |
| 245 | + - name: Set failure status on PR |
| 246 | + if: failure() && github.event_name == 'issue_comment' |
| 247 | + run: | |
| 248 | + gh api repos/${{ github.repository }}/statuses/${{ needs.check.outputs.head-sha }} \ |
| 249 | + -f state=failure \ |
| 250 | + -f context="CI-Pass" \ |
| 251 | + -f description="GPU tests failed" \ |
| 252 | + -f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 253 | + env: |
| 254 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 255 | + |
183 | 256 | all-green: |
184 | 257 | name: All Tests Green |
185 | | - if: always() |
| 258 | + if: always() && github.event_name != 'pull_request' |
186 | 259 | needs: |
| 260 | + - check |
187 | 261 | - get-envs |
188 | 262 | - test-stable-dev |
189 | 263 | - test-prerelease |
190 | 264 | runs-on: ubuntu-latest |
| 265 | + permissions: |
| 266 | + statuses: write |
191 | 267 | steps: |
192 | 268 | - uses: re-actors/alls-green@release/v1 |
193 | 269 | with: |
194 | 270 | allowed-failures: test-prerelease |
195 | 271 | jobs: ${{ toJSON(needs) }} |
| 272 | + |
| 273 | + - name: Set success status on PR |
| 274 | + if: success() && github.event_name == 'issue_comment' |
| 275 | + run: | |
| 276 | + gh api repos/${{ github.repository }}/statuses/${{ needs.check.outputs.head-sha }} \ |
| 277 | + -f state=success \ |
| 278 | + -f context="All Tests Green" \ |
| 279 | + -f description="All GPU tests passed" \ |
| 280 | + -f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 281 | + env: |
| 282 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 283 | + |
| 284 | + - name: Set failure status on PR |
| 285 | + if: failure() && github.event_name == 'issue_comment' |
| 286 | + run: | |
| 287 | + gh api repos/${{ github.repository }}/statuses/${{ needs.check.outputs.head-sha }} \ |
| 288 | + -f state=failure \ |
| 289 | + -f context="All Tests Green" \ |
| 290 | + -f description="GPU tests failed" \ |
| 291 | + -f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 292 | + env: |
| 293 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments