Skip to content

Commit 4e249e9

Browse files
committed
prBuildResultComment test [skip ci]
1 parent ab43984 commit 4e249e9

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: pull request build result comment
2+
on:
3+
workflow_run:
4+
workflows: [build]
5+
types: [completed]
6+
jobs:
7+
success:
8+
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}
9+
runs-on: ubuntu-latest
10+
steps:
11+
# The pull request number isn't readily available, so get it using the
12+
# branch.
13+
# https://github.com/orgs/community/discussions/25220#discussioncomment-11300118
14+
- id: getPr
15+
name: get PR number
16+
env:
17+
GH_TOKEN: ${{ github.token }}
18+
prBranch: |-
19+
${{
20+
(github.event.workflow_run.head_repository.owner.login != github.event.workflow_run.repository.owner.login)
21+
&& format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch)
22+
|| github.event.workflow_run.head_branch
23+
}}
24+
run: gh pr view --repo ${{ github.repository }} $prBranch --json 'number' --jq '"number=\(.number)"' >> "${GITHUB_OUTPUT}"
25+
# Get the URLs to the Windows and mac artifacts.
26+
- id: getUrls
27+
name: get URLs
28+
uses: actions/github-script@v7
29+
with:
30+
script: |
31+
const result = {};
32+
const resp = await github.rest.actions.listWorkflowRunArtifacts({
33+
owner: context.repo.owner,
34+
repo: context.repo.repo,
35+
run_id: context.payload.workflow_run.id,
36+
});
37+
for (const artifact of resp.data.artifacts) {
38+
if (artifact.name.startsWith("osara_windows")) {
39+
result.windows = artifact.archive_download_url;
40+
} else if (artifact.name.startsWith("osara_mac")) {
41+
result.mac = artifact.archive_download_url;
42+
}
43+
}
44+
return result;
45+
- name: comment
46+
uses: thollander/actions-comment-pull-request@v3
47+
with:
48+
pr-number: ${{ steps.getPr.outputs.number }}
49+
message: |
50+
[Build ${{ github.event.workflow_run.run_number }} succeeded!](https://github.com/jcsteh/osara/actions/runs/${{ github.event.workflow_run.id }})
51+
- [Download for Windows](${{ fromJSON(steps.getUrls.outputs.result).windows }})
52+
- [Download for Mac](${{ fromJSON(steps.getUrls.outputs.result).mac }})
53+
failure:
54+
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'failure' }}
55+
runs-on: ubuntu-latest
56+
steps:
57+
- name: comment
58+
uses: thollander/actions-comment-pull-request@v3
59+
with:
60+
pr-number:
61+
message: |
62+
[Build ${{ github.event.workflow_run.run_number }} failed!](https://github.com/jcsteh/osara/actions/runs/${{ github.event.workflow_run.id }})

0 commit comments

Comments
 (0)