Skip to content

Commit 4394043

Browse files
authored
Merge pull request italia#741 from italia/pdf-workflow
Workflow Automation for PDF generation
2 parents 02e0537 + 1e257f7 commit 4394043

File tree

2 files changed

+135
-38
lines changed

2 files changed

+135
-38
lines changed

.github/workflows/build-pdf.yml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: pdf-build
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
# Allows you to run this workflow manually from the Actions tab
9+
workflow_dispatch:
10+
11+
jobs:
12+
build-pdf:
13+
runs-on: ubuntu-latest
14+
env:
15+
SETTINGS_FILE_NAME: "eid-wallet-it-docs"
16+
steps:
17+
# Check out your repository under $GITHUB_WORKSPACE, so your job can access it
18+
- uses: actions/checkout@v3
19+
20+
- uses: actions/setup-python@v4
21+
with:
22+
python-version: "3.10"
23+
architecture: "x64"
24+
25+
- name: Setup Java
26+
uses: actions/setup-java@v3
27+
with:
28+
distribution: 'temurin'
29+
java-version: '17'
30+
31+
- name: Install LaTeX and dependencies
32+
run: |
33+
sudo apt-get update
34+
# Common pkg
35+
sudo apt-get install -y texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended
36+
# languages pkg
37+
sudo apt-get install -y texlive-lang-italian texlive-lang-english
38+
# graphix nd images pkg
39+
sudo apt-get install -y texlive-pictures texlive-font-utils graphviz
40+
# utils for imgs (svg, pdf, ..)
41+
sudo apt-get install -y ghostscript poppler-utils imagemagick netpbm
42+
# Core pkg
43+
sudo apt-get install -y texlive-base texlive-binaries
44+
# LuaLaTeX engine
45+
sudo apt-get install -y texlive-luatex
46+
# Additional pkg (fonts, tables, formatting, etc.)
47+
sudo apt-get install -y texlive-fonts-extra texlive-science texlive-publishers texlive-formats-extra texlive-latex-extra
48+
49+
- name: Install Python dependencies
50+
run: |
51+
python -m pip install -r requirements-dev.txt
52+
53+
# Append appropriate tags to document title based on build context
54+
- name: Append tags to document title
55+
run: |
56+
if [[ "${{ github.event_name }}" == "release" ]]; then
57+
TAG="${{ github.event.release.tag_name }}"
58+
sed -i 's/\(settings_project_name = ".*\)"/\1 - Release '"${TAG}"'"/' docs/it/conf.py
59+
sed -i 's/\(settings_project_name = ".*\)"/\1 - Release '"${TAG}"'"/' docs/en/conf.py
60+
echo "Applied release tag '${TAG}' to document titles"
61+
else
62+
# This is for workflow_dispatch, we use editor's copy designation
63+
echo "Using default title for manual build"
64+
sed -i 's/\(settings_project_name = ".*\)"/\1 - Versione Corrente"/' docs/it/conf.py
65+
sed -i 's/\(settings_project_name = ".*\)"/\1 - Editor'"'"'s Copy"/' docs/en/conf.py
66+
fi
67+
68+
sed -i 's/settings_file_name = ".*"/settings_file_name = "'"$SETTINGS_FILE_NAME"'"/' docs/en/conf.py
69+
70+
- name: Generate LaTeX files and build en version
71+
run: |
72+
echo "Building English version..."
73+
sphinx-build -b latex docs/en/ build/latex/en
74+
cd build/latex/en
75+
76+
# Build
77+
echo "=== First LaTeX run ==="
78+
lualatex -interaction=nonstopmode -file-line-error "$SETTINGS_FILE_NAME.tex" 2>&1 | grep -E "Warning|Error"
79+
80+
echo "Processing index..."
81+
makeindex "$SETTINGS_FILE_NAME.idx" || true
82+
83+
echo "=== Second LaTeX run ==="
84+
lualatex -interaction=nonstopmode -file-line-error "$SETTINGS_FILE_NAME.tex" 2>&1 | grep -E "Warning|Error"
85+
86+
echo "=== Final LaTeX run ==="
87+
lualatex -interaction=nonstopmode -file-line-error "$SETTINGS_FILE_NAME.tex" 2>&1 | grep -E "Warning|Error"
88+
89+
echo "=== Build completed ==="
90+
ls -la "$SETTINGS_FILE_NAME.pdf" || echo "PDF not generated!"
91+
92+
93+
- name: Generate LaTeX files and build it version
94+
run: |
95+
sphinx-build -b latex docs/it/ build/latex/it
96+
cd build/latex/it
97+
# Build
98+
echo "=== First LaTeX run ==="
99+
lualatex -interaction=nonstopmode -file-line-error "$SETTINGS_FILE_NAME.tex" 2>&1 | grep -E "Warning|Error"
100+
101+
echo "Processing index..."
102+
makeindex "$SETTINGS_FILE_NAME.idx" || true
103+
104+
echo "=== Second LaTeX run ==="
105+
lualatex -interaction=nonstopmode -file-line-error "$SETTINGS_FILE_NAME.tex" 2>&1 | grep -E "Warning|Error"
106+
107+
echo "=== Final LaTeX run ==="
108+
lualatex -interaction=nonstopmode -file-line-error "$SETTINGS_FILE_NAME.tex" 2>&1 | grep -E "Warning|Error"
109+
110+
echo "=== Build completed ==="
111+
ls -la "$SETTINGS_FILE_NAME.pdf" || echo "PDF not generated!"
112+
113+
- name: Create PDF directory
114+
run: |
115+
mkdir -p pdf_output
116+
117+
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
118+
119+
cp build/latex/it/$SETTINGS_FILE_NAME.pdf pdf_output/$SETTINGS_FILE_NAME-it-${TIMESTAMP}.pdf
120+
cp build/latex/en/$SETTINGS_FILE_NAME.pdf pdf_output/$SETTINGS_FILE_NAME-en-${TIMESTAMP}.pdf
121+
122+
- name: Upload PDFs as artifact
123+
if: github.event_name == 'workflow_dispatch'
124+
uses: actions/upload-artifact@v4
125+
with:
126+
name: documentation-pdf
127+
path: pdf_output/*.pdf
128+
129+
- name: Upload Release Asset
130+
if: github.event_name == 'release'
131+
uses: softprops/action-gh-release@v1
132+
with:
133+
files: pdf_output/*.pdf
134+
env:
135+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/latex.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)