-
Notifications
You must be signed in to change notification settings - Fork 857
147 lines (127 loc) · 4.62 KB
/
Copy pathpr-description-check.yml
File metadata and controls
147 lines (127 loc) · 4.62 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: PR Description Check
on:
pull_request_target:
branches:
- master
types: [opened, edited, synchronize, reopened]
merge_group:
branches:
- master
jobs:
check-description:
runs-on: ubuntu-latest
permissions:
pull-requests: write
issues: write
# skip on merge queue, because PR context not available to make any checks
if: github.event_name != 'merge_group'
steps:
- name: Check out code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Get changed template JSON files
id: changed-templates
uses: tj-actions/changed-files@v45
with:
files: '*.json'
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Run PR description check
id: pr-check
env:
PR_BODY: ${{ github.event.pull_request.body }}
TEMPLATE_FILES: ${{ steps.changed-templates.outputs.all_changed_files }}
LABELS_ADD_FILE: /tmp/pr_labels_add.txt
LABELS_REMOVE_FILE: /tmp/pr_labels_remove.txt
REQUIRED_PAYLOAD_KEYS: ${{ secrets.REQUIRED_PAYLOAD_KEYS }}
DC_APPLY_STATE_HMAC_KEY: ${{ secrets.DC_APPLY_STATE_HMAC_KEY }}
run: |
set +e
python .github/scripts/check_pr_description.py 2>&1 | tee /tmp/pr_check_output.txt
echo "exit_code=${PIPESTATUS[0]}" >> "$GITHUB_OUTPUT"
{
echo "check_output<<EOF"
cat /tmp/pr_check_output.txt
echo "EOF"
} >> "$GITHUB_ENV"
- name: Add labels
if: always()
env:
GH_TOKEN: ${{ github.token }}
run: |
labels_file="/tmp/pr_labels_add.txt"
if [ ! -f "$labels_file" ] || [ ! -s "$labels_file" ]; then
echo "No labels to add."
exit 0
fi
pr_number="${{ github.event.pull_request.number }}"
repo="${{ github.repository }}"
while IFS= read -r label; do
[ -z "$label" ] && continue
echo "Adding label: $label"
gh pr edit "$pr_number" --repo "$repo" --add-label "$label"
done < "$labels_file"
- name: Remove labels
if: always()
env:
GH_TOKEN: ${{ github.token }}
run: |
labels_file="/tmp/pr_labels_remove.txt"
if [ ! -f "$labels_file" ] || [ ! -s "$labels_file" ]; then
echo "No labels to remove."
exit 0
fi
pr_number="${{ github.event.pull_request.number }}"
repo="${{ github.repository }}"
while IFS= read -r label; do
[ -z "$label" ] && continue
echo "Removing label: $label"
gh pr edit "$pr_number" --repo "$repo" --remove-label "$label" 2>/dev/null || true
done < "$labels_file"
- name: Comment PR - delete ok comment on failure
if: steps.pr-check.outputs.exit_code != '0'
continue-on-error: true
uses: thollander/actions-comment-pull-request@v2
with:
comment_tag: pr_description_check_ok
mode: delete
- name: Comment PR - check failed
if: steps.pr-check.outputs.exit_code != '0'
uses: thollander/actions-comment-pull-request@v2
with:
message: |
## PR Description Check Failed
The PR description is missing required elements. Please update it according to the [PR template](${{ github.server_url }}/${{ github.repository }}/blob/master/.github/pull_request_template.md?plain=1).
<details><summary>Details</summary>
```
${{ env.check_output }}
```
</details>
comment_tag: pr_description_check
mode: recreate
- name: Comment PR - delete fail comment on success
if: steps.pr-check.outputs.exit_code == '0'
continue-on-error: true
uses: thollander/actions-comment-pull-request@v2
with:
comment_tag: pr_description_check
mode: delete
- name: Comment PR - check passed
if: steps.pr-check.outputs.exit_code == '0'
uses: thollander/actions-comment-pull-request@v2
with:
message: |
## PR Description Check Passed
All required sections are filled in correctly.
<details><summary>Details</summary>
```
${{ env.check_output }}
```
</details>
comment_tag: pr_description_check_ok
- name: Fail job if check failed
if: steps.pr-check.outputs.exit_code != '0'
run: exit 1