-
Notifications
You must be signed in to change notification settings - Fork 30
72 lines (64 loc) · 2.69 KB
/
render-diagrams.yml
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
name: Update PDF, PNG and SVG assets for changed TeX files
on:
pull_request:
branches: [main]
paths: [assets/**/*.tex]
jobs:
update-assets:
name: Update assets
runs-on: ubuntu-latest
# don't run on forks and only if PR was opened from branch on this repo
if: github.repository_owner == 'janosh' && github.event.pull_request.head.repo.fork == false
steps:
- name: Check out repo
uses: actions/checkout@v4
with:
# get full history to include BASE_REF commit where PR branched off
fetch-depth: 0
- name: Get changed TeX files
id: diff
run: |
BASE_REF=${{ github.event.before }}
git fetch origin $BASE_REF --depth=1
echo "TeX files changed between BASE_REF=$BASE_REF and SHA=$GITHUB_SHA:"
tex_files=$(git diff --name-only $BASE_REF $GITHUB_SHA | grep .tex$ | xargs)
echo "$tex_files"
typst_files=$(git diff --name-only $BASE_REF $GITHUB_SHA | grep .typ$ | xargs)
echo "$typst_files"
echo "::set-output name=tex-files::$tex_files"
echo "::set-output name=typst-files::$typst_files"
- name: Install compression deps
if: steps.diff.outputs.tex-files != ''
run: |
sudo apt-get install -y pdf2svg imagemagick pngquant zopfli
sudo snap install svgo
pip install pdf-compressor
pdf-compressor --set-api-key ${{ secrets.ILOVEPDF_PUBLIC_KEY }}
- name: Install TeX Live
if: steps.diff.outputs.tex-files != ''
# texlive-latex-extra is needed for package standalone
run: sudo apt-get install texlive latexmk texlive-latex-base texlive-latex-extra
- name: Install Typst
if: steps.diff.outputs.typst-files != ''
uses: typst-community/setup-typst@v3
- name: Run render_(typst|tikz).py on changed TeX files
if: steps.diff.outputs.tex-files != ''
id: render-diagrams
run: |
for tex_file in ${{ steps.diff.outputs.tex-files }}; do
echo "Processing $tex_file..."
python scripts/render_tikz.py "$tex_file"
done
for typst_file in ${{ steps.diff.outputs.typst-files }}; do
echo "Processing $typst_file..."
python scripts/render_typst.py "$typst_file"
done
- name: Push changes if any
if: steps.render-diagrams.outcome == 'success'
run: |
git config user.name 'Janosh Riebesell'
git config user.email [email protected]
git checkout ${{ github.head_ref }}
git add assets/**/*.{pdf,svg,png}
git commit -m 'assets for ${{ steps.diff.outputs.tex-files }}'
git push