Skip to content

pull request build result comment #5

pull request build result comment

pull request build result comment #5

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
env:
GH_TOKEN: ${{ github.token }}
branch: ${{ github.event.workflow_run.head_branch }}
run: gh pr view --repo ${{ github.repository }} ${{ github.event.workflow_run.head_repository.owner.login }}:$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 }})