251 lines
6.9 KiB
Groovy
251 lines
6.9 KiB
Groovy
// Add this webhook in Gitea:
|
|
// http://192.168.1.37:8080/gitea-webhook/post
|
|
|
|
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 {
|
|
stage('Checkout') {
|
|
steps {
|
|
checkout scm
|
|
|
|
sh '''
|
|
set -eu
|
|
|
|
git submodule sync --recursive
|
|
git submodule update --init --recursive
|
|
'''
|
|
}
|
|
}
|
|
|
|
stage('Setup') {
|
|
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
|
|
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..."
|
|
|
|
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)
|
|
|
|
failed = False
|
|
|
|
for path in files:
|
|
print(f"Checking {path}...")
|
|
|
|
try:
|
|
with path.open("rb") as f:
|
|
tomllib.load(f)
|
|
except Exception as exc:
|
|
print(f"ERROR: {path}: {exc}", file=sys.stderr)
|
|
failed = True
|
|
else:
|
|
print(f"OK: {path}")
|
|
|
|
if failed:
|
|
sys.exit(1)
|
|
|
|
print()
|
|
print(f"{len(files)} TOML file(s) valid.")
|
|
PY
|
|
'''
|
|
}
|
|
}
|
|
|
|
stage('Validate Git Config') {
|
|
steps {
|
|
sh '''
|
|
set -eu
|
|
|
|
if [ ! -f gitconfig ]; then
|
|
echo "ERROR: gitconfig is missing." >&2
|
|
exit 1
|
|
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."
|
|
'''
|
|
}
|
|
}
|
|
}
|
|
|
|
post {
|
|
success {
|
|
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.',
|
|
title: 'Configs Valid'
|
|
)
|
|
|
|
echo '✅ All configuration files are valid.'
|
|
}
|
|
|
|
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.',
|
|
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
|
|
'''
|
|
}
|
|
}
|
|
} |