fader_master/Jenkinsfile

295 lines
11 KiB
Groovy

// Add this webhook in Gitea:
// http://192.168.1.37:8080/gitea-webhook/post
pipeline {
agent { label 'rust_nodocker' }
options {
disableConcurrentBuilds()
skipDefaultCheckout(true)
timeout(time: 45, unit: 'MINUTES')
timestamps()
}
parameters {
booleanParam(
name: 'ENABLE_NATIVE_BACKENDS',
defaultValue: false,
description: 'Run Linux-only MIDI/Pulse gates after the worker has been migrated and provisioned.'
)
}
environment {
ENABLE_NATIVE_BACKENDS = "${params.ENABLE_NATIVE_BACKENDS ?: false}"
CARGO_TERM_COLOR = 'never'
RUST_BACKTRACE = '1'
CARGO_TARGET_DIR = "${WORKSPACE}/target-ci"
BADGE_OWNER = 'MadGobblins'
BADGE_PROJECT = 'fader_master'
BADGE_DEFAULT_BRANCH = 'main'
BADGE_PUBLICATION_ROOT = '/mnt/assets/coverage'
COVERAGE_MIN_LINES = '20'
CARGO_LLVM_COV_VERSION = '0.9.1'
RUSTUP_TOOLCHAIN = '1.88.0'
}
stages {
stage('Checkout') {
steps {
checkout scm
sh '''
set -eu
git submodule sync --recursive
git submodule update --init --recursive
rm -rf coverage
mkdir -p coverage
'''
}
}
stage('Setup Rust') {
steps {
sh '''
set -eu
if ! command -v rustup >/dev/null 2>&1; then
echo 'ERROR: rustup is required on the Jenkins worker.' >&2
exit 1
fi
if [ "${ENABLE_NATIVE_BACKENDS}" = true ]; then
rustup toolchain install "${RUSTUP_TOOLCHAIN}" \
--profile minimal \
--component rustfmt \
--component clippy \
--component llvm-tools-preview
else
rustup toolchain install "${RUSTUP_TOOLCHAIN}" \
--profile minimal \
--component rustfmt \
--component clippy
fi
if [ "${ENABLE_NATIVE_BACKENDS}" = true ]; then
if ! cargo llvm-cov --version 2>/dev/null \
| grep -F "cargo-llvm-cov ${CARGO_LLVM_COV_VERSION}" >/dev/null; then
cargo install cargo-llvm-cov \
--version "${CARGO_LLVM_COV_VERSION}" \
--locked
fi
fi
rustc --version
cargo --version
rustfmt --version
cargo clippy --version
if [ "${ENABLE_NATIVE_BACKENDS}" = true ]; then
cargo llvm-cov --version
else
echo 'Native backend and coverage gates are disabled for this portable build.'
fi
'''
}
}
stage('CI Script Tests') {
steps {
sh '''
set -eu
scripts/test-ci.sh
'''
}
}
stage('Format') {
steps {
sh '''
set -eu
cargo fmt --all -- --check
'''
}
}
stage('Check') {
when { expression { params.ENABLE_NATIVE_BACKENDS } }
steps {
sh '''
set -eu
pkg-config --exists alsa libpulse libudev dbus-1
command -v dbus-run-session
cargo check --workspace --all-targets --locked
cargo check --workspace --all-targets --no-default-features --locked
cargo check --workspace --all-targets --all-features --locked
'''
}
}
stage('Tests') {
when { expression { params.ENABLE_NATIVE_BACKENDS } }
steps {
sh '''
set -eu
cargo test --workspace --all-targets --locked
cargo test --workspace --all-targets --no-default-features --locked
cargo test --workspace --all-targets --all-features --locked
dbus-run-session -- cargo test -p fader_master private_bus --locked -- --ignored
: >"coverage/.tests-passed-${BUILD_NUMBER}"
'''
}
}
stage('Portable Rust Gates') {
when { expression { !params.ENABLE_NATIVE_BACKENDS } }
steps {
sh '''
set -eu
cargo check -p fader-core -p fader-config -p midi -p volume_lib -p tui -p media \
--all-targets --no-default-features --locked
cargo test -p fader-core -p fader-config -p midi -p volume_lib -p tui -p media \
--all-targets --no-default-features --locked
cargo test -p fader-core -p fader-config -p midi -p volume_lib -p tui -p media \
--doc --no-default-features --locked
RUSTDOCFLAGS='-D warnings' \
cargo doc -p fader-core -p fader-config -p midi -p volume_lib -p tui -p media \
--no-deps --no-default-features --locked
cargo clippy -p fader-core -p fader-config -p midi -p volume_lib -p tui -p media \
--all-targets --no-default-features --locked -- -D warnings
cargo build -p fader-core -p fader-config -p midi -p volume_lib -p tui -p media \
--release --no-default-features --locked
: >"coverage/.tests-passed-${BUILD_NUMBER}"
'''
}
}
stage('Coverage') {
when { expression { params.ENABLE_NATIVE_BACKENDS } }
steps {
sh '''
scripts/ci-run-coverage.sh \
"${COVERAGE_MIN_LINES}" \
coverage/llvm-cov-summary.json \
"coverage/.coverage-ready-${BUILD_NUMBER}" \
coverage/coverage-status.txt
'''
}
}
stage('Documentation') {
when { expression { params.ENABLE_NATIVE_BACKENDS } }
steps {
sh '''
set -eu
cargo test --workspace --doc --all-features --locked
RUSTDOCFLAGS='-D warnings' \
cargo doc --workspace --no-deps --all-features --locked
'''
}
}
stage('Clippy') {
when { expression { params.ENABLE_NATIVE_BACKENDS } }
steps {
sh '''
set -eu
cargo clippy \
--workspace \
--all-targets \
--all-features \
--locked \
-- \
-D warnings
'''
}
}
stage('Build Release') {
when { expression { params.ENABLE_NATIVE_BACKENDS } }
steps {
sh '''
set -eu
cargo build --workspace --locked
cargo build --workspace --release --all-features --locked
BINARY="${CARGO_TARGET_DIR}/release/fader_master"
if [ ! -x "${BINARY}" ]; then
echo "ERROR: expected release binary is missing or not executable: ${BINARY}" >&2
exit 1
fi
ls -lh "${BINARY}"
file "${BINARY}" || true
ldd "${BINARY}" || true
'''
}
}
}
post {
cleanup {
script {
sh '''
set -eu
scripts/ci-finalize-badges.sh "${BUILD_NUMBER}"
'''
archiveArtifacts(
allowEmptyArchive: false,
artifacts: 'coverage/coverage.svg,coverage/test.svg,coverage/version.svg',
fingerprint: true
)
def ciBranch = env.BRANCH_NAME
if (!ciBranch && env.GIT_BRANCH) {
ciBranch = env.GIT_BRANCH
.replaceFirst(/^refs\/remotes\/origin\//, '')
.replaceFirst(/^origin\//, '')
}
if (ciBranch == env.BADGE_DEFAULT_BRANCH) {
sh '''
set -eu
scripts/ci-publish-badges.sh \
"${BADGE_PUBLICATION_ROOT}" \
"${BADGE_OWNER}" \
"${BADGE_PROJECT}" \
"${BADGE_DEFAULT_BRANCH}" \
coverage test version
'''
} else if (ciBranch) {
echo "Not publishing mutable badges from non-default branch ${ciBranch}."
} else {
echo 'Not publishing mutable badges: BRANCH_NAME and GIT_BRANCH are unavailable.'
}
def nativeBackends = params.ENABLE_NATIVE_BACKENDS
def coverageStatus = fileExists('coverage/coverage-status.txt')
? readFile('coverage/coverage-status.txt').trim()
: nativeBackends
? "Line coverage: unavailable; required minimum: ${env.COVERAGE_MIN_LINES}%; reason: the coverage stage did not produce a status"
: 'Line coverage: unavailable; portable FreeBSD gates intentionally exclude the Linux-only executable and native backends'
def passed = currentBuild.currentResult == 'SUCCESS'
def gateSummary = nativeBackends
? 'Full Linux/native formatting, checks, tests, coverage, documentation, Clippy, and release gates were evaluated.'
: 'Portable formatting, checks, tests, documentation, Clippy, and release-library gates were evaluated; Linux-only executable and native backend gates were skipped.'
publishChecks(
conclusion: passed ? 'SUCCESS' : 'FAILURE',
name: 'Rust CI',
summary: passed ? 'fader_master passed its selected CI mode.' : 'fader_master failed CI.',
text: "${gateSummary} ${coverageStatus}",
title: passed ? (nativeBackends ? 'Native Build Successful' : 'Portable Build Successful') : 'Build Failed'
)
echo "${passed ? 'fader_master passed its selected CI mode.' : 'fader_master CI failed.'} ${gateSummary} ${coverageStatus}"
sh 'rm -f coverage/coverage-status.txt'
}
deleteDir()
}
}
}