-
Notifications
You must be signed in to change notification settings - Fork 1
103 lines (91 loc) · 3.42 KB
/
latex-python-ci.yml
File metadata and controls
103 lines (91 loc) · 3.42 KB
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
name: LaTeX + Python CI
on:
pull_request:
branches:
- main
jobs:
format-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install latexindent binary
run: |
set -e
curl -L -o latexindent-linux \
https://github.com/cmhughes/latexindent.pl/releases/latest/download/latexindent-linux
chmod +x latexindent-linux
sudo mv latexindent-linux /usr/local/bin/latexindent
echo "latexindent installed at:"
which latexindent || echo "latexindent not found on PATH"
echo "latexindent verbose version info:"
latexindent -vv
- name: Check LaTeX formatting with latexindent (dry-run)
run: |
set -e
tmp_file="tmp_check_file"
for ext in tex sty cls; do
find . -name "*.${ext}" -type f -not -name "$tmp_file" | while read -r file; do
latexindent -m -l=.latexindent.yml -o="$tmp_file" "$file"
if ! diff -qZb "$file" "$tmp_file.${ext}" > /dev/null; then
echo "::error file=$file::File is not properly formatted. Please run latexindent locally."
rm -f "$tmp_file.${ext}"
exit 1
fi
rm -f "$tmp_file.${ext}"
done || exit 1
done
echo "All LaTeX files are properly formatted!"
- name: Install Python format tools
run: |
set -e
python -m pip install --upgrade pip
pip install ruff
- name: Check Python + Notebook formatting (Ruff)
run: |
set -e
echo "Checking .py files formatting..."
PY_FAILED=0
for file in $(find . -name "*.py" -not -path "*/.*"); do
if ! ruff format --check --config ./pyproject.toml "$file"; then
echo "::error file=$file::Formatting check failed for $file."
PY_FAILED=1
fi
done
echo "Checking .ipynb files formatting..."
NB_FAILED=0
for file in $(find . -name "*.ipynb" -not -path "*/.*"); do
if ! ruff format --check --config ./pyproject.toml "$file"; then
echo "::error file=$file::Formatting check failed for $file."
echo "TIP: There is likely a trailing newline at the end of a code cell."
ruff format --diff --config ./pyproject.toml "$file"
NB_FAILED=1
fi
done
if [ $PY_FAILED -ne 0 ] || [ $NB_FAILED -ne 0 ]; then
echo "Formatting check failed. You can check by running 'ruff format .' locally."
exit 1
fi
echo "All files passed formatting!"
build:
needs: format-check
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
tex:
- test/testLecture.tex
- test/testExercise.tex
- test/testExam.tex
steps:
- uses: actions/checkout@v4
- name: Submodule-like setup
run: |
mkdir -p ../course_template
rsync -av --exclude='.git' . ../course_template/
mkdir -p ../../course_template
ln -s "$PWD/theme" ../../course_template/theme || true
ln -s "$PWD/style" ../../course_template/style || true
- uses: xu-cheng/latex-action@v3
with:
root_file: ${{ matrix.tex }}
args: -pdf -interaction=nonstopmode -halt-on-error -shell-escape