Build Single Course Page #33
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 course' | |
required: true | |
default: 'NOT_ASSIGNED' | |
# concurrency: | |
# group: ${{ github.workflow }} | |
# cancel-in-progress: true | |
jobs: | |
build: | |
runs-on: ubuntu-22.04 | |
env: | |
my_dict: >- | |
{ | |
"第一学年秋季": "fresh-autumn", | |
"第一学年春季": "fresh-spring", | |
"第一学年夏季": "fresh-summer", | |
"第二学年秋季": "sophomore-autumn", | |
"第二学年春季": "sophomore-spring", | |
"第二学年夏季": "sophomore-summer", | |
"第三学年秋季": "junior-autumn", | |
"第三学年春季": "junior-spring", | |
"第三学年夏季": "junior-summer", | |
"第四学年秋季": "senior-autumn", | |
"第四学年春季": "senior-spring", | |
"第四学年夏季": "senior-summer" | |
} | |
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} | |
curl -f "https://raw.githubusercontent.com/HITSZ-OpenAuto/${line}/main/tag.txt" | |
if [ $? -ne 0 ]; then | |
echo "Error: tag file not found or connection failed" | |
exit 1 | |
fi | |
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 | |
semester="$(echo '${{ env.my_dict }}' | jq -r '."${match_semester}"')" | |
if [ -z "$semester" ]; then | |
continue | |
else | |
echo $semester | |
fi | |
curl -f "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"}' | |
exit 1 | |
fi | |
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.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 | |
semester="$(echo '${{ env.my_dict }}' | jq -r '."${match_semester}"')" | |
if [ -z "$semester" ]; then | |
continue | |
else | |
echo $semester | |
fi | |
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 result_links.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" | |
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: 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" |