Fix Jenkins ZIP packaging with uv-managed AES dependencies
Report CI typst_reporter failed CI.
Beffroi/typst_reporter/pipeline/head There was a failure building this commit
Details
Report CI typst_reporter failed CI.
Beffroi/typst_reporter/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
8db89054f5
commit
d832c23116
|
|
@ -21,3 +21,4 @@ Desktop.ini
|
|||
|
||||
# Jenkins encrypted publication artifacts
|
||||
/.ci-artifacts/
|
||||
/.ci-venv/
|
||||
|
|
|
|||
|
|
@ -68,12 +68,22 @@ pipeline {
|
|||
}
|
||||
}
|
||||
|
||||
stage('Setup Packaging') {
|
||||
steps {
|
||||
sh '''
|
||||
set -eu
|
||||
uv venv --allow-existing .ci-venv
|
||||
uv pip install --python .ci-venv/bin/python -r tools/packaging-requirements.txt
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Validate') {
|
||||
steps {
|
||||
sh '''
|
||||
set -eu
|
||||
bash -n render.sh render-diagnostics.sh tools/package-reports.sh
|
||||
command -v zip
|
||||
.ci-venv/bin/python -c "import pyzipper"
|
||||
command -v python3
|
||||
typst compile --root . tools/check-diagnostics.typ /tmp/check-diagnostics.pdf
|
||||
'''
|
||||
|
|
@ -97,7 +107,7 @@ pipeline {
|
|||
sh '''
|
||||
set +x
|
||||
set -eu
|
||||
./tools/package-reports.sh build "${CI_ARTIFACT_DIR}"
|
||||
PACKAGING_PYTHON=.ci-venv/bin/python ./tools/package-reports.sh build "${CI_ARTIFACT_DIR}"
|
||||
'''
|
||||
archiveArtifacts artifacts: '.ci-artifacts/*.zip', fingerprint: true
|
||||
}
|
||||
|
|
|
|||
10
README.md
10
README.md
|
|
@ -127,9 +127,11 @@ publishes encrypted archives to the same `/mnt/books` mount used by the books:
|
|||
- `/mnt/books/Reports/Reports.zip`: YAML report PDFs.
|
||||
- `/mnt/books/Reports/Diagnostics.zip`: diagnostic PDFs, preserving subfolders.
|
||||
|
||||
Only the ZIPs are archived as Jenkins artifacts. The agent needs `zip`, Python 3,
|
||||
Only the ZIPs are archived as Jenkins artifacts. The agent needs `uv` and Python 3, access to PyPI,
|
||||
and write access to `/mnt/books/Reports`. `DIAGNOSTICS_AUTHOR` defaults to Beffroi.
|
||||
Packaging uses standard ZIP password encryption (ZipCrypto, not AES).
|
||||
Jenkins installs pinned [pyzipper](https://pypi.org/project/pyzipper/) into `.ci-venv`
|
||||
and creates AES-256 ZIPs without a system `zip` executable. Extract with an
|
||||
AES-capable ZIP reader, such as 7-Zip.
|
||||
The temporary password is `CHANGE_ME`; it is a public placeholder, not a secret.
|
||||
Later create a Jenkins **Secret text** credential and replace the Jenkinsfile
|
||||
assignment with `REPORT_ZIP_PASSWORD = credentials('reports-zip-password')`.
|
||||
|
|
@ -138,5 +140,7 @@ The packaging script reads that environment variable with shell tracing disabled
|
|||
To package an existing local build:
|
||||
|
||||
```bash
|
||||
REPORT_ZIP_PASSWORD=CHANGE_ME ./tools/package-reports.sh
|
||||
uv venv --allow-existing .ci-venv
|
||||
uv pip install --python .ci-venv/bin/python -r tools/packaging-requirements.txt
|
||||
PACKAGING_PYTHON=.ci-venv/bin/python REPORT_ZIP_PASSWORD=CHANGE_ME ./tools/package-reports.sh
|
||||
```
|
||||
|
|
|
|||
|
|
@ -3,8 +3,9 @@
|
|||
set +x
|
||||
set -euo pipefail
|
||||
: "${REPORT_ZIP_PASSWORD:?Set REPORT_ZIP_PASSWORD before packaging}"
|
||||
command -v zip >/dev/null
|
||||
command -v python3 >/dev/null
|
||||
script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||
packaging_python="${PACKAGING_PYTHON:-$script_dir/../.ci-venv/bin/python}"
|
||||
"$packaging_python" -c "import pyzipper"
|
||||
build_dir="$(realpath "${1:-build}")"
|
||||
output_dir="$(realpath -m "${2:-.ci-artifacts}")"
|
||||
mkdir -p "$output_dir"
|
||||
|
|
@ -32,19 +33,24 @@ for category in Reports Diagnostics; do
|
|||
count=$((count + 1))
|
||||
done < <(find "$source_dir" "${depth[@]}" -type f -name '*.pdf' -print0)
|
||||
((count > 0)) || { echo "No PDFs for $category" >&2; exit 1; }
|
||||
(
|
||||
cd "$staging_dir/$category"
|
||||
zip -q -r -P "$REPORT_ZIP_PASSWORD" "$staging_dir/$category.zip" .
|
||||
)
|
||||
# Check encryption and decrypt every entry to verify its CRC before publishing.
|
||||
python3 - "$staging_dir/$category.zip" <<'PY_VERIFY'
|
||||
import os, sys, zipfile
|
||||
with zipfile.ZipFile(sys.argv[1]) as archive:
|
||||
entries = [entry for entry in archive.infolist() if not entry.is_dir()]
|
||||
"$packaging_python" - "$staging_dir/$category" "$staging_dir/$category.zip" <<'PY_VERIFY'
|
||||
import os, sys
|
||||
from pathlib import Path
|
||||
import pyzipper
|
||||
source = Path(sys.argv[1])
|
||||
password = os.environ["REPORT_ZIP_PASSWORD"].encode()
|
||||
with pyzipper.AESZipFile(sys.argv[2], "w", compression=pyzipper.ZIP_DEFLATED) as archive:
|
||||
archive.setpassword(password)
|
||||
archive.setencryption(pyzipper.WZ_AES, nbits=256)
|
||||
for pdf in sorted(source.rglob("*.pdf")):
|
||||
archive.write(str(pdf), pdf.relative_to(source).as_posix())
|
||||
# Authenticate and decrypt every PDF before making the archive available.
|
||||
with pyzipper.AESZipFile(sys.argv[2]) as archive:
|
||||
entries = archive.infolist()
|
||||
assert entries, "Empty archive"
|
||||
for entry in entries:
|
||||
assert entry.flag_bits & 1, f"Unencrypted entry: {entry.filename}"
|
||||
assert archive.read(entry, pwd=os.environ["REPORT_ZIP_PASSWORD"].encode()).startswith(b"%PDF-")
|
||||
assert entry.flag_bits & 1 and entry.wz_aes_strength == 3, f"Not AES-256: {entry.filename}"
|
||||
assert archive.read(entry, pwd=password).startswith(b"%PDF-")
|
||||
PY_VERIFY
|
||||
cp "$staging_dir/$category.zip" "$output_dir/$category.zip"
|
||||
done
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
pyzipper==0.4.0
|
||||
Reference in New Issue