Formatted and compiled latex files #20
Workflow file for this run
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: "Compile LaTeX Document" | |
on: | |
push: | |
branches: [latex-format-test] | |
paths: | |
- "docs/**/*.tex" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
env: | |
GH_TOKEN: ${{ github.token }} | |
steps: | |
# Cache TeX Live installation | |
- name: Cache TeX Live | |
uses: actions/cache@v4 | |
with: | |
path: | | |
/usr/local/texlive # Adjust to where TeX Live is installed | |
/usr/share/texlive | |
~/.texlive | |
key: texlive-2024-${{ runner.os }}-latexmk | |
restore-keys: | | |
texlive- | |
# Install TeX Live and latexmk if cache is not available | |
- name: Install TeX Live and latexmk | |
if: steps.cache.outputs.cache-hit != 'true' | |
run: | | |
sudo apt-get update | |
sudo apt-get install texlive-latex-extra texlive-science latexmk | |
- name: Create app access token | |
uses: actions/create-github-app-token@v1 | |
id: app-token | |
with: | |
app-id: ${{ vars.SCO_COMMIT_APP }} | |
private-key: ${{ secrets.SCO_APP_KEY }} | |
# Checkout repository | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ steps.app-token.outputs.token }} | |
- name: Install tex-fmt | |
run: | | |
sudo apt install cargo | |
cargo install tex-fmt | |
# Get changed .tex files | |
- name: Get changed .tex files | |
id: changed-tex-files | |
uses: tj-actions/changed-files@v45 | |
with: | |
files: | | |
**/*.tex | |
diff_relative: true # Get the list of files relative to the repo root | |
# Format and Build LaTeX files | |
- name: Format and Build changed tex files | |
if: steps.changed-tex-files.outputs.any_changed == 'true' | |
env: | |
ALL_CHANGED_FILES: ${{ steps.changed-tex-files.outputs.all_changed_files }} | |
run: | | |
for file in ${ALL_CHANGED_FILES}; do | |
tex-fmt "$file" | |
filename=$(basename -- "$file") | |
folder=$(dirname "$file") # Get the folder of the file | |
echo "Building $filename" | |
cd "$folder" # Change to the folder where the tex file is located | |
make | |
make clean | |
cd - # Go back to root folder | |
done | |
git status | |
# Commit the generated PDF and formatted .tex files back to the repository | |
- name: Commit & Push changes | |
env: | |
ALL_CHANGED_FILES: ${{ steps.changed-tex-files.outputs.all_changed_files }} | |
uses: EndBug/add-and-commit@v9 | |
with: | |
add: --force docs/**/*.pdf docs/**/*.tex | |
author_name: "Github Action" | |
author_email: "[email protected]" | |
message: "Formatted and compiled latex files" |