302 lines
11 KiB
Groovy
302 lines
11 KiB
Groovy
// Add this webhook in Gitea:
|
||
// http://192.168.1.37:8080/gitea-webhook/post
|
||
|
||
pipeline {
|
||
agent { label 'rust_no_docker' }
|
||
|
||
parameters {
|
||
choice(
|
||
name: 'PLAYER_THEME',
|
||
choices: ['warm', 'steel', 'fangdrael', 'bw', 'high-contrast', 'yon-sen', 'steingrund', 'treorst', 'anankar', 'drekinsteps', 'draan'],
|
||
description: 'Color theme for the player handbook.'
|
||
)
|
||
string(
|
||
name: 'PLAYER_CHAPTERS',
|
||
defaultValue: '',
|
||
description: 'Optional comma-separated player-handbook chapter allow-list.'
|
||
)
|
||
string(
|
||
name: 'PLAYER_DISABLED_CHAPTERS',
|
||
defaultValue: '',
|
||
description: 'Optional comma-separated player-handbook chapter deny-list.'
|
||
)
|
||
}
|
||
|
||
environment {
|
||
SOURCE_FILE = "main.typ"
|
||
OUTPUT_FILE = "Ravenous_build.pdf"
|
||
PUBLISHED_FILE = "Ravenous.pdf"
|
||
BALANCE_SOURCE_FILE = "balance_report.typ"
|
||
BALANCE_OUTPUT_FILE = "Ravenous_balance_report_build.pdf"
|
||
BALANCE_PUBLISHED_FILE = "Ravenous_balance_report.pdf"
|
||
MASTER_SOURCE_FILE = "master_handbook.typ"
|
||
MASTER_PLAINTEXT_FILE = "Ravenous_master_handbook_plaintext.pdf"
|
||
MASTER_OUTPUT_FILE = "Ravenous_master_handbook_build.pdf"
|
||
MASTER_PUBLISHED_FILE = "Ravenous_master_handbook.pdf"
|
||
MASTER_BALANCE_SOURCE_FILE = "balance_report_master.typ"
|
||
MASTER_BALANCE_PLAINTEXT_FILE = "Ravenous_master_balance_report_plaintext.pdf"
|
||
MASTER_BALANCE_OUTPUT_FILE = "Ravenous_master_balance_report_build.pdf"
|
||
MASTER_BALANCE_PUBLISHED_FILE = "Ravenous_master_balance_report.pdf"
|
||
PLAYER_SOURCE_FILE = "player_handbook.typ"
|
||
PLAYER_OUTPUT_FILE = "Ravenous_player_handbook_build.pdf"
|
||
PLAYER_PUBLISHED_FILE = "Ravenous_player_handbook.pdf"
|
||
SCREEN_SOURCE_FILE = "master_screen.typ"
|
||
SCREEN_PLAINTEXT_FILE = "Ravenous_master_screen_plaintext.pdf"
|
||
SCREEN_OUTPUT_FILE = "Ravenous_master_screen_build.pdf"
|
||
SCREEN_PUBLISHED_FILE = "Ravenous_master_screen.pdf"
|
||
MASTER_PASSWORD = "billy"
|
||
|
||
// Important: published books live under /mnt/books
|
||
DEPLOY_DIR = "/mnt/books/Ravenous"
|
||
}
|
||
|
||
stages {
|
||
stage('Checkout') {
|
||
steps {
|
||
checkout scm
|
||
|
||
sh '''
|
||
git submodule sync --recursive
|
||
git submodule update --init --recursive
|
||
'''
|
||
}
|
||
}
|
||
|
||
stage('Install Typst') {
|
||
steps {
|
||
sh '''
|
||
set -e
|
||
|
||
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
|
||
|
||
if ! command -v typst >/dev/null 2>&1; then
|
||
echo "Typst not found — installing it..."
|
||
cargo binstall --no-confirm typst-cli
|
||
else
|
||
echo "Typst already installed."
|
||
fi
|
||
|
||
echo "Using:"
|
||
typst --version
|
||
|
||
if ! command -v qpdf >/dev/null 2>&1; then
|
||
echo "qpdf is required to protect the master handbook." >&2
|
||
exit 1
|
||
fi
|
||
|
||
qpdf --version
|
||
'''
|
||
}
|
||
}
|
||
|
||
stage('Build PDFs') {
|
||
steps {
|
||
sh '''
|
||
set -e
|
||
|
||
echo "Generating build metadata"
|
||
./tools/pseudo_toolchain.sh
|
||
|
||
echo "Building ${SOURCE_FILE} -> ${OUTPUT_FILE}"
|
||
typst compile "${SOURCE_FILE}" "${OUTPUT_FILE}"
|
||
|
||
echo "Building ${BALANCE_SOURCE_FILE} -> ${BALANCE_OUTPUT_FILE}"
|
||
typst compile "${BALANCE_SOURCE_FILE}" "${BALANCE_OUTPUT_FILE}"
|
||
|
||
echo "Building ${PLAYER_SOURCE_FILE} -> ${PLAYER_OUTPUT_FILE}"
|
||
typst compile \
|
||
--input preset=player-handbook \
|
||
--input theme="${PLAYER_THEME}" \
|
||
--input chapters="${PLAYER_CHAPTERS}" \
|
||
--input disabled_chapters="${PLAYER_DISABLED_CHAPTERS}" \
|
||
"${PLAYER_SOURCE_FILE}" "${PLAYER_OUTPUT_FILE}"
|
||
|
||
echo "Building ${MASTER_SOURCE_FILE} -> ${MASTER_PLAINTEXT_FILE}"
|
||
typst compile "${MASTER_SOURCE_FILE}" "${MASTER_PLAINTEXT_FILE}"
|
||
|
||
echo "Protecting the master handbook (password: ${MASTER_PASSWORD})"
|
||
qpdf --allow-weak-crypto \
|
||
--encrypt "${MASTER_PASSWORD}" "${MASTER_PASSWORD}" 40 -- \
|
||
"${MASTER_PLAINTEXT_FILE}" "${MASTER_OUTPUT_FILE}"
|
||
|
||
echo "Building ${MASTER_BALANCE_SOURCE_FILE} -> ${MASTER_BALANCE_PLAINTEXT_FILE}"
|
||
typst compile "${MASTER_BALANCE_SOURCE_FILE}" "${MASTER_BALANCE_PLAINTEXT_FILE}"
|
||
|
||
echo "Protecting the master balance report with the master-handbook policy"
|
||
qpdf --allow-weak-crypto \
|
||
--encrypt "${MASTER_PASSWORD}" "${MASTER_PASSWORD}" 40 -- \
|
||
"${MASTER_BALANCE_PLAINTEXT_FILE}" "${MASTER_BALANCE_OUTPUT_FILE}"
|
||
|
||
echo "Building ${SCREEN_SOURCE_FILE} -> ${SCREEN_PLAINTEXT_FILE}"
|
||
typst compile "${SCREEN_SOURCE_FILE}" "${SCREEN_PLAINTEXT_FILE}"
|
||
|
||
echo "Protecting the master screen with the master-handbook policy"
|
||
qpdf --allow-weak-crypto \
|
||
--encrypt "${MASTER_PASSWORD}" "${MASTER_PASSWORD}" 40 -- \
|
||
"${SCREEN_PLAINTEXT_FILE}" "${SCREEN_OUTPUT_FILE}"
|
||
|
||
test -f "${OUTPUT_FILE}"
|
||
test -f "${BALANCE_OUTPUT_FILE}"
|
||
test -f "${PLAYER_OUTPUT_FILE}"
|
||
test -f "${MASTER_OUTPUT_FILE}"
|
||
test -f "${MASTER_BALANCE_OUTPUT_FILE}"
|
||
test -f "${SCREEN_OUTPUT_FILE}"
|
||
|
||
# Never archive or publish unprotected master intermediates.
|
||
rm "${MASTER_PLAINTEXT_FILE}" "${MASTER_BALANCE_PLAINTEXT_FILE}" "${SCREEN_PLAINTEXT_FILE}"
|
||
|
||
echo "Builds complete:"
|
||
ls -lh \
|
||
"${OUTPUT_FILE}" \
|
||
"${BALANCE_OUTPUT_FILE}" \
|
||
"${PLAYER_OUTPUT_FILE}" \
|
||
"${MASTER_OUTPUT_FILE}" \
|
||
"${MASTER_BALANCE_OUTPUT_FILE}" \
|
||
"${SCREEN_OUTPUT_FILE}"
|
||
'''
|
||
}
|
||
}
|
||
|
||
stage('Archive PDFs') {
|
||
steps {
|
||
archiveArtifacts(
|
||
artifacts: "${OUTPUT_FILE},${PLAYER_OUTPUT_FILE},${BALANCE_OUTPUT_FILE},${MASTER_OUTPUT_FILE},${MASTER_BALANCE_OUTPUT_FILE},${SCREEN_OUTPUT_FILE}",
|
||
fingerprint: true
|
||
)
|
||
}
|
||
}
|
||
|
||
stage('Deploy PDFs') {
|
||
steps {
|
||
script {
|
||
def reviewBranches = [
|
||
'origin/lighthouse',
|
||
'lighthouse'
|
||
]
|
||
|
||
def devBranches = [
|
||
'origin/candlelight',
|
||
'candlelight'
|
||
]
|
||
|
||
def masterBranches = [
|
||
'origin/lighthouse',
|
||
'lighthouse'
|
||
]
|
||
|
||
def targetDir
|
||
|
||
if (reviewBranches.contains(env.BRANCH_NAME)) {
|
||
targetDir = "${DEPLOY_DIR}_lighthouse"
|
||
} else if (devBranches.contains(env.BRANCH_NAME)) {
|
||
targetDir = "${DEPLOY_DIR}_candlelight"
|
||
} else if (masterBranches.contains(env.BRANCH_NAME)) {
|
||
targetDir = DEPLOY_DIR
|
||
} else {
|
||
echo "Branch '${env.BRANCH_NAME}' is not a publication branch — skipping deployment."
|
||
return
|
||
}
|
||
|
||
deployTo(targetDir)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
post {
|
||
success {
|
||
publishChecks(
|
||
conclusion: 'SUCCESS',
|
||
name: 'Build Successful',
|
||
summary: 'The Ravenous rulebook, player handbook, master handbook, and balance reports were built successfully.',
|
||
text: 'All six PDFs were compiled and published successfully.',
|
||
title: 'Build Successful'
|
||
)
|
||
|
||
echo '✅ Ravenous books and balance reports built and published!'
|
||
}
|
||
|
||
failure {
|
||
publishChecks(
|
||
conclusion: 'FAILURE',
|
||
name: 'Build Failed',
|
||
summary: 'A Ravenous PDF build or deployment failed.',
|
||
text: 'Rulebook, master-handbook, or balance-report compilation/publication failed.',
|
||
title: 'Build Failed'
|
||
)
|
||
|
||
echo '❌ A Ravenous PDF failed to build or publish.'
|
||
}
|
||
|
||
unstable {
|
||
publishChecks(
|
||
conclusion: 'ACTION_REQUIRED',
|
||
name: 'Build Unstable',
|
||
summary: 'The Ravenous rulebook build is unstable.',
|
||
text: 'The Jenkins build completed with an unstable status.',
|
||
title: 'Build Unstable'
|
||
)
|
||
|
||
echo '⚠️ Ravenous build is unstable.'
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* Publish the generated Ravenous PDFs.
|
||
*
|
||
* Build artifacts retain explicit CI names in Jenkins, while published copies
|
||
* use stable rulebook, master-handbook, and balance-report names. Master-facing
|
||
* PDFs are encrypted before either step.
|
||
*
|
||
* @param targetDir Directory receiving the compiled book.
|
||
*/
|
||
def deployTo(String targetDir) {
|
||
sh """
|
||
set -e
|
||
|
||
echo "Publishing Ravenous, its player and master handbooks, and its balance reports to ${targetDir}"
|
||
|
||
mkdir -p "${targetDir}"
|
||
|
||
rsync -a \
|
||
"${env.OUTPUT_FILE}" \
|
||
"${targetDir}/${env.PUBLISHED_FILE}"
|
||
|
||
rsync -a \
|
||
"${env.BALANCE_OUTPUT_FILE}" \
|
||
"${targetDir}/${env.BALANCE_PUBLISHED_FILE}"
|
||
|
||
rsync -a \
|
||
"${env.PLAYER_OUTPUT_FILE}" \
|
||
"${targetDir}/${env.PLAYER_PUBLISHED_FILE}"
|
||
|
||
rsync -a \
|
||
"${env.MASTER_OUTPUT_FILE}" \
|
||
"${targetDir}/${env.MASTER_PUBLISHED_FILE}"
|
||
|
||
rsync -a \
|
||
"${env.MASTER_BALANCE_OUTPUT_FILE}" \
|
||
"${targetDir}/${env.MASTER_BALANCE_PUBLISHED_FILE}"
|
||
|
||
rsync -a \
|
||
"${env.SCREEN_OUTPUT_FILE}" \
|
||
"${targetDir}/${env.SCREEN_PUBLISHED_FILE}"
|
||
|
||
echo "Published:"
|
||
ls -lh \
|
||
"${targetDir}/${env.PUBLISHED_FILE}" \
|
||
"${targetDir}/${env.BALANCE_PUBLISHED_FILE}" \
|
||
"${targetDir}/${env.PLAYER_PUBLISHED_FILE}" \
|
||
"${targetDir}/${env.MASTER_PUBLISHED_FILE}" \
|
||
"${targetDir}/${env.MASTER_BALANCE_PUBLISHED_FILE}" \
|
||
"${targetDir}/${env.SCREEN_PUBLISHED_FILE}"
|
||
"""
|
||
}
|