Skip to content

PP attachment

PP attachment #229

Workflow file for this run

# 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: Setup TeX Live
uses: teatimeguest/setup-texlive-action@e69e0852590264df4a35dbc6cc94009a2466a562
with:
packages: |
scheme-full
- name: Generate .tex and .pdf files
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
pdflatex -output-directory=datasets/oneoff/pdf "datasets/oneoff/tex/$tree_name.tex"
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 }}