-
Notifications
You must be signed in to change notification settings - Fork 15
284 lines (252 loc) · 9.4 KB
/
course-single.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
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
name: "Build Single Course Page"
on:
workflow_dispatch:
inputs:
repo_name:
description: 'Name of the repository'
required: true
default: 'NOT_ASSIGNED'
# concurrency:
# group: ${{ github.workflow }}
# cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-22.04
permissions:
contents: write
id-token: write
steps:
- name: Get parameters
id: extract
run: |
REPO="${{ github.event.inputs.repo_name }}"
if [ -z "$REPO" ]; then
REPO="NOT_ASSIGNED"
fi
echo "repo_name=$REPO" >> "$GITHUB_OUTPUT"
- name: First check
run: |
echo 'First check: file existence'
line="${{ steps.extract.outputs.repo_name }}"
echo '-------------------------------------------------'
echo ${line}
set +e
curl "https://raw.githubusercontent.com/HITSZ-OpenAuto/${line}/main/tag.txt" -o "tag_${line}.txt"
if [ $? -ne 0 ]; then
echo "Error: tag file not found or connection failed"
set -e
exit 1
fi
set -e
echo " "
echo '-----tag.txt-----'
cat "tag_${line}.txt"
echo " "
echo '-----------------'
Semesters=`cat "tag_${line}.txt" | grep -E "^semester:..*$"`
Semesters=${Semesters#*: }
echo ${Semesters}
IFS=' / ' read -r -a semesters <<< "$Semesters"
for match_semester in "${semesters[@]}"
do
case ${match_semester} in
'第一学年秋季')
semester='fresh-autumn'
;;
'第一学年春季')
semester='fresh-spring'
;;
'第一学年夏季')
semester='fresh-summer'
;;
'第二学年秋季')
semester='sophomore-autumn'
;;
'第二学年春季')
semester='sophomore-spring'
;;
'第二学年夏季')
semester='sophomore-summer'
;;
'第三学年秋季')
semester='junior-autumn'
;;
'第三学年春季')
semester='junior-spring'
;;
'第三学年夏季')
semester='junior-summer'
;;
'第四学年秋季')
semester='senior-autumn'
;;
'第四学年春季')
semester='senior-spring'
;;
'研究生秋季')
semester='graduate-autumn'
;;
'研究生春季')
semester='graduate-spring'
;;
*)
echo "No match semester"
continue
;;
esac
CATEGORY=`cat "tag_${line}.txt" | grep -E "^category:..*$" | sed -E 's/^category:.(.*)$/\1/'`
# 针对文理通识和跨专业选修做的适配
case ${CATEGORY} in
'跨专业选修')
semester='cross-specialty'
;;
'文理通识')
semester='general-knowledge'
;;
*)
echo "No match special categories"
;;
esac
echo $semester
# Ensure the if statement can be executed
set +e
curl -sf -o /dev/null "https://raw.githubusercontent.com/HITSZ-OpenAuto/hoa-moe/main/content/docs/${semester}/${line}.md"
if [ $? -ne 0 ]; then
echo "Error: Course pages have not been created yet. "
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.PERSONAL_ACCESS_TOKEN }}" \
https://api.github.com/repos/HITSZ-OpenAuto/hoa-moe/actions/workflows/course.yaml/dispatches \
-d '{"ref":"main"}'
set -e
exit 1
fi
set -e
done
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install Python dependencies
run: pip install -r scripts/requirements.txt
- name: Build single course page
run: |
echo 'Checked. Start building.'
line="${{ steps.extract.outputs.repo_name }}"
first_time=1
curl "https://raw.githubusercontent.com/HITSZ-OpenAuto/${line}/main/tag.txt" -o "tag_${line}.txt"
curl "https://raw.githubusercontent.com/HITSZ-OpenAuto/${line}/main/README.md" -o "temp.md"
python scripts/gen_repo_update_time.py HITSZ-OpenAuto ${line} ${{ secrets.PERSONAL_ACCESS_TOKEN }}
cp result_update_time.txt result_time.txt
python scripts/gen_links.py HITSZ-OpenAuto ${line} ${{ secrets.PERSONAL_ACCESS_TOKEN }}
cp result.txt result_links.txt
Semesters=`cat "tag_${line}.txt" | grep -E "^semester:..*$"`
Semesters=${Semesters#*: }
IFS=' / ' read -r -a semesters <<< "$Semesters"
for match_semester in "${semesters[@]}"
do
case ${match_semester} in
'第一学年秋季')
semester='fresh-autumn'
;;
'第一学年春季')
semester='fresh-spring'
;;
'第一学年夏季')
semester='fresh-summer'
;;
'第二学年秋季')
semester='sophomore-autumn'
;;
'第二学年春季')
semester='sophomore-spring'
;;
'第二学年夏季')
semester='sophomore-summer'
;;
'第三学年秋季')
semester='junior-autumn'
;;
'第三学年春季')
semester='junior-spring'
;;
'第三学年夏季')
semester='junior-summer'
;;
'第四学年秋季')
semester='senior-autumn'
;;
'第四学年春季')
semester='senior-spring'
;;
'研究生秋季')
semester='graduate-autumn'
;;
'研究生春季')
semester='graduate-spring'
;;
*)
echo "No match semester"
continue
;;
esac
CATEGORY=`cat "tag_${line}.txt" | grep -E "^category:..*$" | sed -E 's/^category:.(.*)$/\1/'`
# 针对文理通识和跨专业选修做的适配
case ${CATEGORY} in
'跨专业选修')
semester='cross-specialty'
;;
'文理通识')
semester='general-knowledge'
;;
*)
echo "No match special categories"
;;
esac
if [ "$first_time" -eq 1 ]; then
curl "https://raw.githubusercontent.com/HITSZ-OpenAuto/hoa-moe/main/content/docs/${semester}/${line}.md" -o "temp1.md"
first_time=0
fi
head -n 7 "temp1.md" > "./content/docs/${semester}/${line}.md"
echo >> "./content/docs/${semester}/${line}.md"
cat result_time.txt >> "./content/docs/${semester}/${line}.md"
tail -n +2 "temp.md" >> "./content/docs/${semester}/${line}.md"
echo >> "./content/docs/${semester}/${line}.md"
echo "## 资料下载" >> "./content/docs/${semester}/${line}.md"
echo >> "./content/docs/${semester}/${line}.md"
cat scripts/netdisk_notice.txt >> "./content/docs/${semester}/${line}.md"
echo >> "./content/docs/${semester}/${line}.md"
cat result_links.txt >> "./content/docs/${semester}/${line}.md"
echo >> "./content/docs/${semester}/${line}.md"
cat scripts/sponsor.txt >> "./content/docs/${semester}/${line}.md"
echo >> "./content/docs/${semester}/${line}.md"
python scripts/wrap_badges.py "content/docs/${semester}/${line}.md"
done
- name: Generate daily report
env:
TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
ORG_NAME: HITSZ-OpenAuto
NEWS_TYPE: daily
run: |
python scripts/gen_news.py
- name: Fetch opened PRs and issues
env:
TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
run: |
python scripts/fetch_opened_prs_and_issues.py
- name: Auto correct
uses: huacnlee/autocorrect-action@v2
with:
args: --fix content/
- name: Commit and push changes
uses: EndBug/add-and-commit@v9
with:
add: "content"
default_author: github_actions
message: "ci: update course pages"