Skip to content

Commit 084f589

Browse files
authored
Merge pull request #27 from Coding-Club-Lab-Lyon/fixing-ci-shit-show
Fixing ci shit show
2 parents 21d1160 + 62da2d9 commit 084f589

83 files changed

Lines changed: 112 additions & 303 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/parse.yml

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,40 @@ name: Parser
22

33
on:
44
workflow_dispatch: # allows manual triggering
5-
schedule:
6-
- cron: '0 12 * * 0' # runs at 12:00 on Sunday
5+
push:
6+
branches:
7+
- main
78

89
jobs:
9-
parse_files:
10+
parse_directories:
1011
runs-on: ubuntu-latest
1112
steps:
12-
- uses: actions/checkout@v2
13-
with:
14-
fetch-depth: 0
15-
- name: Get new commits
16-
id: commits
17-
run: echo "NEW_COMMIT_COUNT=$(git log --oneline --since '24 hours ago' | wc -l)" >> "$GITHUB_OUTPUT"
13+
- uses: actions/checkout@v4
1814
- name : "Install Python dependencies"
19-
if: ${{ steps.commits.outputs.NEW_COMMIT_COUNT > 0 || github.event_name == 'workflow_dispatch'}}
20-
run : pip install Markdown reportlab selenium weasyprint==53.0 PyPDF2
15+
run : pip install -r .github/workflows/parser/requirements.txt
2116
- name: "Parse markdown subjects"
22-
if: ${{ steps.commits.outputs.NEW_COMMIT_COUNT > 0 || github.event_name == 'workflow_dispatch'}}
2317
run: |
24-
for file in $(ls -d */)
18+
set -e
19+
cd .github/workflows/parser
20+
subjects=$(ls -d ../../../*/)
21+
for directory in ${subjects}
2522
do
26-
if [ ! -d "$file/subject" ]; then
27-
echo "::error file=$file,title="No subject folder."::$file"
28-
continue
29-
fi
30-
if [ ! -f "$file/subject/data.txt" ]; then
31-
echo "::error file=$file/subject,title="No subject data.txt."::$file/subject"
32-
continue
33-
fi
34-
data=$(cat $file/subject/data.txt)
35-
stable=$(echo "$data" | cut -d$'\n' -f4)
36-
if [ "$stable" = "stable" ]; then
37-
echo "::notice file=$file/mouli/data.txt,title="Marked as stable"::$file/mouli/data.txt"
23+
if [ ! -d "$directory/subject" ]; then
24+
echo "::error directory=$directory,title="No subject folder"::$directory"
3825
continue
3926
fi
40-
title=$(echo "$data" | cut -d$'\n' -f1)
41-
if [ -z "$title" ]; then
42-
echo "::error file=$file/subject/data.txt,title="No title."::$file/subject/data.txt"
27+
md=$(find "$directory/subject" "$directory/Subject" -name "*.md" -type f 2>/dev/null | head -n1)
28+
if [ ! -f "$md" ]; then
29+
echo "::error directory=$directory/subject,title="No markdown found"::$directory/subject"
4330
continue
4431
fi
45-
version=$(echo "$data" | cut -d$'\n' -f2)
46-
if [ -z "$version" ]; then
47-
echo "::error file=$file/subject/data.txt,title="No version."::$file/subject/data.txt"
48-
continue
49-
fi
50-
campus=$(echo "$data" | cut -d$'\n' -f3)
51-
if [ -z "$campus" ]; then
52-
echo "::error file=$file/subject/data.txt,title="No campus."::$file/subject/data.txt"
53-
continue
54-
fi
55-
md=$(ls $file/subject/*.md | head -n1)
56-
if [ -z "$md" ]; then
57-
echo "::error file=$file/subject,title="No markdown file."::$file/subject"
58-
continue
32+
# This will write the pdf in $directory. Meaning in the parent directory of the markdown file.
33+
python3 cc_subjects.py "$md"
34+
if [ $? -ne 0 ]; then
35+
echo "::error directory=$directory/subject,title="Conversion failed"::$directory/subject"
5936
fi
60-
cd .github/workflows/parser && python3 cc_subjects.py "../../../$md" "$title" "$version" "$campus" && cd ../../..
6137
done
6238
- uses: EndBug/add-and-commit@v9
63-
if: ${{ steps.commits.outputs.NEW_COMMIT_COUNT > 0 || github.event_name == 'workflow_dispatch'}}
6439
with:
6540
add: "-- . ':!.github'"
6641
default_author: github_actions

.github/workflows/parser/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# How To Use Manually
2+
3+
This script is triggered on push to main in the github actions.
4+
It converts markdown files to cobra pdf subjects.
5+
6+
## Virtual env
7+
8+
First, cd your way to the script's directory
9+
10+
```bash
11+
cd .github/workflows/parser
12+
```
13+
14+
I strongly suggest making a virtual env for ease of use.
15+
16+
```bash
17+
python3 -m venv venv
18+
source venv/bin/activate
19+
```
20+
21+
## Install dependencies
22+
23+
```bash
24+
pip install -r requirements.txt
25+
```
26+
27+
## Running
28+
29+
You only need to give it the path of the markdown file you want to convert.
30+
*No more title, version, campus bullshit. erm.*
31+
32+
```bash
33+
python3 cc_subjects.py <PATH-TO-MD>
34+
```
35+
36+
Important note. The pdf will be generated in the parent directory of the markdown file. Exemple:
37+
38+
```
39+
├── nom_du_sujet
40+
│ ├── Sujet.pdf // Généré
41+
│ └── subject
42+
│ └── sujet.md
43+
44+
```

.github/workflows/parser/builder/src/report.css

Lines changed: 10 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -64,139 +64,20 @@
6464
}
6565

6666
@font-face {
67-
font-family: "FontAwesome";
68-
font-display: block;
69-
src: url(fontawesome/solid/pro-fa-solid-900-1.ttf);
70-
unicode-range: u+f000, u+f002, u+f00e, u+f010, u+f03b, u+f076, u+f0f4, u+f222-f224, u+f227, u+f229-f22c, u+f249, u+f276, u+f279
71-
}
72-
73-
@font-face {
74-
font-family: "FontAwesome";
75-
font-display: block;
76-
src: url(fontawesome/solid/pro-fa-solid-900-2.ttf);
77-
unicode-range: u+f001, u+f004-f005, u+f007, u+f00c, u+f011-f012, u+f015, u+f019, u+f023-f024, u+f02c-f02d, u+f02f-f031, u+f03a, u+f03d, u+f040, u+f04a-f04e, u+f060-f064, u+f067-f068, u+f06b-f06d, u+f072, u+f075, u+f077, u+f07b, u+f084, u+f091, u+f093, u+f095, u+f0ad, u+f0b0, u+f0c0-f0c2, u+f0c8-f0c9, u+f0cc, u+f0ce, u+f0d1, u+f0d7, u+f0dc, u+f0e0, u+f0e8, u+f0f3, u+f106, u+f108-f109, u+f10e, u+f110-f111, u+f11e, u+f121, u+f128-f12a, u+f132, u+f135, u+f145, u+f15b, u+f188, u+f1ab, u+f1ad, u+f1bb, u+f1c0, u+f1d8, u+f1e4, u+f1eb, u+f205, u+f217, u+f21a, u+f21c-f21d, u+f233, u+f238, u+f251, u+f283, u+f292, u+f29e, u+f2a0, u+f2a7, u+f2bb, u+f2cc, u+f2db
78-
}
79-
80-
@font-face {
81-
font-family: "FontAwesome";
82-
font-display: block;
83-
src: url(fontawesome/solid/pro-fa-solid-900-3.ttf);
84-
unicode-range: u+f008, u+f018, u+f01c, u+f025, u+f02a, u+f02e, u+f05b, u+f078, u+f086, u+f09c, u+f0a3, u+f0b1, u+f0c6, u+f0e7, u+f112, u+f126, u+f12c-f12e, u+f130-f131, u+f13d, u+f140, u+f155, u+f164, u+f1ae, u+f1b2, u+f1b8, u+f1ce, u+f1dc, u+f1e5-f1e6, u+f1ec, u+f21b, u+f22d, u+f234, u+f246, u+f275, u+f295, u+f2cd
85-
}
86-
87-
@font-face {
88-
font-family: "FontAwesome";
89-
font-display: block;
90-
src: url(fontawesome/solid/pro-fa-solid-900-4.ttf);
91-
unicode-range: u+f009-f00b, u+f02b, u+f034-f035, u+f071, u+f08d, u+f0db, u+f0f9, u+f120, u+f12b, u+f165, u+f1ba, u+f204, u+f225, u+f239, u+f25c, u+f26c, u+f2c7-f2cb
92-
}
93-
94-
@font-face {
95-
font-family: "FontAwesome";
96-
font-display: block;
97-
src: url(fontawesome/solid/pro-fa-solid-900-5.ttf);
98-
unicode-range: u+f00d, u+f026-f028, u+f0cd, u+f0e9, u+f0f0, u+f0f5, u+f157, u+f159, u+f193, u+f221, u+f226, u+f228, u+f235, u+f29a, u+f2d1
99-
}
100-
101-
@font-face {
102-
font-family: "FontAwesome";
103-
font-display: block;
104-
src: url(fontawesome/solid/pro-fa-solid-900-6.ttf);
105-
unicode-range: u+f013, u+f050-f051, u+f085, u+f0e3, u+f11b, u+f19d, u+f21e, u+f2a3
106-
}
107-
108-
@font-face {
109-
font-family: "FontAwesome";
110-
font-display: block;
111-
src: url(fontawesome/solid/pro-fa-solid-900-7.ttf);
112-
unicode-range: u+f01e, u+f021, u+f036-f039, u+f048-f049, u+f05e, u+f069, u+f0e2, u+f100-f105, u+f107, u+f15d, u+f162, u+f1fa, u+f245, u+f290, u+f2b9
113-
}
114-
115-
@font-face {
116-
font-family: "FontAwesome";
117-
font-display: block;
118-
src: url(fontawesome/solid/pro-fa-solid-900-8.ttf);
119-
unicode-range: u+f029, u+f045, u+f074, u+f079, u+f09e, u+f0c4, u+f10d, u+f122, u+f14d, u+f158, u+f197, u+f1e0, u+f20b, u+f24e
120-
}
121-
122-
@font-face {
123-
font-family: "FontAwesome";
124-
font-display: block;
125-
src: url(fontawesome/solid/pro-fa-solid-900-9.ttf);
126-
unicode-range: u+f032, u+f0a1, u+f0fc, u+f187, u+f19c, u+f1e2, u+f1f6, u+f206-f207, u+f236, u+f240-f244, u+f291, u+f2a1
127-
}
128-
129-
@font-face {
130-
font-family: "FontAwesome";
131-
font-display: block;
132-
src: url(fontawesome/solid/pro-fa-solid-900-10.ttf);
133-
unicode-range: u+f033, u+f03c, u+f0ca-f0cb, u+f0fb, u+f124, u+f127, u+f1cd, u+f253-f254, u+f2c2
134-
}
135-
136-
@font-face {
137-
font-family: "FontAwesome";
138-
font-display: block;
139-
src: url(fontawesome/solid/pro-fa-solid-900-11.ttf);
140-
unicode-range: u+f042, u+f055-f057, u+f059-f05a, u+f06a, u+f0ed-f0ee, u+f144, u+f1da, u+f28b, u+f28d, u+f2bd
141-
}
142-
143-
@font-face {
144-
font-family: "FontAwesome";
145-
font-display: block;
146-
src: url(fontawesome/solid/pro-fa-solid-900-12.ttf);
147-
unicode-range: u+f043, u+f052, u+f125, u+f141-f142, u+f153, u+f1b3, u+f1fb, u+f2a2, u+f2a4, u+f2a8, u+f2b6
148-
}
149-
150-
@font-face {
151-
font-family: "FontAwesome";
152-
font-display: block;
153-
src: url(fontawesome/solid/pro-fa-solid-900-13.ttf);
154-
unicode-range: u+f053-f054, u+f058, u+f073, u+f07a, u+f083, u+f0a8-f0ab, u+f0d8-f0da, u+f137-f13a, u+f1b9, u+f1fd-f1fe, u+f200-f201, u+f218
155-
}
156-
157-
@font-face {
158-
font-family: "FontAwesome";
159-
font-display: block;
160-
src: url(fontawesome/solid/pro-fa-solid-900-14.ttf);
161-
unicode-range: u+f07c, u+f0c3, u+f134, u+f15c, u+f1ac
162-
}
163-
164-
@font-face {
165-
font-family: "FontAwesome";
166-
font-display: block;
167-
src: url(fontawesome/solid/pro-fa-solid-900-15.ttf);
168-
unicode-range: u+f089, u+f098, u+f0dd-f0de, u+f0f1-f0f2, u+f0fa, u+f0fd-f0fe, u+f143, u+f146, u+f14a-f14b, u+f154, u+f199, u+f1b1, u+f1de, u+f1e1, u+f277, u+f2d3
169-
}
170-
171-
@font-face {
172-
font-family: "FontAwesome";
173-
font-display: block;
174-
src: url(fontawesome/solid/pro-fa-solid-900-16.ttf);
175-
unicode-range: u+f0ea, u+f182-f183, u+f1b0, u+f1dd, u+f1fc, u+f29d, u+f2ce
176-
}
177-
178-
@font-face {
179-
font-family: "FontAwesome";
180-
font-display: block;
181-
src: url(fontawesome/brand/pro-fa-brands-400-1.ttf);
182-
unicode-range: u+f081-f082, u+f08c, u+f099, u+f09b, u+f0d2-f0d3, u+f13b, u+f166-f167, u+f16a-f16d, u+f179-f17c, u+f17e, u+f18c, u+f19a-f19b, u+f1a0, u+f1b4, u+f1bc, u+f1be, u+f1e8, u+f1ed, u+f1f0-f1f1, u+f20e, u+f210, u+f213-f214, u+f230, u+f232, u+f23a, u+f26b, u+f270, u+f288, u+f299, u+f29b, u+f2a6, u+f2b0, u+f2c5-f2c6, u+f2e0
67+
font-family: "FontAwesome";
68+
src: url("fontawesome/solid/pro-fa-solid-900.ttf") format("truetype");
69+
font-weight: normal;
70+
font-style: normal;
18371
}
18472

18573
@font-face {
186-
font-family: "FontAwesome";
187-
font-display: block;
188-
src: url(fontawesome/brand/pro-fa-brands-400-2.ttf);
189-
unicode-range: u+f092, u+f0d4-f0d5, u+f113, u+f13c, u+f15a, u+f16e, u+f170-f172, u+f17d, u+f180, u+f184, u+f1a5-f1a6, u+f1a9-f1aa, u+f1b5, u+f1bd, u+f1cb-f1cc, u+f1d1-f1d4, u+f1ee, u+f1f2-f1f5, u+f208-f209, u+f20d, u+f211, u+f23e, u+f24b-f24c, u+f25e, u+f260-f261, u+f265, u+f268-f269, u+f26d-f26e, u+f27c, u+f27e, u+f280, u+f282, u+f284, u+f286, u+f293-f294, u+f296, u+f2a5, u+f2b3-f2b4, u+f2d5-f2d8
74+
font-family: "FontAwesome";
75+
src: url("fontawesome/brand/pro-fa-brands-400.ttf")
76+
format("truetype");
77+
font-weight: normal;
78+
font-style: normal;
19079
}
19180

192-
@font-face {
193-
font-family: "FontAwesome";
194-
font-display: block;
195-
src: url(fontawesome/brand/pro-fa-brands-400-3.ttf);
196-
unicode-range: u+f0e1, u+f136, u+f168-f169, u+f173-f174, u+f181, u+f189-f18b, u+f18d, u+f194, u+f198, u+f19e, u+f1a1-f1a4, u+f1a7-f1a8, u+f1b6-f1b7, u+f1ca, u+f1d0, u+f1d5-f1d7, u+f1e7, u+f1e9, u+f202-f203, u+f212, u+f215-f216, u+f231, u+f237, u+f23b-f23d, u+f263-f264, u+f266-f267, u+f26a, u+f27d, u+f281, u+f285, u+f287, u+f289-f28a, u+f297-f298, u+f2a9-f2ae, u+f2b1-f2b2, u+f2b8, u+f2c4, u+f2d9-f2da, u+f2dd-f2de
197-
}
198-
199-
20081
@page :blank {
20182
@top-left {
20283
background: none;
@@ -402,4 +283,4 @@ pagebreak {
402283
hr {
403284
border: 1px solid #c5c5c5;
404285
border-width: 1px 0 0 0;
405-
}
286+
}

.github/workflows/parser/cc_subjects.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python3
2-
from compileall import compile_path
32
import io
43
import os
54
import markdown
@@ -18,24 +17,22 @@
1817
from weasyprint import HTML
1918
from PyPDF2 import PdfWriter, PdfReader, PdfMerger
2019

21-
if len(sys.argv) < 4:
22-
print("Usage: python3 cc_subjects.py <file> <title> <version> <campus>")
20+
if len(sys.argv) < 2:
21+
print("Usage: python3 cc_subjects.py <file>")
2322
exit(1)
2423

2524
compile_file = sys.argv[1]
25+
project_title = compile_file.replace("_", " ").split("/")[-1].removesuffix(".md").capitalize()
2626
export_dir = "/".join(compile_file.split("/")[:-1])
27-
project_title = sys.argv[2]
28-
project_version = sys.argv[3][:10]
29-
project_campus = sys.argv[4]
3027

3128

32-
def str_to_snake_case(str):
33-
str = str.title().replace(" ", "-")
34-
str = re.sub('([^\w-])', '_', str)
35-
str = re.sub('^_', '', str)
36-
str = re.sub('_$', '', str)
37-
str = re.sub('_+', '_', str)
38-
return str
29+
def str_to_snake_case(string):
30+
string = string.title().replace(" ", "-")
31+
string = re.sub(r"([^\w-])", "_", string)
32+
string = re.sub(r"^_", "", string)
33+
string = re.sub(r"_$", "", string)
34+
string = re.sub(r"_+", "_", string)
35+
return string
3936

4037

4138
# Check directory
@@ -57,7 +54,7 @@ def custom_commands(html):
5754
html = html.replace("\\!", "\a")
5855
replacements = [
5956
("!pagebreak", "<pagebreak>"),
60-
("!icon:([\w-]+)", replace_font_awesome),
57+
(r"!icon:([\w-]+)", replace_font_awesome),
6158
("<blockquote>\n<p>:(info|success|warning|danger)",
6259
"<blockquote class=\"\\1\">\n<p>"),
6360
]
@@ -87,17 +84,12 @@ def custom_commands(html):
8784
width = stringWidth(text, "Roboto", 50)
8885
can.drawString(535 - width, 390 + i * 55, text)
8986

90-
text = "© Coding Club " + project_campus.capitalize()
87+
text = "© Coding Club Lyon"
9188
can.setFillColor(HexColor('#4B526F'))
9289
can.setFont("FiraSans-Regular", 10)
9390
width = stringWidth(text, "FiraSans-Regular", 10)
9491
can.drawString(23, 32, text)
9592

96-
text = "VERSION " + project_version
97-
can.setFillColor(HexColor('#8288A8'))
98-
can.setFont("Roboto", 17)
99-
width = stringWidth(text, "Roboto", 17)
100-
can.drawString(535 - width, 335, text)
10193
can.save()
10294
packet.seek(0)
10395

@@ -149,13 +141,20 @@ def custom_commands(html):
149141
elem = driver.find_element(By.XPATH, "//*")
150142
interpreted_html = elem.get_attribute("outerHTML")
151143

144+
if interpreted_html is None:
145+
print("Interpretation failed.")
146+
exit(1)
147+
152148
with open(html_file_name, "w") as html_out_file:
153149
html_out_file.write(interpreted_html)
154150

155151
# Create final PDF file
156152
print("Exporting PDF...")
157153
pdf = HTML(html_file_name).write_pdf()
158154
f = open("builder/output.pdf", 'wb')
155+
if pdf is None:
156+
print("PDF output failed.")
157+
exit(1)
159158
f.write(pdf)
160159
f.close()
161160
# Merge 2 pdfs cover and output (output has multiple pages)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Markdown==3.7
2+
PyPDF2==3.0.1
3+
reportlab==4.2.2
4+
selenium==4.30.0
5+
weasyprint==65.1

Asteroids/Asteroids.pdf

-22.6 KB
Binary file not shown.

Asteroids/subject/data.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

BSQ/Bsq.pdf

-16 KB
Binary file not shown.

BSQ/subject/data.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

CpoolDay/Cpoolday.pdf

-20 KB
Binary file not shown.

0 commit comments

Comments
 (0)