|
| 1 | +name: Pull Request Comment |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ['Publish wiki'] |
| 6 | + types: |
| 7 | + - completed |
| 8 | + |
| 9 | +# Cancels all previous workflow runs for pull requests that have not completed. |
| 10 | +concurrency: |
| 11 | + # The concurrency group contains the workflow name and the branch name for pull requests |
| 12 | + # or the commit hash for any other events. |
| 13 | + group: ${{ github.workflow }}-${{ github.sha }} |
| 14 | + |
| 15 | +jobs: |
| 16 | + artifact-review-comment: |
| 17 | + if: > |
| 18 | + github.repository == 'PHPCSStandards/PHP_CodeSniffer-documentation' && |
| 19 | + github.event.workflow_run.event == 'pull_request' && |
| 20 | + github.event.workflow_run.conclusion == 'success' |
| 21 | +
|
| 22 | + runs-on: ubuntu-latest |
| 23 | + |
| 24 | + permissions: |
| 25 | + # Needed for the PR comment. |
| 26 | + pull-requests: write |
| 27 | + |
| 28 | + name: Comment on a pull request |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Download PR info artifact |
| 32 | + uses: actions/github-script@v7 |
| 33 | + with: |
| 34 | + script: | |
| 35 | + const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ |
| 36 | + owner: context.repo.owner, |
| 37 | + repo: context.repo.repo, |
| 38 | + run_id: context.payload.workflow_run.id, |
| 39 | + }); |
| 40 | +
|
| 41 | + const matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { |
| 42 | + return artifact.name == "pr_info" |
| 43 | + })[0]; |
| 44 | +
|
| 45 | + if ( ! matchArtifact ) { |
| 46 | + core.setFailed( 'No artifact found!' ); |
| 47 | + return; |
| 48 | + } |
| 49 | +
|
| 50 | + const download = await github.rest.actions.downloadArtifact({ |
| 51 | + owner: context.repo.owner, |
| 52 | + repo: context.repo.repo, |
| 53 | + artifact_id: matchArtifact.id, |
| 54 | + archive_format: 'zip', |
| 55 | + }); |
| 56 | +
|
| 57 | + const fs = require('fs'); |
| 58 | + const path = require('path'); |
| 59 | + const temp = '${{ runner.temp }}/artifacts'; |
| 60 | + if (!fs.existsSync(temp)){ |
| 61 | + fs.mkdirSync(temp); |
| 62 | + } |
| 63 | + fs.writeFileSync(path.join(temp, 'pr_info.zip'), Buffer.from(download.data)); |
| 64 | +
|
| 65 | + - name: Unzip PR info artifact |
| 66 | + run: unzip pr_info.zip -d "${{ runner.temp }}/artifacts" |
| 67 | + |
| 68 | + - name: "DEBUG: show dir layout" |
| 69 | + run: ls -aohR "${{ runner.temp }}/artifacts" |
| 70 | + |
| 71 | + - name: Read PR number |
| 72 | + id: pr_number |
| 73 | + shell: bash |
| 74 | + run: | |
| 75 | + value=$(<"${{ runner.temp }}/artifacts/pr_number") |
| 76 | + echo "PR_NR=$value" >> "$GITHUB_OUTPUT" |
| 77 | +
|
| 78 | + - name: Read Wiki artifact URL |
| 79 | + id: artifact_url |
| 80 | + shell: bash |
| 81 | + run: | |
| 82 | + value=$(<"${{ runner.temp }}/artifacts/artifact_url") |
| 83 | + echo "URL=$value" >> "$GITHUB_OUTPUT" |
| 84 | +
|
| 85 | + - name: "DEBUG: show grabbed PR nr" |
| 86 | + run: echo ${{ steps.pr_number.outputs.PR_NR }} |
| 87 | + |
| 88 | + - name: "DEBUG: show grabbed artifact URL" |
| 89 | + run: echo ${{ steps.artifact_url.outputs.URL }} |
| 90 | + |
| 91 | + - name: "Post comment to review artifact" |
| 92 | + uses: mshick/add-pr-comment@v2 |
| 93 | + with: |
| 94 | + issue: ${{ steps.pr_number.outputs.PR_NR }} |
| 95 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 96 | + message: | |
| 97 | + **_=== This is an auto-generated comment ===_** |
| 98 | +
|
| 99 | + Thank you for your PR. |
| 100 | + A dry-run has been executed on your PR, executing all markdown pre-processing for the wiki files. |
| 101 | +
|
| 102 | + Please review the resulting final markdown files via the [created artifact](${{ steps.artifact_url.outputs.URL }}). |
| 103 | + This is especially important when adding new pages or updating auto-generated output blocks. |
| 104 | +
|
| 105 | + _N.B.: the above link will automatically be updated when this PR is updated._ |
0 commit comments