updated workflow to use miktex #131
This file contains hidden or 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 LaTeX PDFs | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| paths: | |
| - '**.tex' | |
| - '**.sty' | |
| - '**.cls' | |
| - '**.py' | |
| - '**.ipynb' | |
| - '**.yml' | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - '**.tex' | |
| - '**.sty' | |
| - '**.cls' | |
| - '**.py' | |
| - '**.ipynb' | |
| - '**.yml' | |
| workflow_dispatch: | |
| jobs: | |
| format-check: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Set up Git repository | |
| uses: actions/checkout@v4 | |
| - name: Initialize and update submodules | |
| run: | | |
| git submodule init | |
| git submodule update | |
| - name: Install MiKTeX latexindent package & Log Version | |
| run: | | |
| set -e | |
| curl -fsSL https://miktex.org/download/key | sudo gpg --dearmor -o /usr/share/keyrings/miktex.gpg | |
| OS_CODENAME=$(lsb_release -cs) | |
| echo "Detected GitHub Runner Ubuntu codename: ${OS_CODENAME}" | |
| echo "deb [arch=amd64 signed-by=/usr/share/keyrings/miktex.gpg] https://miktex.org/download/ubuntu ${OS_CODENAME} universe" | sudo tee /etc/apt/sources.list.d/miktex.list | |
| sudo apt-get update -y -q | |
| sudo apt-get install -qq -y --no-install-recommends miktex | |
| sudo miktexsetup --shared=yes finish | |
| sudo initexmf --admin --set-config-value=[MPM]AutoInstall=1 | |
| sudo mpm --admin --update | |
| sudo mpm --admin --install=latexindent | |
| sudo apt-get install -qq -y perl cpanminus | |
| sudo cpanm --notest YAML::Tiny File::HomeDir Log::Log4perl Log::Dispatch::File Unicode::GCString | |
| echo "==========================================================" | |
| echo "latexindent Version Verification (via MiKTeX):" | |
| echo "Installed path: $(which latexindent)" | |
| latexindent -vv | |
| echo "==========================================================" | |
| - 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 -path "./course_template/*" -not -name "$tmp_file" | while read -r file; do | |
| latexindent -m -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 ./course_template/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 ./course_template/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 ./course_template/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_latex: | |
| needs: format-check | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Set up Git repository | |
| uses: actions/checkout@v4 | |
| - name: Initialize and update submodules | |
| run: | | |
| git submodule init | |
| git submodule update | |
| - name: Compile LaTeX document | |
| uses: xu-cheng/texlive-action@v2 | |
| with: | |
| scheme: full | |
| run: | | |
| cd exercise | |
| cp ../course_template/exerciseClass.cls ./ | |
| python3 build.py | |
| cd .. | |
| cd lecture | |
| cp ../course_template/lectureClass.cls ./ | |
| python3 build.py | |
| cd .. | |
| cd exam | |
| cp ../course_template/examClass.cls ./ | |
| python3 build.py | |
| - name: Upload PDF file | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| name: github-pages | |
| path: built/ | |
| deploy: | |
| needs: build_latex | |
| if: ${{ github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') }} | |
| permissions: | |
| pages: write | |
| id-token: write | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |