-
Notifications
You must be signed in to change notification settings - Fork 1
262 lines (234 loc) · 10.3 KB
/
report-maker.yml
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# Candace Savonen March 2022
# This calls the report makers but then also handles the commenting
name: Run error checker
on:
workflow_call:
inputs:
check_type:
required: true
type: string
error_min:
default: 0
type: number
sort_dictionary:
default: false
type: boolean
gh_pat:
type: string
required: true
branch_name:
type: string
default: ${GITHUB_REF#refs/heads/}
jobs:
status-update:
runs-on: ubuntu-latest
steps:
- name: Declare report name
id: setup1
run: |
if ${{ contains(inputs.check_type, 'spelling') }} ;then
echo "error_name=spelling errors" >> $GITHUB_OUTPUT
echo "ignore_file=resources/dictionary.txt" >> $GITHUB_OUTPUT
elif ${{ contains(inputs.check_type, 'urls') }} ;then
echo "error_name=broken url errors" >> $GITHUB_OUTPUT
echo "ignore_file=resources/ignore-urls.txt" >> $GITHUB_OUTPUT
elif ${{ contains(inputs.check_type, 'quiz_format') }} ;then
echo "error_name=quiz formatting errors" >> $GITHUB_OUTPUT
fi
- name: Build components of the spell check comment
id: build-components1
run: |
echo "time=$(date +'%Y-%m-%d-%T')" >> $GITHUB_OUTPUT
echo "commit_id=$GITHUB_SHA" >> $GITHUB_OUTPUT
shell: bash
- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc1
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: ${{ steps.setup1.outputs.error_name }}
- name: Status update
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc1.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
The ${{ steps.setup1.outputs.error_name }} check is currently being re-run :runner:
_Comment updated at ${{ steps.build-components1.outputs.time }} with changes from ${{ steps.build-components1.outputs.commit_id }}_
edit-mode: replace
error-check:
runs-on: ubuntu-latest
container:
image: jhudsl/base_ottr:main
steps:
- name: Declare report name
id: setup2
run: |
if ${{ contains(inputs.check_type, 'spelling') }} ;then
echo "error_name=spelling errors" >> $GITHUB_OUTPUT
echo "ignore_file=resources/dictionary.txt" >> $GITHUB_OUTPUT
elif ${{ contains(inputs.check_type, 'urls') }} ;then
echo "error_name=broken url errors" >> $GITHUB_OUTPUT
echo "ignore_file=resources/ignore-urls.txt" >> $GITHUB_OUTPUT
elif ${{ contains(inputs.check_type, 'quiz_format') }} ;then
echo "error_name=quiz formatting errors" >> $GITHUB_OUTPUT
fi
- name: Build components of the spell check comment
id: build-components2
run: |
branch_name='preview-${{ github.event.pull_request.number }}'
echo "time=$(date +'%Y-%m-%d-%T')" >> $GITHUB_OUTPUT
echo "commit_id=$GITHUB_SHA" >> $GITHUB_OUTPUT
shell: bash
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: 'preview-${{ github.event.pull_request.number }}'
- name: Run the check
uses: jhudsl/ottr-reports@main
id: check_results
continue-on-error: true
with:
check_type: ${{ inputs.check_type }}
error_min: ${{ inputs.error_min }}
- name: Declare file path and time
id: file-path
run: |
branch_name='preview-${{ github.event.pull_request.number }}'
echo "link_to_ignore_file=https://github.com/${GITHUB_REPOSITORY}/edit/${{ inputs.branch_name }}/${{ steps.setup.outputs.ignore_file }}" >> $GITHUB_OUTPUT
echo "time=$(date +'%Y-%m-%d-%T')" >> $GITHUB_OUTPUT
echo "error_url=https://github.com/${GITHUB_REPOSITORY}/blob/$branch_name/${{ steps.check_results.outputs.report_path }}" >> $GITHUB_OUTPUT
shell: bash
- name: Find Comment Again
uses: peter-evans/find-comment@v3
id: fc2
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: ${{ steps.setup2.outputs.error_name }}
- name: Say check is incomplete
if: steps.check_results.outcome == 'failure'
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc2.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
:warning: Check: ${{ steps.setup2.outputs.error_name }} did not fully run! Go to the `Actions` tab to find more info.
Post issue to https://github.com/jhudsl/OTTR_Template/issues if this seems incorrect.
_Comment updated at ${{ steps.build-components2.outputs.time }} with changes from ${{ steps.build-components2.outputs.commit_id }}_
edit-mode: replace
- name: Stop if failure
if: steps.check_results.outcome == 'failure'
run: exit 1
############################# Handle commenting ################################
- name: Commit check files to branch
id: commit
run: |
branch_name='preview-${{ github.event.pull_request.number }}'
git config --global --add safe.directory $GITHUB_WORKSPACE
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add ${{ steps.check_results.outputs.report_path }} --force || echo "No changes to commit"
git commit -m 'Add check file' || echo "No changes to commit"
git pull --rebase --set-upstream origin $branch_name --allow-unrelated-histories --strategy-option=ours
git merge origin/${{ github.head_ref }} --allow-unrelated-histories --strategy-option ours
git push origin $branch_name --force || echo "No changes to commit"
error_num=$(cat ${{ steps.check_results.outputs.report_path }} | wc -l)
error_num="$((error_num-1))"
echo "error_num=$error_num" >> $GITHUB_OUTPUT
shell: bash
- name: There are errors!
if: ${{ steps.commit.outputs.error_num > inputs.error_min }}
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc2.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
:warning: ${{ steps.setup2.outputs.error_name }} :warning:
There are ${{ steps.setup2.outputs.error_name }} that need to be addressed.
Click here :arrow_right: [for ${{ steps.setup2.outputs.error_name }}!](${{ steps.file-path.outputs.error_url }}) :exclamation:
Add errors that aren't errors to the [${{ steps.setup2.outputs.ignore_file }}](${{ steps.file-path.outputs.link_to_ignore_file }}) file of this repo.
If you are having troubles see [this guide](https://www.ottrproject.org/faqs.html#Most_Common_Errors)
_Comment updated at ${{ steps.build-components2.outputs.time }} with changes from ${{ steps.build-components2.outputs.commit_id }}_
edit-mode: replace
- name: Fail if too many errors
if: ${{ steps.commit.outputs.error_num > inputs.error_min }}
run: |
echo ${{ steps.commit.outputs.error_num }}
exit 1
shell: bash
- name: Don't fail if not too many errors
if: ${{ steps.commit.outputs.error_num <= inputs.error_min }}
run: |
echo ${{ steps.commit.outputs.error_num }}
shell: bash
- name: No errors comment
if: ${{ steps.commit.outputs.error_num <= inputs.error_min }}
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc2.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
No ${{ steps.setup2.outputs.error_name }}! :tada:
_Comment updated at ${{ steps.build-components2.outputs.time }} with changes from ${{ steps.build-components2.outputs.commit_id }}_
edit-mode: replace
sort-dictionary:
runs-on: ubuntu-latest
if: inputs.sort_dictionary
steps:
- name: "Check out PR branch"
id: checkout-pr-branch
uses: actions/checkout@v4
- name: "Check write permissions"
id: check-write-permissions
env:
GITHUB_TOKEN: ${{ inputs.gh_pat }}
run: |
pr_branch=$(git rev-parse --abbrev-ref HEAD)
# Attempt to push a dummy commit to test write permissions
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
# Try to create a temporary branch and push
branch_name="test-write-permissions-$(date +%s)"
git checkout -b "$branch_name"
git commit --allow-empty -m "Test write permissions"
if git push origin "$branch_name"; then
echo "Successfully pushed to branch - write permissions confirmed"
# Clean up test branch and check the PR branch back out
git push origin --delete "$branch_name"
git checkout "$pr_branch"
exit 0
else
echo "Failed to push - insufficient write permissions"
exit 1
fi
- name: "Sort dictionary file"
id: sort-dictionary
# Only run the sort if we're going to be able to commit the result back
if: steps.check-permissions.outcome == 'success'
env:
GITHUB_TOKEN: ${{ inputs.gh_pat }}
run: |
dictionary_file="resources/dictionary.txt"
tmp_dictionary_file="resources/dictionary.txt.sorted"
pr_branch=$(git rev-parse --abbrev-ref HEAD)
if [ -e dictionary_file ]; then
sort $dictionary_file > $tmp_dictionary_file
diff $dictionary_file $tmp_dictionary_file
if [ $? -ne 0 ]; then
#The files are different, we need to commit
rm $dictionary_file
mv $tmp_dictionary_file $dictionary_file
git add $dictionary_file
git commit -m 'Sort dictionary file'
git pull --rebase --set-upstream origin $pr_branch --allow-unrelated-histories --strategy-option=ours
git push origin $pr_branch
else
echo "No changes in dictionary.txt"
fi
else
echo "Dictionary not found at expected location"
exit 1
fi