PR Gate #827
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 Gate | |
| on: | |
| pull_request: | |
| branches: [main] | |
| types: [opened, synchronize, reopened, labeled, unlabeled] | |
| workflow_run: | |
| workflows: ['PR E2E Tests (Required)'] | |
| types: [completed] | |
| permissions: | |
| statuses: write | |
| pull-requests: read | |
| jobs: | |
| # ── On pull_request: set initial gate status ── | |
| pr-gate: | |
| if: github.event_name == 'pull_request' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Set validation status | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const labels = context.payload.pull_request.labels.map(l => l.name); | |
| const sha = context.payload.pull_request.head.sha; | |
| const branch = context.payload.pull_request.head.ref; | |
| // Release branches skip validation | |
| if (branch.startsWith('release/')) { | |
| await github.rest.repos.createCommitStatus({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| sha, | |
| state: 'success', | |
| context: 'PR Validation', | |
| description: 'Release branch — validation skipped', | |
| }); | |
| core.info('Release branch — auto-pass'); | |
| return; | |
| } | |
| if (!labels.includes('run-tests')) { | |
| // No label — block merge until validation is triggered | |
| await github.rest.repos.createCommitStatus({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| sha, | |
| state: 'failure', | |
| context: 'PR Validation', | |
| description: 'Add the run-tests label to trigger validation', | |
| }); | |
| core.info('No run-tests label — gate blocks merge'); | |
| } else { | |
| // Label present — block merge until validation workflow completes | |
| await github.rest.repos.createCommitStatus({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| sha, | |
| state: 'pending', | |
| context: 'PR Validation', | |
| description: 'Waiting for PR E2E Tests to complete...', | |
| }); | |
| core.info('run-tests label found — set pending, waiting for E2E tests'); | |
| } | |
| # ── On workflow_run: update gate after E2E tests finish ── | |
| update-gate: | |
| if: github.event_name == 'workflow_run' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Update validation status from E2E result | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const run = context.payload.workflow_run; | |
| const sha = run.head_sha; | |
| const conclusion = run.conclusion; // success, failure, cancelled, etc. | |
| const passed = conclusion === 'success'; | |
| await github.rest.repos.createCommitStatus({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| sha, | |
| state: passed ? 'success' : 'failure', | |
| context: 'PR Validation', | |
| description: passed | |
| ? 'PR E2E Tests passed' | |
| : `PR E2E Tests ${conclusion}`, | |
| }); | |
| core.info(`E2E tests ${conclusion} — set PR Validation to ${passed ? 'success' : 'failure'}`); |