pull request build result comment #4
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: pull request build result comment | |
| on: | |
| workflow_run: | |
| workflows: [build] | |
| types: [completed] | |
| jobs: | |
| success: | |
| if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| # The pull request number isn't readily available, so get it using the | |
| # branch. | |
| - id: getPr | |
| name: get PR number | |
| run: gh pr view --repo ${{ github.repository }} ${{ github.event.workflow_run.head_repository.owner.login }}:${{ github.event.workflow_run.head_branch }} --json 'number' --jq '"number=\(.number)"' >> "${GITHUB_OUTPUT}" | |
| # Get the URLs to the Windows and mac artifacts. | |
| - id: getUrls | |
| name: get URLs | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const result = {}; | |
| const resp = await github.rest.actions.listWorkflowRunArtifacts({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| run_id: context.payload.workflow_run.id, | |
| }); | |
| for (const artifact of resp.data.artifacts) { | |
| if (artifact.name.startsWith("osara_windows")) { | |
| result.windows = artifact.archive_download_url; | |
| } else if (artifact.name.startsWith("osara_mac")) { | |
| result.mac = artifact.archive_download_url; | |
| } | |
| } | |
| return result; | |
| - name: comment | |
| uses: thollander/actions-comment-pull-request@v3 | |
| with: | |
| pr-number: ${{ steps.getPr.outputs.number }} | |
| message: | | |
| [Build succeeded!](https://github.com/jcsteh/osara/actions/runs/${{ github.event.workflow_run.id }}) | |
| - [Download for Windows](${{ steps.getUrls.outputs.windows }}) | |
| - [Download for Mac](${{ steps.getUrls.outputs.mac }}) | |
| failure: | |
| if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'failure' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: comment | |
| uses: thollander/actions-comment-pull-request@v3 | |
| with: | |
| pr-number: | |
| message: | | |
| [Build failed!](https://github.com/jcsteh/osara/actions/runs/${{ github.event.workflow_run.id }}) |