Skip to content

Commit 1a02665

Browse files
committed
Add one-time deterministic PDF finalization workflow
Signed-off-by: Ari Sulistiono <admin@arisulistiono.com>
1 parent d055ec1 commit 1a02665

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Finalize deterministic release PDFs
2+
3+
on:
4+
push:
5+
branches: [hardening/release-integrity]
6+
paths:
7+
- ".github/workflows/finalize-pdf-determinism.yml"
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: write
12+
13+
jobs:
14+
finalize:
15+
if: github.actor == 'masarray'
16+
runs-on: ubuntu-24.04
17+
steps:
18+
- name: Checkout hardening branch
19+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
20+
with:
21+
ref: hardening/release-integrity
22+
fetch-depth: 0
23+
24+
- name: Make ReportLab output invariant
25+
shell: python
26+
run: |
27+
from pathlib import Path
28+
path = Path('scripts/generate-release-pdfs.py')
29+
text = path.read_text(encoding='utf-8')
30+
if 'from reportlab.pdfgen import canvas' not in text:
31+
text = text.replace('from reportlab.pdfbase.pdfmetrics import stringWidth\n', 'from reportlab.pdfbase.pdfmetrics import stringWidth\nfrom reportlab.pdfgen import canvas\n')
32+
marker = '\ndef footer(canvas, doc):\n'
33+
function = "\ndef invariant_canvas(*args, **kwargs):\n kwargs['invariant'] = 1\n return canvas.Canvas(*args, **kwargs)\n"
34+
if 'def invariant_canvas(' not in text:
35+
text = text.replace(marker, function + marker)
36+
text = text.replace('doc.build(story, onFirstPage=footer, onLaterPages=footer)', 'doc.build(story, onFirstPage=footer, onLaterPages=footer, canvasmaker=invariant_canvas)')
37+
path.write_text(text, encoding='utf-8')
38+
39+
- name: Regenerate and verify PDFs
40+
run: |
41+
python -m pip install --disable-pip-version-check reportlab==4.4.9 pypdf==6.4.1
42+
python scripts/generate-release-pdfs.py
43+
python scripts/generate-release-pdfs.py --check
44+
python scripts/validate-public-content.py
45+
46+
- name: Remove one-time workflow and commit
47+
shell: bash
48+
run: |
49+
set -euo pipefail
50+
rm -f .github/workflows/finalize-pdf-determinism.yml
51+
git config user.name "Ari Sulistiono"
52+
git config user.email "admin@arisulistiono.com"
53+
git add -A
54+
git commit -s -m "Make release PDF generation deterministic"
55+
git push origin HEAD:hardening/release-integrity

0 commit comments

Comments
 (0)