Repository navigation
205 lines (181 loc) · 7.72 KB
/
Copy pathpdf.yml
File metadata and controls
205 lines (181 loc) · 7.72 KB
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
---
name: PDF
# Builds every PDF of the documentation after a push to main or to the
# print-on-demand branch: the screen edition, the print edition (the book block
# for print on demand), its PDF/X-4 copy in CMYK and the greyscale preview. The
# run summary lists all four with their download links, so they need not be dug
# out of the artifact section.
on:
push:
branches: ["main", "feature/print-on-demand"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
permissions:
contents: read
# A newer push to the same branch makes a running build obsolete; main and a
# branch do not cancel each other.
concurrency:
group: "pdf-${{ github.ref }}"
cancel-in-progress: true
env:
# The versions the PDF style is tested with (TESTED_TYPST in tools/build_pdf.py).
# Typst is pre-1.0 and its minor releases change layout, and the pandoc Ubuntu
# ships is older, so both come from their own releases.
PANDOC_VERSION: "3.11"
TYPST_VERSION: "0.15.1"
jobs:
pdf:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
with:
submodules: "recursive"
fetch-depth: "0"
- name: setup python
id: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: install task
uses: arduino/setup-task@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: install and configure poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: load environment cache
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: update packages
run: sudo apt-get update -y
# Poppler carries the pdffonts, pdfimages and pdftotext the preflight report
# reads. Ghostscript comes from a container below, not from apt.
- name: install packages
run: sudo apt-get install -y libffi-dev libz-dev poppler-utils
- name: install pandoc
run: |
release="https://github.com/jgm/pandoc/releases/download/${PANDOC_VERSION}"
curl --fail --silent --show-error --location --output "$RUNNER_TEMP/pandoc.deb" \
"${release}/pandoc-${PANDOC_VERSION}-1-amd64.deb"
sudo dpkg -i "$RUNNER_TEMP/pandoc.deb"
- name: install typst
run: |
release="https://github.com/typst/typst/releases/download/v${TYPST_VERSION}"
curl --fail --silent --show-error --location "${release}/typst-x86_64-unknown-linux-musl.tar.xz" \
| tar -xJ -C "$RUNNER_TEMP"
sudo install -m 0755 "$RUNNER_TEMP/typst-x86_64-unknown-linux-musl/typst" /usr/local/bin/typst
# The ISO Coated v2 profile of the output intent is not in the repository
# (its licence forbids it), so it is fetched once and kept between runs.
- name: cache the output intent profile
uses: actions/cache@v4
with:
path: dist/icc
key: icc-iso-coated-v2-eci
# Ubuntu ships Ghostscript 10.02, where `-dPDFX=4` is still a boolean, so
# the 4 raises `/typecheck in --pdfmark--` and PDF/X-4 cannot be written at
# all. A container carries a newer one, behind a shim that runs it at the
# paths the build uses, so the PDFs, the pdfmark prefix and the profiles
# resolve inside the container exactly as they do outside. The grey output
# intent profile comes out of the same image.
- name: ghostscript from a container
run: |
printf 'FROM alpine:edge\nRUN apk add --no-cache ghostscript\n' | docker build -q -t pdfx-gs -
W="$GITHUB_WORKSPACE"
sudo tee /usr/local/bin/gs-docker >/dev/null <<SHIM
#!/bin/sh
exec docker run --rm -v "$W:$W" -v /tmp:/tmp -w "$W" pdfx-gs gs "\$@"
SHIM
sudo chmod +x /usr/local/bin/gs-docker
gs-docker --version
mkdir -p dist/icc
docker run --rm pdfx-gs cat /usr/share/ghostscript/iccprofiles/default_gray.icc \
> dist/icc/default_gray.icc
{
echo "GHOSTSCRIPT=/usr/local/bin/gs-docker"
echo "PDF_GRAY_PROFILE=$W/dist/icc/default_gray.icc"
} >> "$GITHUB_ENV"
- name: build the screen pdf
run: task pdf
- name: build the print pdfs
run: task pdf:print -- --normalize --gray
- name: upload the screen pdf
id: screen
uses: actions/upload-artifact@v4
with:
name: pdf-screen
path: |
dist/documentation-eccenca-com-*.pdf
!dist/documentation-eccenca-com-*-print*.pdf
if-no-files-found: error
retention-days: 30
# A PDF is compressed already.
compression-level: 0
- name: upload the print pdf
id: print
uses: actions/upload-artifact@v4
with:
name: pdf-print
path: dist/documentation-eccenca-com-*-print.pdf
if-no-files-found: error
retention-days: 30
compression-level: 0
- name: upload the pdf/x-4 pdf
id: pdfx
uses: actions/upload-artifact@v4
with:
name: pdf-print-x4
path: dist/documentation-eccenca-com-*-print-x4.pdf
if-no-files-found: error
retention-days: 30
compression-level: 0
- name: upload the greyscale pdf
id: gray
uses: actions/upload-artifact@v4
with:
name: pdf-print-gray-x4
path: dist/documentation-eccenca-com-*-print-gray-x4.pdf
if-no-files-found: error
retention-days: 30
compression-level: 0
# The table is built in one go and printed to the log as well, so the
# editions and their links are readable even if the summary ever stays
# empty - which is how the first run of this step ended.
- name: list the pdfs in the run summary
run: |
# $1 is a glob; $4, when given, drops what the glob also matches - the
# screen edition is the one file whose name carries no `-print`.
describe() {
file="$(ls $1 2>/dev/null | grep -v -- "${4:-^$}" | head -1)"
if [ -z "$file" ]; then
printf '| %s | - | - | missing |\n' "$2"
return
fi
printf '| %s | %s | %s | [%s](%s) |\n' "$2" \
"$(pdfinfo "$file" 2>/dev/null | awk '/^Pages/ {print $2}')" \
"$(du -h "$file" | cut -f1)" "$(basename "$file")" "$3"
}
{
echo "## PDF editions of ${GITHUB_REF_NAME}"
echo
echo "| Edition | Pages | Size | Download |"
echo "| :------ | ----: | ---: | :------- |"
describe "dist/documentation-eccenca-com-*.pdf" \
"Screen" "${{ steps.screen.outputs.artifact-url }}" "-print"
describe "dist/documentation-eccenca-com-*-print.pdf" \
"Print, book block" "${{ steps.print.outputs.artifact-url }}"
describe "dist/documentation-eccenca-com-*-print-x4.pdf" \
"Print, PDF/X-4 in CMYK" "${{ steps.pdfx.outputs.artifact-url }}"
describe "dist/documentation-eccenca-com-*-print-gray-x4.pdf" \
"Print, greyscale preview" "${{ steps.gray.outputs.artifact-url }}"
echo
echo "The print editions carry the preflight report of \`dec-tool pdf-preflight\`;"
echo "a failed check fails this job."
} | tee -a "$GITHUB_STEP_SUMMARY"
echo "summary file: $GITHUB_STEP_SUMMARY, $(wc -c < "$GITHUB_STEP_SUMMARY") bytes"