-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathdocs-pr-failure-post-comment.yml
More file actions
66 lines (58 loc) · 2.01 KB
/
Copy pathdocs-pr-failure-post-comment.yml
File metadata and controls
66 lines (58 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
name: Post PR comment with doc-build failure log
env:
DOCS_FAILURE_ARTIFACT: test-build-docs-container_failed
on:
workflow_run:
workflows: ["Test building docs when they're updated"]
types: [completed]
jobs:
comment:
if: >-
github.event.workflow_run.event == 'pull_request'
&& github.event.workflow_run.conclusion == 'failure'
runs-on: ubuntu-latest
permissions:
pull-requests: write
actions: read
steps:
- name: Check for failure artifact
id: check
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
run: |
gh api repos/$REPO/actions/runs/${{ github.event.workflow_run.id }}/artifacts \
--jq '.artifacts[] | select(.name == "${{ env.DOCS_FAILURE_ARTIFACT }}") | .id' > artifact_id.txt
if [ -s artifact_id.txt ]; then
echo "found=true" >> $GITHUB_OUTPUT
else
echo "found=false" >> $GITHUB_OUTPUT
fi
- name: Download logs
if: steps.check.outputs.found == 'true'
uses: actions/download-artifact@v4
with:
name: ${{ env.DOCS_FAILURE_ARTIFACT }}
path: ${{ env.DOCS_FAILURE_ARTIFACT }}
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Post comment
if: steps.check.outputs.found == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
run: |
PR_NUMBER=$(cat "${DOCS_FAILURE_ARTIFACT}/pr_number.txt")
{
echo "### ❌ Docs build failed"
echo
echo '<details open="true">'
echo "<summary>Build logs</summary>"
echo
echo '```'
cat "${DOCS_FAILURE_ARTIFACT}/build.log"
echo '```'
echo
echo "</details>"
} > comment-body.md
gh pr comment "$PR_NUMBER" --repo "$REPO" --body-file comment-body.md