comment #274
This file contains 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: comment | |
on: | |
workflow_run: | |
workflows: [build] | |
types: [completed] | |
jobs: | |
pr_comment: | |
if: github.event.workflow_run.event == 'pull_request' && | |
github.event.workflow_run.conclusion == 'success' | |
runs-on: ubuntu-latest | |
steps: | |
- env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
gh repo set-default ${{ github.repository }} | |
pr=$(gh pr list --state open --json headRefOid,number \ | |
--jq '.[] | select(.headRefOid == "${{ github.event.workflow_run.head_sha }}") | .number') | |
if [ -z "$pr" ]; then | |
echo "No matching pull request found" | |
exit 1 | |
fi | |
artifacts=$(gh run view ${{ github.event.workflow_run.id }} --json artifacts --jq '.artifacts') | |
if [ -z "$artifacts" ]; then | |
echo "No artifacts found" | |
exit 1 | |
fi | |
body=$(echo "$artifacts" | jq -r ' | |
def link: "https://github.com/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/runs/${{ github.event.workflow_run.id }}/artifacts/\(.id)"; | |
def entry: "* [\(.name)](link)"; | |
"Download the artifacts for this pull request:\n\n<details><summary>Windows</summary>\n" + | |
(sort_by(.name) | map(select(.name | test("w64|msvc")) | entry) | join("\n")) + | |
"\n</details>\n\n<details><summary>macOS</summary>\n" + | |
(sort_by(.name) | map(select(.name | test("macos")) | entry) | join("\n")) + | |
"\n</details>" | |
') | |
comment_id=$(gh issue comment list $pr --json id,author \ | |
--jq '.[] | select(.author.login == "github-actions[bot]") | .id') | |
if [ -z "$comment_id" ]; then | |
gh pr comment $pr --body "$body" | |
else | |
gh issue comment update $comment_id --body "$body" | |
fi |