-
Notifications
You must be signed in to change notification settings - Fork 1
199 lines (174 loc) · 7.78 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
# 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
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: setup
run: |
if ${{ contains(inputs.check_type, 'spelling') }} ;then
echo "error_name=spelling error" >> $GITHUB_OUTPUT
echo "ignore_file=resources/dictionary.txt" >> $GITHUB_OUTPUT
elif ${{ contains(inputs.check_type, 'urls') }} ;then
echo "error_name=broken urls error" >> $GITHUB_OUTPUT
echo "ignore_file=resources/ignore-urls.txt" >> $GITHUB_OUTPUT
elif ${{ contains(inputs.check_type, 'quiz_format') }} ;then
echo "error_name=quiz formatting error" >> $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.setup.outputs.error_name }}
- name: Status update
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.fc1.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
The check: ${{ steps.setup.outputs.error_name }} 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
jobs:
error-check:
runs-on: ubuntu-latest
container:
image: jhudsl/base_ottr:main
steps:
- name: Declare report name
id: setup
run: |
if ${{ contains(inputs.check_type, 'spelling') }} ;then
echo "error_name=spelling error" >> $GITHUB_OUTPUT
echo "ignore_file=resources/dictionary.txt" >> $GITHUB_OUTPUT
elif ${{ contains(inputs.check_type, 'urls') }} ;then
echo "error_name=broken urls error" >> $GITHUB_OUTPUT
echo "ignore_file=resources/ignore-urls.txt" >> $GITHUB_OUTPUT
elif ${{ contains(inputs.check_type, 'quiz_format') }} ;then
echo "error_name=quiz formatting error" >> $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.setup.outputs.error_name }}
- name: Say check is incomplete
if: steps.check_results.outcome == 'failure'
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.fc2.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
:warning: Check: ${{ steps.setup.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
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@v2
with:
comment-id: ${{ steps.fc2.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
:warning: ${{ steps.setup.outputs.error_name }} :warning:
There are ${{ steps.setup.outputs.error_name }} that need to be addressed.
Click here :arrow_right: [for ${{ steps.setup.outputs.error_name }}s!](${{ steps.file-path.outputs.error_url }}) :exclamation:
Add errors that aren't errors to the [${{ steps.setup.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-components.outputs.time }} with changes from ${{ steps.build-components.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@v2
with:
comment-id: ${{ steps.fc2.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
No ${{ steps.setup.outputs.error_name }}s! :tada:
_Comment updated at ${{ steps.build-components.outputs.time }} with changes from ${{ steps.build-components.outputs.commit_id }}_
edit-mode: replace