-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-pdfs
executable file
·39 lines (36 loc) · 1.63 KB
/
generate-pdfs
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
#!/usr/bin/env bash
### IMPORTANT!!!
### Keep this file in sync with action.yml
# Ignore failures due to grep when piped.
# https://stackoverflow.com/a/11231970/5868796
set +o pipefail
# These are magic workflow commands for GitHub Actions
# Docs: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines
echo "::group::Creating PDFs"
echo "List of files:"
grep -s -l "window\.PrimerSpecConfig" _site/**/*.html _site/*.html | cat
echo "Generating PDFs..."
grep -s -l "window\.PrimerSpecConfig" _site/**/*.html _site/*.html | while read -r file
do
relativePath=${file#_site/}
pdfFile="_site/assets/primer-spec-pdf/${relativePath%.html}.pdf"
pdfFileDir=${pdfFile%/*}
echo "Source: $file"
echo "Dest: $pdfFile"
echo "In directory: $pdfFileDir"
echo ""
mkdir -p $pdfFileDir
echo "Writing to $pdfFile..."
chrome --no-sandbox --headless --disable-gpu --disable-software-rasterizer --run-all-compositor-stages-before-draw --print-to-pdf-no-header --print-to-pdf="$pdfFile" $file
# Chrome appears to provide r/w permissions only to the `user/owner` group,
# so GitHub Pages is unable to read the file.
# HUGE thanks to Arthur from GitHub Support for figuring this out! ❤️
echo "Making the PDF readable to GitHub Pages..."
chmod a+r $pdfFile
# Update the corresponding HTML file so Primer Spec knows that a PDF is
# available.
echo "Updating the corresponding HTML file to include PDF path: ${pdfFile#_site/}"
sed -i "s=pdfPath:.*// @managed by build-primer-spec-action=pdfPath: '${pdfFile#_site/}', // @managed by build-primer-spec-action=" $file
echo "Done."
done
echo "::endgroup::"