2023-09-08 05:26:59 +00:00
|
|
|
name: comment
|
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_run:
|
2024-05-19 22:02:42 +00:00
|
|
|
workflows: [build]
|
2023-09-08 05:26:59 +00:00
|
|
|
types: [completed]
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
pr_comment:
|
2024-10-21 02:34:11 +00:00
|
|
|
if: github.event.workflow_run.event == 'pull_request' &&
|
|
|
|
github.event.workflow_run.conclusion == 'success'
|
2023-09-08 05:26:59 +00:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2024-05-19 22:02:42 +00:00
|
|
|
- env:
|
|
|
|
GH_REPO: ${{ github.repository }}
|
|
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
run: |
|
|
|
|
pr=$(gh pr list --state open --json headRefOid,number \
|
|
|
|
--jq '.[] | select(.headRefOid == "${{ github.event.workflow_run.head_sha }}") | .number')
|
|
|
|
if [ -z "$pr" ]; then
|
2024-10-21 02:34:11 +00:00
|
|
|
echo "No matching open pull request found"
|
|
|
|
exit 0
|
2024-05-19 22:02:42 +00:00
|
|
|
fi
|
2023-09-08 05:26:59 +00:00
|
|
|
|
2024-05-19 22:02:42 +00:00
|
|
|
artifacts=$(gh api repos/{owner}/{repo}/actions/runs/${{ github.event.workflow_run.id }}/artifacts --jq '.artifacts')
|
|
|
|
if [ "$(echo "$artifacts" | jq 'length')" -eq 0 ]; then
|
|
|
|
echo "No artifacts found"
|
|
|
|
exit 0
|
|
|
|
fi
|
2023-09-08 05:26:59 +00:00
|
|
|
|
2024-05-19 22:02:42 +00:00
|
|
|
body=$(echo "$artifacts" | jq -r '
|
2024-05-20 17:47:43 +00:00
|
|
|
def link: "https://nightly.link/${{ github.repository }}/actions/artifacts/\(.id).zip";
|
2024-05-20 17:26:11 +00:00
|
|
|
def entry: "* [\(.name)](\(link))";
|
2024-05-20 17:47:43 +00:00
|
|
|
"Download the artifacts for this pull request:\n<details><summary>Windows</summary>\n\n" +
|
2024-05-19 22:02:42 +00:00
|
|
|
(sort_by(.name) | map(select(.name | test("w64|msvc")) | entry) | join("\n")) +
|
2024-05-20 17:47:43 +00:00
|
|
|
"\n</details>\n<details><summary>macOS</summary>\n\n" +
|
2024-05-19 22:02:42 +00:00
|
|
|
(sort_by(.name) | map(select(.name | test("macos")) | entry) | join("\n")) +
|
|
|
|
"\n</details>"
|
|
|
|
')
|
2023-09-08 05:26:59 +00:00
|
|
|
|
2024-05-19 22:02:42 +00:00
|
|
|
comment_id=$(gh issue view $pr --json comments \
|
|
|
|
--jq '.comments[] | select(.author.login == "github-actions") | .id')
|
|
|
|
if [ -n "$comment_id" ]; then
|
|
|
|
edit=--edit-last
|
|
|
|
fi
|
|
|
|
gh pr comment $pr --body "$body" $edit
|