Skip to content

Commit 5badd30

Browse files
authored
Add GitHub Actions workflow to create PDFs from Markdown
1 parent 8d36214 commit 5badd30

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

.github/workflows/create_pdf.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: create PDF workflow
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- '**.md' # Only run if Markdown files change
9+
- '!.github/**' # Don't run if only workflow files change
10+
11+
# This prevents multiple runs from overlapping if you push rapidly
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
makepdfs:
18+
runs-on: ubuntu-latest
19+
container:
20+
image: docker://pandoc/latex:2.9
21+
22+
steps:
23+
- uses: actions/checkout@v3
24+
25+
- name: prepare output directories
26+
run: |
27+
for d in */; do
28+
mkdir -p output/"$d"
29+
done
30+
31+
- name: create pdf file(s)
32+
run: |
33+
find . -type f \( -iname "*.md" ! -iname "README.md" \) | while read f; do
34+
pandoc "$f" -s -o "output/${f%.md}.pdf" --toc --number-sections --verbose
35+
done
36+
37+
- uses: actions/upload-artifact@v3
38+
with:
39+
name: output
40+
path: output
41+
42+
pushpdfs:
43+
needs: makepdfs
44+
runs-on: ubuntu-latest
45+
# Added a check to ensure the bot doesn't trigger itself
46+
if: github.actor != 'github-actions[bot]'
47+
48+
steps:
49+
- uses: actions/checkout@v3
50+
51+
- name: Download all workflow run artifacts
52+
uses: actions/download-artifact@v3
53+
with:
54+
name: output
55+
path: pdf
56+
57+
- name: Add and commit files
58+
run: |
59+
git config --global user.name github-actions[bot]
60+
git config --global user.email github-actions[bot]@users.noreply.github.com
61+
62+
# Check if there are actually changes to avoid empty commit errors
63+
git add pdf/*.pdf
64+
if git diff --staged --quiet; then
65+
echo "No changes to commit"
66+
else
67+
git commit -m "Auto update pdfs [skip ci]" -a
68+
git push
69+
fi

0 commit comments

Comments
 (0)