ci: restore uv managed zip packaging
This commit is contained in:
parent
e48c319249
commit
ab048d36d2
|
|
@ -51,7 +51,7 @@ pipeline {
|
|||
|
||||
stage('Package Reports') {
|
||||
environment {
|
||||
REPORT_ARCHIVE_PASSWORD = credentials('typst-reporter-publish-password')
|
||||
REPORT_ZIP_PASSWORD = credentials('typst-reporter-publish-password')
|
||||
}
|
||||
steps {
|
||||
sh '''
|
||||
|
|
@ -59,7 +59,7 @@ pipeline {
|
|||
set -eu
|
||||
./beffroi.sh package "${CI_REPORT_DIR}" "${CI_ARTIFACT_DIR}"
|
||||
'''
|
||||
archiveArtifacts artifacts: '.ci-artifacts/*.tar.gz.enc', fingerprint: true
|
||||
archiveArtifacts artifacts: '.ci-artifacts/*.zip', fingerprint: true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ pipeline {
|
|||
sh '''
|
||||
set -eu
|
||||
mkdir -p "${DEPLOY_DIR}"
|
||||
for archive in Reports.tar.gz.enc Diagnostics.tar.gz.enc; do
|
||||
for archive in Reports.zip Diagnostics.zip; do
|
||||
cp "${CI_ARTIFACT_DIR}/${archive}" "${DEPLOY_DIR}/.${archive}.tmp"
|
||||
mv -f "${DEPLOY_DIR}/.${archive}.tmp" "${DEPLOY_DIR}/${archive}"
|
||||
done
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ commit them with the reports submodule update, and run:
|
|||
./beffroi.sh all build/publication
|
||||
```
|
||||
|
||||
Jenkins runs the same build and publishes encrypted `Reports.tar.gz.enc` and
|
||||
`Diagnostics.tar.gz.enc` archives from `main`.
|
||||
Jenkins runs the same build and publishes AES-encrypted `Reports.zip` and
|
||||
`Diagnostics.zip` archives from `main`.
|
||||
|
||||
## Commands
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ case "$command_name" in
|
|||
scripts/build-publication.sh "$1"
|
||||
;;
|
||||
package)
|
||||
[[ $# -eq 2 ]]||usage 2; require tar gzip openssl
|
||||
[[ $# -eq 2 ]]||usage 2; require uv
|
||||
scripts/package-reports.sh "$1" "$2"
|
||||
;;
|
||||
test)
|
||||
|
|
@ -52,7 +52,7 @@ case "$command_name" in
|
|||
[[ $# -eq 0 ]]||usage 2
|
||||
require git typst
|
||||
echo "Core tools are available."
|
||||
for optional in uv tar gzip openssl; do
|
||||
for optional in uv; do
|
||||
if command -v "$optional" >/dev/null 2>&1; then "$optional" --version 2>/dev/null | head -n 1 || true; else echo "Optional tool missing: $optional"; fi
|
||||
done
|
||||
;;
|
||||
|
|
|
|||
|
|
@ -1,20 +1,49 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
set +x
|
||||
: "${REPORT_ARCHIVE_PASSWORD:?Set REPORT_ARCHIVE_PASSWORD to encrypt publication archives}"
|
||||
: "${REPORT_ZIP_PASSWORD:?Set REPORT_ZIP_PASSWORD to encrypt publication archives}"
|
||||
build_root=${1:-}; artifact_dir=${2:-}
|
||||
[[ -n "$build_root" && -n "$artifact_dir" && $# -eq 2 ]]||{ echo "Usage: $0 BUILD_ROOT ARTIFACT_DIR" >&2; exit 2; }
|
||||
build_root=$(realpath "$build_root"); mkdir -p "$artifact_dir"; artifact_dir=$(realpath "$artifact_dir")
|
||||
for command in tar gzip openssl; do command -v "$command" >/dev/null||{ echo "$command is required" >&2; exit 1; }; done
|
||||
stage=$(mktemp -d "${TMPDIR:-/tmp}/report-package.XXXXXXXX"); trap 'rm -rf "$stage"' EXIT
|
||||
for category in Reports Diagnostics; do
|
||||
source_dir="$build_root/${category,,}/pdfs"; [[ -d "$source_dir" ]]||source_dir="$build_root/${category,,}"
|
||||
count=0
|
||||
while IFS= read -r -d '' pdf; do [[ -s "$pdf" && $(head -c 5 "$pdf") == '%PDF-' ]]||{ echo "Invalid PDF: $pdf" >&2; exit 1; }; ((count+=1)); done < <(find "$source_dir" -type f -name '*.pdf' -print0)
|
||||
((count > 0))||{ echo "No PDFs for $category" >&2; exit 1; }
|
||||
tar -C "$source_dir" -czf "$stage/$category.tar.gz" .
|
||||
openssl enc -aes-256-cbc -salt -pbkdf2 -pass env:REPORT_ARCHIVE_PASSWORD -in "$stage/$category.tar.gz" -out "$artifact_dir/$category.tar.gz.enc"
|
||||
openssl enc -d -aes-256-cbc -pbkdf2 -pass env:REPORT_ARCHIVE_PASSWORD -in "$artifact_dir/$category.tar.gz.enc" -out "$stage/$category.verify.tar.gz"
|
||||
tar -tzf "$stage/$category.verify.tar.gz" >/dev/null
|
||||
done
|
||||
echo "Created encrypted report archives in $artifact_dir"
|
||||
command -v uv >/dev/null || { echo "uv is required" >&2; exit 1; }
|
||||
mkdir -p "$artifact_dir"
|
||||
|
||||
# Packaging dependencies belong to this tool and are resolved in uv's cache.
|
||||
uv run --isolated --with pyzipper==0.3.6 python - "$build_root" "$artifact_dir" <<'PY'
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pyzipper
|
||||
|
||||
build_root = Path(sys.argv[1]).resolve()
|
||||
artifact_dir = Path(sys.argv[2]).resolve()
|
||||
password = os.environ["REPORT_ZIP_PASSWORD"].encode()
|
||||
|
||||
for category in ("Reports", "Diagnostics"):
|
||||
source_dir = build_root / category.lower() / "pdfs"
|
||||
if not source_dir.is_dir():
|
||||
source_dir = build_root / category.lower()
|
||||
|
||||
pdfs = sorted(path for path in source_dir.rglob("*.pdf") if path.is_file())
|
||||
if not pdfs:
|
||||
raise SystemExit(f"No PDFs for {category}")
|
||||
for pdf in pdfs:
|
||||
if not pdf.read_bytes().startswith(b"%PDF-"):
|
||||
raise SystemExit(f"Invalid PDF: {pdf}")
|
||||
|
||||
archive = artifact_dir / f"{category}.zip"
|
||||
with pyzipper.AESZipFile(
|
||||
archive, "w", compression=pyzipper.ZIP_DEFLATED, encryption=pyzipper.WZ_AES
|
||||
) as output:
|
||||
output.setpassword(password)
|
||||
output.setencryption(pyzipper.WZ_AES, nbits=256)
|
||||
for pdf in pdfs:
|
||||
output.write(pdf, pdf.relative_to(source_dir))
|
||||
|
||||
with pyzipper.AESZipFile(archive) as check:
|
||||
check.setpassword(password)
|
||||
if check.testzip() is not None:
|
||||
raise SystemExit(f"Archive verification failed: {archive}")
|
||||
|
||||
print(f"Created encrypted report archives in {artifact_dir}")
|
||||
PY
|
||||
|
|
|
|||
Loading…
Reference in New Issue