Update Jenkinsfile
Config CI Configuration sanity checks passed.
Dandaedre/configs/pipeline/head This commit looks good Details

This commit is contained in:
Dandaedre 2026-09-13 21:43:53 +02:00
parent 23371ded1e
commit e3784f2859
1 changed files with 75 additions and 165 deletions

240
Jenkinsfile vendored
View File

@ -5,11 +5,7 @@ pipeline {
agent { label 'rust_nodocker' }
environment {
CARGO_TERM_COLOR = 'never'
PYTHONUNBUFFERED = '1'
// Keep Zellij from touching the Jenkins user's real config.
CI_HOME = "${WORKSPACE}/.ci-home"
}
stages {
@ -26,97 +22,91 @@ pipeline {
}
}
stage('Setup') {
stage('Validate Configs') {
steps {
sh '''
set -eu
echo "Checking required tools..."
if ! command -v git >/dev/null 2>&1; then
echo "ERROR: git is not installed." >&2
exit 1
fi
if ! command -v python3 >/dev/null 2>&1; then
echo "ERROR: python3 is not installed." >&2
echo "ERROR: python3 is required." >&2
exit 1
fi
echo
echo "Git:"
git --version
echo
echo "Python:"
python3 --version
# ---------------------------------------------------------
# Zellij
# ---------------------------------------------------------
if ! command -v zellij >/dev/null 2>&1; then
echo
echo "Zellij not found — installing it..."
if ! command -v cargo-binstall >/dev/null 2>&1; then
echo "cargo-binstall not found — installing it..."
cargo install cargo-binstall
fi
cargo binstall \
--no-confirm \
zellij
fi
echo
echo "Zellij:"
zellij --version
# Clean isolated HOME for config validation.
rm -rf "${CI_HOME}"
mkdir -p "${CI_HOME}"
'''
}
}
stage('Validate TOML') {
steps {
sh '''
set -eu
echo "Validating TOML files..."
echo "Validating configuration files..."
python3 <<'PY'
import sys
import tomllib
from pathlib import Path
files = sorted(Path(".").glob("*.toml"))
if not files:
print("ERROR: no TOML files found.", file=sys.stderr)
sys.exit(1)
import tomllib
failed = False
for path in files:
print(f"Checking {path}...")
# ------------------------------------------------------------
# TOML
# ------------------------------------------------------------
toml_files = sorted(Path(".").rglob("*.toml"))
for path in toml_files:
print(f"[TOML] {path}")
try:
with path.open("rb") as f:
tomllib.load(f)
except Exception as exc:
print(f"ERROR: {path}: {exc}", file=sys.stderr)
print(f"ERROR: invalid TOML: {path}: {exc}", file=sys.stderr)
failed = True
# ------------------------------------------------------------
# YAML
# ------------------------------------------------------------
yaml_files = sorted(
list(Path(".").rglob("*.yaml")) +
list(Path(".").rglob("*.yml"))
)
if yaml_files:
try:
import yaml
except ImportError:
print(
"ERROR: YAML files found but PyYAML is not installed.",
file=sys.stderr,
)
print(
"Install it on the worker with: python3 -m pip install pyyaml",
file=sys.stderr,
)
failed = True
else:
print(f"OK: {path}")
for path in yaml_files:
print(f"[YAML] {path}")
try:
with path.open("r", encoding="utf-8") as f:
list(yaml.safe_load_all(f))
except Exception as exc:
print(
f"ERROR: invalid YAML: {path}: {exc}",
file=sys.stderr,
)
failed = True
# ------------------------------------------------------------
# Summary
# ------------------------------------------------------------
print()
print(f"TOML files checked: {len(toml_files)}")
print(f"YAML files checked: {len(yaml_files)}")
if failed:
sys.exit(1)
print()
print(f"{len(files)} TOML file(s) valid.")
print("Structured config files are syntactically valid.")
PY
'''
}
@ -127,79 +117,17 @@ PY
sh '''
set -eu
if [ ! -f gitconfig ]; then
echo "ERROR: gitconfig is missing." >&2
exit 1
if [ -f gitconfig ]; then
echo "Checking gitconfig..."
git config \
--file gitconfig \
--list >/dev/null
echo "gitconfig is valid."
else
echo "No gitconfig found — skipping."
fi
echo "Validating gitconfig..."
# Ask Git itself to parse the configuration.
#
# --list forces Git to read all entries.
# --file prevents the worker's own Git config from being
# involved in the check.
git config \
--file gitconfig \
--list >/dev/null
echo "OK: gitconfig"
'''
}
}
stage('Validate Zellij Config') {
steps {
sh '''
set -eu
if [ ! -f zellij.kdl ]; then
echo "ERROR: zellij.kdl is missing." >&2
exit 1
fi
echo "Validating zellij.kdl..."
CONFIG_DIR="${CI_HOME}/.config/zellij"
mkdir -p "${CONFIG_DIR}"
cp zellij.kdl "${CONFIG_DIR}/config.kdl"
# Use an isolated HOME so Zellij only sees the repository
# configuration and cannot accidentally validate/use the
# Jenkins worker's personal config.
HOME="${CI_HOME}" \
ZELLIJ_CONFIG_DIR="${CONFIG_DIR}" \
zellij setup --check
echo
echo "OK: zellij.kdl"
'''
}
}
stage('Repository Sanity') {
steps {
sh '''
set -eu
echo "Checking known configuration files..."
for file in \
alacritty.toml \
gitconfig \
helix.toml \
languages.toml \
zellij.kdl
do
if [ ! -f "${file}" ]; then
echo "ERROR: expected config is missing: ${file}" >&2
exit 1
fi
done
echo
echo "All expected configuration files are present."
'''
}
}
@ -210,42 +138,24 @@ PY
publishChecks(
conclusion: 'SUCCESS',
name: 'Config CI',
summary: 'All configuration files are valid.',
text: 'TOML files, Git configuration, and Zellij KDL configuration passed syntax/parser validation.',
summary: 'Configuration sanity checks passed.',
text: 'TOML, YAML where present, and Git configuration passed basic syntax validation.',
title: 'Configs Valid'
)
echo '✅ All configuration files are valid.'
echo '✅ Config sanity checks passed.'
}
failure {
publishChecks(
conclusion: 'FAILURE',
name: 'Config CI',
summary: 'A configuration file is invalid.',
text: 'TOML parsing, Git configuration parsing, Zellij validation, or repository sanity checks failed. Check the Jenkins log.',
summary: 'Configuration sanity checks failed.',
text: 'At least one TOML, YAML, or Git configuration file failed syntax validation.',
title: 'Invalid Config'
)
echo '❌ Configuration validation failed.'
}
unstable {
publishChecks(
conclusion: 'ACTION_REQUIRED',
name: 'Config CI',
summary: 'Configuration CI is unstable.',
text: 'The Jenkins build completed with an unstable status.',
title: 'Config CI Unstable'
)
echo '⚠️ Configuration CI is unstable.'
}
always {
sh '''
rm -rf .ci-home
'''
echo '❌ Config sanity checks failed.'
}
}
}