|
| 1 | +name: Handle Validation Result |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["Commit Validation"] |
| 6 | + types: [completed] |
| 7 | + |
| 8 | +permissions: |
| 9 | + actions: read |
| 10 | + contents: read |
| 11 | + issues: write |
| 12 | + pull-requests: write |
| 13 | + # needed because gh cli fetches unnecessary extra data |
| 14 | + repository-projects: read |
| 15 | + |
| 16 | +jobs: |
| 17 | + handle-validation-result: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: 'Download PR number artifact' |
| 21 | + uses: actions/github-script@v6 |
| 22 | + with: |
| 23 | + script: | |
| 24 | + let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ |
| 25 | + owner: context.repo.owner, |
| 26 | + repo: context.repo.repo, |
| 27 | + run_id: context.payload.workflow_run.id, |
| 28 | + }); |
| 29 | + let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { |
| 30 | + return artifact.name == "pr_number.txt" |
| 31 | + })[0]; |
| 32 | + let download = await github.rest.actions.downloadArtifact({ |
| 33 | + owner: context.repo.owner, |
| 34 | + repo: context.repo.repo, |
| 35 | + artifact_id: matchArtifact.id, |
| 36 | + archive_format: 'zip', |
| 37 | + }); |
| 38 | + let fs = require('fs'); |
| 39 | + fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr_number.zip`, Buffer.from(download.data)); |
| 40 | +
|
| 41 | + - name: 'Unzip artifact' |
| 42 | + run: unzip pr_number.zip |
| 43 | + |
| 44 | + - name: Mark unstale if success |
| 45 | + if: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 46 | + run: | |
| 47 | + export PR_NUMBER=$(cat pr_number.txt) |
| 48 | + echo "In repo $GH_REPO on PR $PR_NUMBER" |
| 49 | +
|
| 50 | + if gh pr view -R"$GH_REPO" "$PR_NUMBER" --json labels | grep stale ; then |
| 51 | + echo "No longer stale" |
| 52 | + gh pr edit -R"$GH_REPO" "$PR_NUMBER" --remove-label stale |
| 53 | + gh pr comment -R"$GH_REPO" "$PR_NUMBER" --body 'The validity checks are now passing. Thank you.' |
| 54 | + else |
| 55 | + echo "Was already not stale" |
| 56 | + fi |
| 57 | + env: |
| 58 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + GH_REPO: ${{ github.event.repository.full_name }} |
| 60 | + |
| 61 | + - name: Make comment and mark stale if failed |
| 62 | + if: ${{ github.event.workflow_run.conclusion == 'failure' }} |
| 63 | + run: | |
| 64 | + export PR_NUMBER=$(cat pr_number.txt) |
| 65 | + echo "In repo $GH_REPO on PR $PR_NUMBER" |
| 66 | +
|
| 67 | + echo "Mark as stale" |
| 68 | + gh pr edit -R"$GH_REPO" "$PR_NUMBER" --add-label stale |
| 69 | + gh pr comment -R"$GH_REPO" "$PR_NUMBER" --body 'The validity checks failed. Please look at the logs (click the red X) and correct the errors. Your PR will be closed automatically in 2 days if not fixed.' |
| 70 | + env: |
| 71 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 72 | + GH_REPO: ${{ github.event.repository.full_name }} |
0 commit comments