Add Jenkinsfile
Report CI typst_reporter passed all CI checks.
Beffroi/typst_reporter/pipeline/head This commit looks good Details

This commit is contained in:
Dandaedre 2026-09-13 20:48:17 +02:00
parent 51654caf7d
commit 88a9e64add
1 changed files with 303 additions and 0 deletions

303
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,303 @@
// Add this webhook in Gitea:
// http://192.168.1.37:8080/gitea-webhook/post
pipeline {
agent { label 'rust_no_docker' }
environment {
CARGO_TERM_COLOR = 'always'
// CI-only staging directory.
CI_ARTIFACT_DIR = '.ci-artifacts'
}
stages {
stage('Checkout') {
steps {
checkout scm
sh '''
set -eu
git submodule sync --recursive
git submodule update --init --recursive
'''
}
}
stage('Setup Typst') {
steps {
sh '''
set -eu
# ---------------------------------------------------------
# cargo-binstall
# ---------------------------------------------------------
if ! command -v cargo-binstall >/dev/null 2>&1; then
echo "cargo-binstall not found — installing it..."
cargo install cargo-binstall
else
echo "cargo-binstall already installed."
fi
# ---------------------------------------------------------
# Typst
# ---------------------------------------------------------
if ! command -v typst >/dev/null 2>&1; then
echo "Typst not found — installing typst-cli..."
cargo binstall \
--no-confirm \
typst-cli
else
echo "Typst already installed."
fi
echo
echo "Using:"
typst --version
'''
}
}
stage('Validate Scripts') {
steps {
sh '''
set -eu
echo "Checking shell scripts..."
if [ ! -f render.sh ]; then
echo "ERROR: render.sh is missing." >&2
exit 1
fi
bash -n render.sh
if [ ! -x render.sh ]; then
echo "ERROR: render.sh is not executable." >&2
exit 1
fi
echo "render.sh syntax OK."
'''
}
}
stage('Validate Typst Sources') {
steps {
sh '''
set -eu
echo "Checking Typst sources..."
typ_files="$(find . \
-type f \
-name '*.typ' \
-not -path './.git/*')"
if [ -z "${typ_files}" ]; then
echo "ERROR: no Typst source files found." >&2
exit 1
fi
echo "Typst sources:"
echo "${typ_files}"
'''
}
}
stage('Render Reports') {
steps {
sh '''
set -eu
echo "Rendering all reports..."
echo
rm -rf "${CI_ARTIFACT_DIR}"
mkdir -p "${CI_ARTIFACT_DIR}"
# Remove previously generated PDFs so that CI can verify
# that the current build actually produced them.
find . \
-type f \
-name '*.pdf' \
-not -path './.git/*' \
-not -path "./${CI_ARTIFACT_DIR}/*" \
-delete
./render.sh --all
echo
echo "Render complete."
'''
}
}
stage('Collect Reports') {
steps {
sh '''
set -eu
echo "Collecting generated reports..."
count=0
find . \
-type f \
-name '*.pdf' \
-not -path './.git/*' \
-not -path "./${CI_ARTIFACT_DIR}/*" \
-print |
while IFS= read -r pdf; do
relative="${pdf#./}"
destination="${CI_ARTIFACT_DIR}/${relative}"
mkdir -p "$(dirname "${destination}")"
cp "${pdf}" "${destination}"
echo " ${relative}"
done
count="$(find "${CI_ARTIFACT_DIR}" \
-type f \
-name '*.pdf' |
wc -l |
tr -d ' ')"
echo
echo "Generated ${count} PDF report(s)."
if [ "${count}" -eq 0 ]; then
echo "ERROR: render.sh completed but produced no PDFs." >&2
exit 1
fi
'''
}
}
stage('Verify Reports') {
steps {
sh '''
set -eu
echo "Verifying generated PDFs..."
failed=0
find "${CI_ARTIFACT_DIR}" \
-type f \
-name '*.pdf' \
-print |
while IFS= read -r pdf; do
if [ ! -s "${pdf}" ]; then
echo "ERROR: empty PDF: ${pdf}" >&2
failed=1
continue
fi
# PDF files should begin with the PDF magic header.
magic="$(head -c 5 "${pdf}")"
if [ "${magic}" != "%PDF-" ]; then
echo "ERROR: invalid PDF header: ${pdf}" >&2
failed=1
continue
fi
echo "OK: ${pdf}"
done
if [ "${failed}" -ne 0 ]; then
exit 1
fi
echo
echo "All generated reports look valid."
'''
}
}
stage('Publish Reports') {
steps {
sh '''
set -eu
# ---------------------------------------------------------
# REPORT PUBLICATION PLACEHOLDER
# ---------------------------------------------------------
#
# Publishing is deliberately disabled for now.
#
# Generated PDFs are available under:
#
# .ci-artifacts/
#
# Future publication could for example:
#
# - rsync PDFs to the Beffroi report archive
# - copy them to a mounted archive directory
# - upload them to Gitea
# - publish only reports changed by this commit
#
# Do NOT deploy anything from this stage yet.
# ---------------------------------------------------------
echo "Report publication is currently disabled."
echo "Artifacts ready in ${CI_ARTIFACT_DIR}:"
find "${CI_ARTIFACT_DIR}" \
-type f \
-name '*.pdf' \
-print
'''
}
}
}
post {
success {
publishChecks(
conclusion: 'SUCCESS',
name: 'Report CI',
summary: 'typst_reporter passed all CI checks.',
text: 'Shell validation, Typst source checks, report rendering, and PDF validation completed successfully. External publication is disabled.',
title: 'Reports rendered successfully'
)
echo '✅ typst_reporter rendered and validated all reports.'
}
failure {
publishChecks(
conclusion: 'FAILURE',
name: 'Report CI',
summary: 'typst_reporter failed CI.',
text: 'A script validation, Typst compilation, report rendering, or PDF validation step failed. Check the Jenkins log.',
title: 'Report CI failed'
)
echo '❌ typst_reporter CI failed.'
}
unstable {
publishChecks(
conclusion: 'ACTION_REQUIRED',
name: 'Report CI',
summary: 'typst_reporter CI is unstable.',
text: 'The Jenkins build completed with an unstable status.',
title: 'Report CI unstable'
)
echo '⚠️ typst_reporter CI is unstable.'
}
always {
echo 'CI finished.'
}
}
}