-
Notifications
You must be signed in to change notification settings - Fork 3
66 lines (64 loc) · 2.79 KB
/
parse.yml
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
name: Parser
on:
workflow_dispatch: # allows manual triggering
schedule:
- cron: '0 12 * * 0' # runs at 12:00 on Sunday
jobs:
parse_files:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get new commits
id: commits
run: echo "NEW_COMMIT_COUNT=$(git log --oneline --since '24 hours ago' | wc -l)" >> "$GITHUB_OUTPUT"
- name : "Install Python dependencies"
if: ${{ steps.commits.outputs.NEW_COMMIT_COUNT > 0 || github.event_name == 'workflow_dispatch'}}
run : pip install Markdown reportlab selenium weasyprint==53.0 PyPDF2
- name: "Parse markdown subjects"
if: ${{ steps.commits.outputs.NEW_COMMIT_COUNT > 0 || github.event_name == 'workflow_dispatch'}}
run: |
for file in $(ls -d */)
do
if [ ! -d "$file/subject" ]; then
echo "::error file=$file,title="No subject folder."::$file"
continue
fi
if [ ! -f "$file/subject/data.txt" ]; then
echo "::error file=$file/subject,title="No subject data.txt."::$file/subject"
continue
fi
data=$(cat $file/subject/data.txt)
stable=$(echo "$data" | cut -d$'\n' -f4)
if [ "$stable" = "stable" ]; then
echo "::notice file=$file/mouli/data.txt,title="Marked as stable"::$file/mouli/data.txt"
continue
fi
title=$(echo "$data" | cut -d$'\n' -f1)
if [ -z "$title" ]; then
echo "::error file=$file/subject/data.txt,title="No title."::$file/subject/data.txt"
continue
fi
version=$(echo "$data" | cut -d$'\n' -f2)
if [ -z "$version" ]; then
echo "::error file=$file/subject/data.txt,title="No version."::$file/subject/data.txt"
continue
fi
campus=$(echo "$data" | cut -d$'\n' -f3)
if [ -z "$campus" ]; then
echo "::error file=$file/subject/data.txt,title="No campus."::$file/subject/data.txt"
continue
fi
md=$(ls $file/subject/*.md | head -n1)
if [ -z "$md" ]; then
echo "::error file=$file/subject,title="No markdown file."::$file/subject"
continue
fi
cd .github/workflows/parser && python3 cc_subjects.py "../../../$md" "$title" "$version" "$campus" && cd ../../..
done
- uses: EndBug/add-and-commit@v9
if: ${{ steps.commits.outputs.NEW_COMMIT_COUNT > 0 || github.event_name == 'workflow_dispatch'}}
with:
add: "-- . ':!.github'"
default_author: github_actions