-
Notifications
You must be signed in to change notification settings - Fork 0
98 lines (87 loc) · 3.51 KB
/
tex-pdf.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
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
# add .tex conversion and (and .pdf rendering of .tex file) to a pull request that adds/modifies a cgel tree.
# currently assumes cgel file(s) in datasets/oneoff.
name: Create tree .tex and .pdf
on:
push:
paths:
- datasets/oneoff/*.cgel
branches-ignore:
- main
jobs:
render:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
submodules: true
fetch-depth: 0
- name: Update to make sure we have a newly created branch
run: |
git branch -v
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# https://github.com/trilom/file-changes-action/issues/116#issuecomment-790007782
- name: Get changed files
run: |
# check to see if there's a previous commit on the branch
# if not, then diff with origin/main
# if yes, then diff with the HEAD @ prevous commit
if [[ "${{ github.event.before }}" == "0000000000000000000000000000000000000000" ]] ; then
git fetch --depth=1 origin main
export DIFF=$( git diff --name-only origin/main ${{ github.sha }} )
echo "Diff between origin/main and ${{ github.sha }} "
else
export DIFF=$( git diff --name-only ${{ github.event.before }} ${{ github.sha }} )
echo "Diff between ${{ github.event.before }} and ${{ github.sha }} "
fi
echo "DIFF_FILES=$(echo $DIFF | tr '\n' ' ')" >> $GITHUB_ENV
- name: Config github actions bot
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
cache: 'pip'
- run: pip install -r cgel/requirements.txt
- name: Install jq
run: |
sudo apt-get update
sudo apt-get install -y jq
- name: Generate .tex and .pdf files
env:
SERVICE_URL: ${{ secrets.LATEX_SERVICE_URL }}
CREDS: ${{ secrets.TEXLIVE_API_CREDS }}
run: |
mkdir -p datasets/oneoff/tex
mkdir -p datasets/oneoff/pdf
for changed_file in ${DIFF_FILES}; do
if [[ "$changed_file" == **.cgel ]]; then
filename=$(basename "$changed_file")
tree_name="${filename%.cgel}"
# make .tex
python cgel/tree2tex.py "${changed_file}" > "datasets/oneoff/tex/$tree_name.tex"
# make .pdf
jq -n --arg latex "$(cat datasets/oneoff/tex/$tree_name.tex)" '{"latex_code": $latex}' | curl -X POST "$SERVICE_URL" -u $CREDS -H "Content-Type: application/json" -d @- --output datasets/oneoff/pdf/$tree_name.pdf
fi
done
- name: Commit and push .tex and .pdf files
run: |
for changed_file in ${DIFF_FILES}; do
if [[ "$changed_file" == **.cgel ]]; then
filename=$(basename "$changed_file")
tree_name="${filename%.cgel}"
git add "datasets/oneoff/tex/$tree_name.tex"
git add "datasets/oneoff/pdf/$tree_name.pdf"
git commit -m "generated tex and pdf files for $filename"
fi
done
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}