[DELIVERABLE 3] Hazard Analysis (#184) #4
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: [main] | |
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 }} | |
# 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 | |
# Build LaTeX files | |
- name: 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 | |
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 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 | |
author_name: "Github Action" | |
author_email: "action@github.com" | |
message: "Add compiled PDF" |