forked from rrthomas/hpmor
-
Notifications
You must be signed in to change notification settings - Fork 6
198 lines (161 loc) · 5.23 KB
/
check-and-ebook.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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# This workflow performs
# check: Quality checks on chapter text and code upon new commits and PRs.
# make: Makes eBooks if .tex files have changed.
# upload: Uploads the artifacts to release WorkInProgress, but only for push into main branch.
name: Check and Make eBook
# This workflow runs upon
# - manual triggering
# - create new PR (check, make)
# - push to main (check, make, upload)
on:
workflow_dispatch:
pull_request:
branches: ["main"]
push:
branches: ["main"]
jobs:
check:
runs-on: ubuntu-24.04
outputs:
cache-hit: ${{ steps.cache-lookup.outputs.cache-hit }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 1 # 0 if you want to push to repo
- name: Calculate hash on chapters/*.tex
id: calculate-hash
run: |
echo "hash=${{ hashFiles('chapters/*.tex') }}" >> $GITHUB_OUTPUT
touch hash-chapters.txt
- name: Cache lookup
id: cache-lookup
uses: actions/cache@v4
with:
path: hash-chapters.txt
key: chapter-hash-for-ebook-${{ github.ref_name }}-${{ steps.calculate-hash.outputs.hash }}
- name: Preparations
run: ln -s python-requirements.txt requirements.txt
- name: Python set up
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
- name: Python packages
run: pip install -r python-requirements.txt
- name: Run pytest unittests
run: pytest
- name: Check chapters for known issues
run: python3 -O scripts/check_chapters.py
- name: Check pre-commit tests
uses: pre-commit/action@v3.0.1
make:
needs: check
# do not run for unchanged tex files
if: needs.check.outputs.cache-hit != 'true'
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 1 # 0 if you want to push to repo
- name: Preparations
run: ln -s python-requirements.txt requirements.txt
- name: Python set up
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
- name: Install Python packages
run: pip install -r python-requirements.txt
# - name: setup environment to DE lang
# run: |
# cd /usr/share/locales
# sudo ./install-language-pack de_DE.UTF-8
- name: ls before
run: |
pwd
ls -l
- name: Speed up apt-get steps
uses: abbbi/github-actions-tune@v1
- name: Install apt packages using cache
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: texlive-extra-utils pandoc calibre imagemagick ghostscript
version: 1.0
# execute_install_scripts: true
- name: Install ImageMagick to fix caching issue
# since cache does not properly work / "convert" not found
run: |
sudo apt-get install imagemagick
- name: Print versions
run: |
cat /etc/os-release
# xelatex -v
# latexmk -v
calibre --version
pandoc --version
ebook-convert --version
python3 --version
- name: Make eBooks
run: |
wget --quiet https://github.com/${{ github.repository }}/releases/latest/download/hpmor.html -O hpmor-prev.html
wget --quiet https://github.com/${{ github.repository }}/releases/latest/download/hpmor.pdf -O hpmor.pdf
sh scripts/make_ebooks.sh > /dev/null
- name: Compare to previous hpmor.html
run: |
diff -U 0 -s hpmor-prev.html hpmor.html > hpmor-html-diff.log || true
- name: ls after
run: |
pwd
ls -al
- name: Upload eBooks as artifact
uses: actions/upload-artifact@v4
with:
name: ebooks
path: |
./hpmor-html-diff.log
./hpmor.docx
./hpmor.epub
./hpmor.fb2
./hpmor.html
./hpmor.mobi
retention-days: 14
#
# upload to release WorkInProgress
#
upload:
needs: make
# only for main branch and actions push or manual run
if: github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
permissions:
contents: write
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get tags
run: git fetch --tags origin
- name: Update tag WorkInProgress
run: |
git tag -d WorkInProgress || true
git tag WorkInProgress
git push origin -f WorkInProgress
- name: Download eBooks artifact
uses: actions/download-artifact@v4
with:
name: ebooks
- name: Publish eBooks to release WorkInProgress
uses: softprops/action-gh-release@v2
with:
tag_name: WorkInProgress
prerelease: true
files: |
./hpmor-html-diff.log
./hpmor.docx
./hpmor.epub
./hpmor.fb2
./hpmor.html
./hpmor.mobi