-
Notifications
You must be signed in to change notification settings - Fork 16
393 lines (350 loc) · 16.9 KB
/
course.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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
name: "Build Documentation"
on:
push:
paths:
- "scripts/**"
- ".github/workflows/course.yaml"
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-22.04
permissions:
contents: write
id-token: write
steps:
- 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: Fetch public repositories in the organization
run: |
# 起始页
page=1
# 用于保存输出的 JSON 文件
output_file="repos.json"
# 清空输出文件,确保每次运行时是从空文件开始
> "$output_file"
# 循环直到获取所有页面的仓库名
while true; do
# 发起请求,获取当前页的仓库
response=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/orgs/HITSZ-OpenAuto/repos?type=public&per_page=50&page=$page")
# 将响应内容追加到文件中
echo "$response" >> "$output_file"
# 检查响应头中的 Link 是否包含 rel="next",来判断是否有下一页
header=$(curl -s -I -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/orgs/HITSZ-OpenAuto/repos?type=public&per_page=50&page=$page")
set +e
next_page=$(echo -e "$header" | grep -i 'rel="next"')
set -e
echo $next_page
if [ -z "$next_page" ]; then
break
fi
# 如果有下一页,增加页码
page=$((page + 1))
done
echo "All public repositories have been saved to $output_file"
- name: Parse the repo names and save as env vars
id: parse_repos
run: |
repos=$(jq -r '.[].name' repos.json | jq -R -s -c 'split("\n")[:-1]')
echo "repos_array=$repos" >> $GITHUB_ENV
- name: Bulid directory pages
run: |
semester_arr=('fresh-autumn' 'fresh-spring' 'fresh-summer' 'sophomore-autumn' 'sophomore-spring' 'sophomore-summer' 'junior-autumn' 'junior-spring' 'junior-summer' 'senior-autumn' 'senior-spring' 'graduate-autumn' 'graduate-spring' 'cross-specialty' 'general-knowledge')
semester_name=('大一·秋' '大一·春' '大一·夏' '大二·秋' '大二·春' '大二·夏' '大三·秋' '大三·春' '大三·夏' '大四·秋' '大四·春' '研究生·秋' '研究生·春' '跨专业选修' '文理通识与MOOC')
category_arr='mandatory distributional-selective cross-major-selective graduate-course undergraduate-graduate-course selective general-knowledge legacy'
for((i=0;i<${#semester_arr[@]};i++))
do
SEMESTER="${semester_arr[i]}"
OUT="${semester_name[i]}"
echo "Creating a folder for a new semester"
mkdir -p "./content/docs/${SEMESTER}"
echo "./content/docs/${SEMESTER}"
echo '---' > "./content/docs/${SEMESTER}/_index.zh-cn.md"
echo "title: ${OUT}" >> "./content/docs/${SEMESTER}/_index.zh-cn.md"
echo "weight: $((${i}+2))" >> "./content/docs/${SEMESTER}/_index.zh-cn.md"
echo 'comments: false' >> "./content/docs/${SEMESTER}/_index.zh-cn.md"
echo 'toc: false' >> "./content/docs/${SEMESTER}/_index.zh-cn.md"
echo '---' >> "./content/docs/${SEMESTER}/_index.zh-cn.md"
echo "探索以下各节以查找相关资料" >> "./content/docs/${SEMESTER}/_index.zh-cn.md"
for CATEGORY in $category_arr
do
touch "${SEMESTER}-${CATEGORY}.txt"
done
done
# echo "${{ steps.modified_files_list.outputs.stringList }}" > tmp.txt
# cat tmp.txt | grep -E "^-.(([A-Z]){2,4}([0-9]){3}([0-9]|X){1}|MOOC|GeneralKnowledge|CrossSpecialty).*$" | sed -E 's/^..(.*)$/\1/' > repos.txt
# cat repos.txt
- name: Build course pages
run: |
# 建立课程页面
counter_man=0
counter_dis=100
counter_graduate=200
counter_cross=300
counter_general=400
counter_legacy=1000
for line in $(echo '${{ env.repos_array }}' | jq -r '.[]');
do
set +e
echo "$line" | grep -qE '^([A-Z]{2,4}[0-9]{3}([0-9]|X){1}|MOOC|GeneralKnowledge|CrossSpecialty).*$'
if [ $? -eq 1 ]; then
continue
fi
set -e
echo '-------------------------------------------------'
echo ${line}
curl "https://raw.githubusercontent.com/HITSZ-OpenAuto/${line}/main/tag.txt" -o "tag_${line}.txt"
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
echo $semester
CATEGORY=`cat "tag_${line}.txt" | grep -E "^category:..*$" | sed -E 's/^category:.(.*)$/\1/'`
case ${CATEGORY} in
'必修')
category='mandatory'
;;
'限选')
category='distributional-selective'
;;
'研究生阶段课程')
category='graduate-course'
;;
'本研共通')
category='undergraduate-graduate-course'
;;
'选修')
category='selective'
;;
'跨专业选修')
semester='cross-specialty'
category='cross-major-selective'
;;
'文理通识')
semester='general-knowledge'
category='general-knowledge'
;;
'归档')
category='legacy'
;;
*)
echo "No match category"
continue
;;
esac
echo $category
cat "tag_${line}.txt" | grep -E "^name:..*$" | sed -E 's/^name:.(.*)$/\1/' > "name_${line}.txt"
if test ! -s "${semester}-${category}.txt"
then
if [ ${CATEGORY} = "必修" ]
then
echo "## ${CATEGORY}" > "${semester}-${category}.txt"
fi
if [ ${CATEGORY} = "限选" ]
then
echo "## ${CATEGORY}" > "${semester}-${category}.txt"
echo "[限选课选课指南](https://hoa.moe/blog/distributive-guidance-for-22/)" >> "${semester}-${category}.txt"
fi
# if [ ${CATEGORY} = "跨专业选修" ]
# then
# echo "[查看跨专业选修课选课指南](https://hoa.moe/blog/selecting-cross-major-lessons/)" >> "${semester}-${category}.txt"
# fi
if [ ${CATEGORY} = "研究生阶段课程" ]
then
echo "## ${CATEGORY}" > "${semester}-${category}.txt"
echo "此类课程是本科生可跨选的研究生阶段课程。它们也属限选课,但是与专业限选课性质不同,故单独列出。具体请看[研究生阶段课程选课指南](https://hoa.moe/blog/master-phd-course-selection/)。" >> "${semester}-${category}.txt"
fi
if [ ${CATEGORY} = "本研共通" ]
then
echo "## ${CATEGORY}" > "${semester}-${category}.txt"
echo "此类课程是本科生可跨选的研究生阶段课程。它们也属限选课,但是与专业限选课性质不同,故单独列出。具体请看[研究生阶段课程选课指南](https://hoa.moe/blog/master-phd-course-selection/)。" >> "${semester}-${category}.txt"
fi
if [ ${CATEGORY} = "选修" ]
then
echo "## ${CATEGORY}" > "${semester}-${category}.txt"
fi
if [ ${CATEGORY} = "归档" ]
then
echo "## ${CATEGORY}" > "${semester}-${category}.txt"
echo "此类课程在之前的培养方案中处于较重要的地位,但由于培养方案的调整,现在不再开设了。不过,原课程资料仍保留,感兴趣的同学可以自行查阅。" >> "${semester}-${category}.txt"
fi
echo "<!--more-->" >> "${semester}-${category}.txt"
echo "{{< cards >}}" >> "${semester}-${category}.txt"
fi
echo -n "{{< card link=\"${line}\"" | tr [:upper:] [:lower:] >> "${semester}-${category}.txt"
echo "title=\"$(cat "name_${line}.txt")\">}}" >> "${semester}-${category}.txt"
echo '------index.txt-------'
cat "${semester}-${category}.txt"
echo '----------------------'
echo '---' > "./content/docs/${semester}/${line}.md"
echo "title: (${CATEGORY})$(cat "name_${line}.txt")" >> "./content/docs/${semester}/${line}.md"
if [ ${CATEGORY} = "必修" ]
then
counter_man=$((${counter_man}+1));
echo "weight: ${counter_man}" >> "./content/docs/${semester}/${line}.md"
elif [ ${CATEGORY} = "限选" ]
then
counter_dis=$((${counter_dis}+1));
echo "weight: ${counter_dis}" >> "./content/docs/${semester}/${line}.md"
elif [ ${CATEGORY} = "研究生阶段课程" ]
then
counter_graduate=$((${counter_graduate}+1));
echo "weight: ${counter_graduate}" >> "./content/docs/${semester}/${line}.md"
elif [ ${CATEGORY} = "本研共通" ]
then
counter_graduate=$((${counter_graduate}+1));
echo "weight: ${counter_graduate}" >> "./content/docs/${semester}/${line}.md"
elif [ ${CATEGORY} = "选修" ]
then
counter_graduate=$((${counter_graduate}+1));
echo "weight: ${counter_graduate}" >> "./content/docs/${semester}/${line}.md"
elif [ ${CATEGORY} = "跨专业选修" ]
then
counter_cross=$((${counter_cross}+1));
echo "weight: ${counter_cross}" >> "./content/docs/${semester}/${line}.md"
elif [ ${CATEGORY} = "文理通识" ]
then
counter_general=$((${counter_general}+1));
echo "weight: ${counter_general}" >> "./content/docs/${semester}/${line}.md"
elif [ ${CATEGORY} = "归档" ]
then
counter_legacy=$((${counter_legacy}+1));
echo "weight: ${counter_legacy}" >> "./content/docs/${semester}/${line}.md"
fi
echo 'toc: true' >> "./content/docs/${semester}/${line}.md"
echo "editURL: \"https://github.com/HITSZ-OpenAuto/${line}/edit/main/README.md\"" >> "./content/docs/${semester}/${line}.md"
echo "math: true" >> "./content/docs/${semester}/${line}.md"
echo '---' >> "./content/docs/${semester}/${line}.md"
echo >> "./content/docs/${semester}/${line}.md"
python scripts/gen_repo_update_time.py HITSZ-OpenAuto ${line} ${{ secrets.PERSONAL_ACCESS_TOKEN }}
cat result.txt >> "./content/docs/${semester}/${line}.md"
curl "https://raw.githubusercontent.com/HITSZ-OpenAuto/${line}/main/README.md" -o "temp.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"
echo >> "./content/docs/${semester}/${line}.md"
echo "**注意:1.6 0:00 ~ 1.10 23:59 由于 OSA 服务器需要进行磁盘阵列的迁移,校内网盘服务暂时不可用。**" >> "./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"
python scripts/gen_links.py HITSZ-OpenAuto ${line} ${{ secrets.PERSONAL_ACCESS_TOKEN }}
cat result.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"
done
done
- name: Build semester pages
run: |
semester_arr=('fresh-autumn' 'fresh-spring' 'fresh-summer' 'sophomore-autumn' 'sophomore-spring' 'sophomore-summer' 'junior-autumn' 'junior-spring' 'junior-summer' 'senior-autumn' 'senior-spring' 'graduate-autumn' 'graduate-spring' 'cross-specialty' 'general-knowledge')
category_arr='mandatory distributional-selective cross-major-selective graduate-course undergraduate-graduate-course selective general-knowledge legacy'
for((i=0;i<${#semester_arr[@]};i++))
do
SEMESTER="${semester_arr[i]}"
for CATEGORY in $category_arr
do
if test -s "${SEMESTER}-${CATEGORY}.txt"
then
echo "$(cat "${SEMESTER}-${CATEGORY}.txt")" >> "./content/docs/${SEMESTER}/_index.zh-cn.md"
echo "{{< /cards >}}" >> "./content/docs/${SEMESTER}/_index.zh-cn.md"
fi
done
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: Wrap badges
run: |
for file in $(find content/docs -name "*.md")
do
python scripts/wrap_badges.py $file
done
- 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"