Build Single Course Page #171
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |