-
Notifications
You must be signed in to change notification settings - Fork 5
57 lines (50 loc) · 1.71 KB
/
pr.yaml
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
name: Validate `awesome.toml`
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Validate sections
id: validate
run: |
set +e # Allow the script to fail but capture its output
{
echo "output<<EOF"
bash .github/workflows/check_sorting.sh
exit_code="$?"
echo EOF
} >> "$GITHUB_OUTPUT"
echo "exit_code=$exit_code" >> "$GITHUB_OUTPUT"
exit "$exit_code"
- name: Post PR Comment
if: github.event_name == 'pull_request'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
COMMENT_BODY="${{ steps.validate.outputs.output }}"
EXIT_CODE="${{ steps.validate.outputs.exit_code }}"
EXISTING_COMMENT=$(gh pr view "$PR_NUMBER" \
--json comments \
--jq '.comments[] | select(.author.login=="github-actions")')
if [ "$EXIT_CODE" -ne 0 ]; then
if [ -n "$EXISTING_COMMENT" ]; then
gh pr comment "$PR_NUMBER" --body "$COMMENT_BODY" --edit-last
else
gh pr comment "$PR_NUMBER" --body "$COMMENT_BODY"
fi
else
if [ -n "$EXISTING_COMMENT" ]; then
# Currently the gh cli and the API fail to delete comments so we
# just update any existing one for now.
gh pr comment "$PR_NUMBER" --body "Thanks for fixing the CI issues!" --edit-last
fi
fi