-
-
Notifications
You must be signed in to change notification settings - Fork 4
316 lines (269 loc) · 9.72 KB
/
render.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
name: Render book
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
render-books:
name: Render books
runs-on: ubuntu-20.04
steps:
- name: Extract branch name
if: github.event_name != 'pull_request'
shell: bash
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
id: extract_branch
- name: Extract branch name on pull request
if: github.event_name == 'pull_request'
run: echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF})" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v3
- name: Get version
run: |
version=$(cat ./VERSION)
version=${version##+( )} # Trim left whitespaces
version=${version%%+( )} # Trim right whitespaces
echo "BOOK_VERSION=$version" >> $GITHUB_ENV
echo "version : $version"
- name: Checking version format
run: |
if ! [[ $BOOK_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+(-(alpha|beta|rc)(-[0-9]+)?)?$ ]]
then
echo "Invalid version format. Check your ./VERSION file."
exit 1
fi
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%B %Y')"
- name: Install pandoc
run: |
wget https://github.com/jgm/pandoc/releases/download/2.9.2.1/pandoc-2.9.2.1-1-amd64.deb
sudo dpkg -i pandoc-2.9.2.1-1-amd64.deb
sudo apt-get update && sudo apt-get install -y make texlive texlive-xetex texlive-latex-extra texlive-fonts-recommended pdftk
- name: Configure pdftk
run: |
sudo sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml
- name: Install mainfont
run: |
mkdir -p "$HOME/.local/share/fonts"
cp ./fra/templates/fonts/* "$HOME/.local/share/fonts"
cp ./eng/templates/fonts/* "$HOME/.local/share/fonts"
- name: Render PDF
run: |
sed -i -E "s/date: .+/date: ${{ steps.date.outputs.date }} - ${{ env.BOOK_VERSION }}/g" ./fra/metadata.yml
sed -i -E "s/date: .+/date: ${{ steps.date.outputs.date }} - ${{ env.BOOK_VERSION }}/g" ./eng/metadata.yml
cd ./fra && make pdf && cd -
mv ./fra/build/pdf/book.pdf ./fra/build/pdf/book-fra.pdf
cd ./eng && make pdf && cd -
mv ./eng/build/pdf/book.pdf ./eng/build/pdf/book-eng.pdf
- name: Render HTML
run: |
cd ./fra && make html && cd -
cd ./eng && make html && cd -
- uses: actions/upload-artifact@v3
with:
name: book-fra-pdf-${{ env.BOOK_VERSION }}
path: ./fra/build/pdf/book-fra.pdf
retention-days: 1
- uses: actions/upload-artifact@v3
with:
name: book-fra-html-${{ env.BOOK_VERSION }}
path: ./fra/build/html/
retention-days: 1
- uses: actions/upload-artifact@v3
with:
name: book-eng-pdf-${{ env.BOOK_VERSION }}
path: ./eng/build/pdf/book-eng.pdf
retention-days: 1
- uses: actions/upload-artifact@v3
with:
name: book-eng-html-${{ env.BOOK_VERSION }}
path: ./eng/build/html/
retention-days: 1
# Pictures in the book may be referenced at some place in the text.
# Ex: \ref{fig:name} in the text to reference the \label{fig:name} illustration.
#
# When badly referenced, pandoc generates a double questionmarks ("??") in the place
# of the latex tags. This Action checks if there are no "??" in the generated PDF.
check-latex-references:
needs: render-books
name: Check valid latex references
runs-on: ubuntu-22.04
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Install poppler-utils
run: |
sudo apt-get update && sudo apt-get install -y poppler-utils
- name: Get version
run: |
version=$(cat ./VERSION)
version=${version##+( )} # Trim left whitespaces
version=${version%%+( )} # Trim right whitespaces
echo "BOOK_VERSION=$version" >> $GITHUB_ENV
echo "version : $version"
- name: Checking version format
run: |
if ! [[ $BOOK_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+(-(alpha|beta|rc)(-[0-9]+)?)?$ ]]
then
echo "Invalid version format. Check your ./VERSION file."
exit 1
fi
- name: Download FR artifact
uses: actions/download-artifact@v3
with:
name: book-fra-pdf-${{ env.BOOK_VERSION }}
path: ./
- name: Get FR text from book
run: |
pdftotext ./book-fra.pdf
- name: Get FR text from book
run: |
if grep -q "??" ./book-fra.pdf; then
echo "The file contains the string '??'"
else
echo "The file does not contain the string '??'"
fi
- name: Download EN artifact
uses: actions/download-artifact@v3
with:
name: book-eng-pdf-${{ env.BOOK_VERSION }}
path: ./
- name: Get EN text from book
run: |
pdftotext ./book-eng.pdf
- name: Get EN text from book
run: |
if grep -q "??" ./book-eng.pdf; then
echo "The file contains the string '??'"
else
echo "The file does not contain the string '??'"
fi
check-version-change:
name: "Check version change"
runs-on: ubuntu-22.04
needs: check-latex-references
outputs:
version_changed: ${{ steps.check.outputs.version_changed }}
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
ref: ${{ github.sha }}
fetch-depth: 2
- name: Get Previous Commit
id: prev_commit
run: echo "::set-output name=sha::$(git log --skip=1 -n 1 --pretty=format:'%H')"
- name: Check VERSION file change
id: check
run: |
if git diff --name-only ${{ steps.prev_commit.outputs.sha }} ${{ github.sha }} | grep '^VERSION$'; then
echo "VERSION file was modified."
echo "::set-output name=version_changed::true"
else
echo "VERSION file was not modified."
echo "::set-output name=version_changed::false"
fi
deploy-to-gh-pages:
if: needs.check-version-change.outputs.version_changed == 'true' && (github.ref == 'refs/heads/main')
needs: check-version-change
runs-on: ubuntu-22.04
name: Deploy to GitHub Pages
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Get version
run: |
version=$(cat ./VERSION)
version=${version##+( )} # Trim left whitespaces
version=${version%%+( )} # Trim right whitespaces
echo "BOOK_VERSION=$version" >> $GITHUB_ENV
echo "version : $version"
- name: Checking version format
run: |
if ! [[ $BOOK_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+(-(alpha|beta|rc)(-[0-9]+)?)?$ ]]
then
echo "Invalid version format. Check your ./VERSION file."
exit 1
fi
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: book-fra-html-${{ env.BOOK_VERSION }}
path: output/fra/
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: book-eng-html-${{ env.BOOK_VERSION }}
path: output/eng/
- name: Optimize images
run: |
sudo apt-get install -y jpegoptim optipng
find ./output/ -iname '*.jpg' -exec jpegoptim {} \; -o -iname '*.png' -exec optipng {} \;
- name: Copy default index files
run: |
cp ./index.html ./output/
cp -r ./images ./output/
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: output/
full_commit_message: Publishing version ${{ env.BOOK_VERSION }} - ${{ github.event.head_commit.message }}
cname: book-devops.berwick.fr
release:
if: needs.check-version-change.outputs.version_changed == 'true' && (github.ref == 'refs/heads/main')
needs: check-version-change
runs-on: ubuntu-22.04
name: Generate book files for release
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Get version
run: |
version=$(cat ./VERSION)
version=${version##+( )} # Trim left whitespaces
version=${version%%+( )} # Trim right whitespaces
echo "BOOK_VERSION=$version" >> $GITHUB_ENV
echo "version : $version"
- name: Checking version format
run: |
if ! [[ $BOOK_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+(-(alpha|beta|rc)(-[0-9]+)?)?$ ]]
then
echo "Invalid version format. Check your ./VERSION file."
exit 1
fi
- name: Download FR PDF artifact
uses: actions/download-artifact@v3
with:
name: book-fra-pdf-${{ env.BOOK_VERSION }}
path: ./
- name: Download EN PDF artifact
uses: actions/download-artifact@v3
with:
name: book-eng-pdf-${{ env.BOOK_VERSION }}
path: ./
- name: Get version
id: get-version
run: |
VERSION_CONTENT=$(cat VERSION)
echo "::set-output name=version::$VERSION_CONTENT"
if [[ $VERSION_CONTENT == *"-alpha"* ]] || [[ $VERSION_CONTENT == *"-beta"* ]] || [[ $VERSION_CONTENT == *"-rc"* ]]; then
echo "::set-output name=prerelease::true"
else
echo "::set-output name=prerelease::false"
fi
- name: Create release
uses: softprops/action-gh-release@v1
with:
name: ${{ env.BOOK_VERSION }}
tag_name: ${{ env.BOOK_VERSION }}
files: |
./book-fra.pdf
./book-eng.pdf
prerelease: ${{ steps.get-version.outputs.prerelease }}
env:
GITHUB_TOKEN: ${{ github.token }}