This repository was archived by the owner on May 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
157 lines (150 loc) · 5.83 KB
/
Copy pathcompile.yml
File metadata and controls
157 lines (150 loc) · 5.83 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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 }} ${{ 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: |
VAR=${{ env.ROOT_FILE }}
curl https://shingzhanho.github.io/COMP2120-Notes/${VAR/.tex/.pdf} --output ./${{ matrix.target }}/${VAR/.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