-
Notifications
You must be signed in to change notification settings - Fork 13
312 lines (279 loc) · 12.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
name: "Build Documentation"
on:
push:
paths:
- "scripts/**"
- ".github/workflows/course.yaml"
schedule:
- cron: "0 16 */2 * *"
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: Get all repositories in the organization
uses: austenstone/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
org: "HITSZ-OpenAuto"
delimiter: "\n"
id: get-org-repos
- name: Turn to array
id: modified_files_list
uses: lucaspinheirogit/[email protected]
with:
stringArray: ${{ steps.get-org-repos.outputs.repos }}
- name: Bulid directory
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' 'cross-specialty' 'general-knowledge')
semester_name=('大一·秋' '大一·春' '大一·夏' '大二·秋' '大二·春' '大二·夏' '大三·秋' '大三·春' '大三·夏' '大四·秋' '大四·春' '跨专业选修' '文理通识与MOOC')
category_arr='mandatory distributional-selective cross-major-selective general-knowledge graduate-course 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).*$" | 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 $(cat repos.txt)
do
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'
;;
*)
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'
;;
'跨专业选修')
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 "此类课程是本科生可跨选的研究生阶段课程。它们也属限选课,但是与专业限选课性质不同,故单独列出。具体请看研究生阶段课程选课指南(尚未完成)。" >> "${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_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"
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"
echo "如果你是校内学生,可移步至 <a href='https://open.osa.moe/openauto/${line}'>open.osa.moe</a> 查看本门课程的电子书、课件和实验软件等。" >> "./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' 'cross-specialty' 'general-knowledge')
category_arr='mandatory distributional-selective cross-major-selective graduate-course 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: Wrap badges
run: |
sh wrap.sh
- name: AutoCorrect
uses: huacnlee/autocorrect-action@v2
with:
args: --fix
- name: Commit and push changes
uses: EndBug/add-and-commit@v9
with:
add: "content"
default_author: github_actions
message: "ci: update course pages"