|
| 1 | +name: Set Test Statuses |
| 2 | +on: |
| 3 | + - pull_request_target |
| 4 | +permissions: |
| 5 | + pull-requests: write |
| 6 | + checks: write |
| 7 | + contents: write |
| 8 | + statuses: write |
| 9 | +jobs: |
| 10 | + # Tugboat tests are not automatically set pending, even though they are |
| 11 | + # required in branch protection rules (see #10553). |
| 12 | + # |
| 13 | + # Therefore, a PR can inappropriately appear to be ready to merge if, |
| 14 | + # for instance, a composer.lock merge conflict prevents the Tugboat |
| 15 | + # preview from successfully building. |
| 16 | + # |
| 17 | + # Additionally, CI tests are only run for code changes but they are |
| 18 | + # required checks, even for documentation only changes. In these cases, |
| 19 | + # the tests should be skipped since no functional changes have occured. |
| 20 | + # |
| 21 | + # To address these two issues, this action sets check statuses directly |
| 22 | + # to the appropriate states: |
| 23 | + # - For docs only changes, all required checks are set to 'success' |
| 24 | + # - For code changes, Tugboat tests are set to 'pending' so that we can |
| 25 | + # trust our automated code review processes more. |
| 26 | + set-test-statuses: |
| 27 | + name: Set Tests Statuses |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - name: Check for documentation only changes |
| 31 | + id: docs-only |
| 32 | + uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1 |
| 33 | + with: |
| 34 | + script: | |
| 35 | + const opts = github.rest.pulls.listFiles.endpoint.merge({ |
| 36 | + owner: context.repo.owner, |
| 37 | + repo: context.repo.repo, |
| 38 | + pull_number: context.payload.pull_request.number, |
| 39 | + }) |
| 40 | + const files = await github.paginate( |
| 41 | + opts, |
| 42 | + (response) => response.data.map( |
| 43 | + (file) => file.filename |
| 44 | + ) |
| 45 | + ) |
| 46 | +
|
| 47 | + for (const file of files) { |
| 48 | + console.log(`Checking PR file: ${file}`) |
| 49 | + if (!file.endsWith('.md')) { |
| 50 | + console.log(`Code change found in: ${file}`) |
| 51 | + return "false" |
| 52 | + } |
| 53 | + } |
| 54 | +
|
| 55 | + console.log(`No code change found.`) |
| 56 | + return "true" |
| 57 | + result-encoding: string |
| 58 | + - name: Set status for documentation changes. |
| 59 | + if: ${{ steps.docs-only.outputs.result == 'true' }} |
| 60 | + run: | |
| 61 | + test_names=( |
| 62 | + va/tests/cypress |
| 63 | + va/tests/phpunit |
| 64 | + va/tests/content-build-gql |
| 65 | + va/tests/status-error |
| 66 | + 'Composer Validate' |
| 67 | + 'Check Fields' |
| 68 | + ESLint |
| 69 | + Stylelint |
| 70 | + PHPStan |
| 71 | + PHPUnit |
| 72 | + PHP_CodeSniffer |
| 73 | + 'PHP Lint' |
| 74 | + ) |
| 75 | + for test_name in "${test_names[@]}"; do |
| 76 | + gh api \ |
| 77 | + --method POST \ |
| 78 | + -H "Accept: application/vnd.github+json" \ |
| 79 | + "/repos/${GITHUB_REPOSITORY}/statuses/${SHA}" \ |
| 80 | + -f state='success' \ |
| 81 | + -f context="${test_name}"; |
| 82 | + done; |
| 83 | + env: |
| 84 | + SHA: ${{ github.event.pull_request.head.sha }} |
| 85 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 86 | + - name: Set status for code changes. |
| 87 | + if: ${{ steps.docs-only.outputs.result == 'false' }} |
| 88 | + run: | |
| 89 | + test_names=( |
| 90 | + va/tests/cypress |
| 91 | + va/tests/phpunit |
| 92 | + va/tests/content-build-gql |
| 93 | + va/tests/status-error |
| 94 | + ) |
| 95 | + for test_name in "${test_names[@]}"; do |
| 96 | + gh api \ |
| 97 | + --method POST \ |
| 98 | + -H "Accept: application/vnd.github+json" \ |
| 99 | + "/repos/${GITHUB_REPOSITORY}/statuses/${SHA}" \ |
| 100 | + -f state='pending' \ |
| 101 | + -f context="${test_name}"; |
| 102 | + done; |
| 103 | + env: |
| 104 | + SHA: ${{ github.event.pull_request.head.sha }} |
| 105 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments