Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

fix, gh: download path #103

fix, gh: download path

fix, gh: download path #103

Workflow file for this run

name: Compile Document and Deploy
permissions:
contents: read
pages: write
id-token: write
on:
push:
branches:
- master
jobs:
build-by-miktex:
name: Build by MiKTeX
runs-on: ubuntu-22.04
if: ${{ !contains(github.event.head_commit.message, '@nobuild') }}
env:
APT_LIST: "" ## Evaluated at runtime
ROOT_FILE: ""
OUTPUT_FILE: ""
SOURCE_HASH: ""
strategy:
matrix:
target: [notes, cheatsheet]
steps:
- name: Checkout repository
uses: actions/checkout@v4
## Configure GPG key
- name: Configure MiKTeX GPG key
run: |
curl -fsSL https://miktex.org/download/key | sudo tee /usr/share/keyrings/miktex-keyring.asc > /dev/null
echo "deb [signed-by=/usr/share/keyrings/miktex-keyring.asc] https://miktex.org/download/ubuntu jammy universe" | sudo tee /etc/apt/sources.list.d/miktex.list
## Prepare the environment
- name: Get dependencies list
run: echo "APT_LIST=$(awk '{$1=$1}1' OFS=' ' RS='' build/apt-list.txt)" >> "$GITHUB_ENV"
- name: Include disclaimer header
run: |
chmod +x ./build/add-disclaimer.sh
./build/add-disclaimer.sh
- name: Get root file
run: echo "ROOT_FILE=`(ls ${{ matrix.target }} | grep -E "COMP2120-.*\.tex")`" >> "$GITHUB_ENV"
- name: Hash all .tex source files
run: echo "SOURCE_HASH=${{ hashFiles(format('./{0}/', matrix.target)) }}" >> "$GITHUB_ENV"
- name: Check for hash changes
id: check-hash
run: |
chmod +x ./build/download-hash.sh
./build/download-hash.sh ${${{ env.ROOT_FILE }}/.tex/.pdf.hash} ${{ env.SOURCE_HASH }}
## Install MiKTeX
- name: Install MiKTeX and dependencies
id: apt-install
if: ${{ steps.check-hash.outputs.changed == 1 }}
uses: awalsh128/cache-apt-pkgs-action@v1
with:
packages: ${{ env.APT_LIST }}
- uses: actions/setup-python@v5
if: ${{ steps.check-hash.outputs.changed == 1 }}
with:
python-version: '3.13'
cache: 'pip'
- name: Install Python packages
if: ${{ steps.check-hash.outputs.changed == 1 }}
run: |
python -m pip install --upgrade pip
pip install -r build/requirements.txt
## Restore LaTeX packages cache if apt was cached
- name: Restore LaTeX packages from cache
id: miktex-cache
if: ${{ steps.apt-install.outputs.cache-hit == 'true' && steps.check-hash.outputs.changed == 1 }}
uses: actions/cache/restore@v4
with:
key: miktex-pkg-${{ runner.os }}-${{ hashFiles(format('./{0}/packages.tex', matrix.target)) }}
path: ~/.miktex
## Finish MiKTeX setup
- name: Finish MiKTeX setup
if: ${{ steps.check-hash.outputs.changed == 1 }}
run: |
miktexsetup finish
initexmf --set-config-value [MPM]AutoInstall=1
initexmf --enable-installer
initexmf --update-fndb
initexmf --mkmaps
miktex packages update
- name: Fix PATH
run: echo "PATH=$HOME/bin:$PATH" >> "$GITHUB_ENV"
## Compile the document
- name: Compile target - ${{ matrix.target }}
id: compile
if: ${{ steps.check-hash.outputs.changed == 1 }}
run: |
latexmk -shell-escape -interaction=nonstopmode -pdf -cd -outdir=. -f ./${{ matrix.target }}/${{ env.ROOT_FILE }}
- name: Download PDF from remote (document was not changed)
id: download-pdf
if: ${{ steps.check-hash.outputs.changed == 0 }}
run: |
curl https://shingzhanho.github.io/COMP2120-Notes/${${{ env.ROOT_FILE }}/.tex/.pdf} --output ./${{ matrix.target }}/${${{ env.ROOT_FILE }}/.tex/.pdf}
## Cache the MiKTeX packages if apt cache or miktex cache did not hit
- name: Cache MiKTeX packages
if: ${{ !(steps.apt-install.outputs.cache-hit == 'true' && steps.miktex-cache.outputs.cache-hit) && steps.check-hash.outputs.changed == 1 }}
uses: actions/cache/save@v4
with:
key: miktex-pkg-${{ runner.os }}-${{ hashFiles(format('./{0}/packages.tex', matrix.target)) }}
path: ~/.miktex
## Upload the artifact
- name: Find output file
run: echo "OUTPUT_FILE=`(ls ${{ matrix.target }} | grep -E "COMP2120-.*\.pdf")`" >> "$GITHUB_ENV"
- name: Write hash to file
run: echo "${{ env.SOURCE_HASH }}" > ${{ matrix.target }}/${{ env.OUTPUT_FILE }}.hash
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: pdf-miktex-${{ matrix.target }}
path: |
${{ matrix.target }}/${{ env.OUTPUT_FILE }}
${{ matrix.target }}/${{ env.OUTPUT_FILE }}.hash
if-no-files-found: error
retention-days: 1
## Upload logs
- name: Upload compile logs
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: logs-miktex-${{ matrix.target }}
path: /home/runner/.miktex/texmfs/data/miktex/log/
retention-days: 14
deploy:
name: Build and deploy static site
runs-on: ubuntu-latest
needs: build-by-miktex
if: ${{ !contains(github.event.head_commit.message, '@nodeploy') }}
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v4
with:
pattern: pdf-miktex-*
path: gh-pages
merge-multiple: true
- name: Upload static files as artifact
uses: actions/upload-pages-artifact@v3
with:
path: gh-pages
- name: Configure pages
uses: actions/configure-pages@v5
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4