From: Michael Tremer Date: Wed, 23 Oct 2024 12:43:52 +0000 (+0000) Subject: jenkins: Add LCOV pass and build Debian packages X-Git-Tag: 0.9.30~917 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0b538c51488670a99a84352561cd51d8e823a2e0;p=pakfire.git jenkins: Add LCOV pass and build Debian packages Signed-off-by: Michael Tremer --- diff --git a/Jenkinsfile b/Jenkinsfile index 83bb25245..2a75a3004 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,50 +2,127 @@ pipeline { agent none stages { - /* - Run Pakfire through Clang's Static Analyzer... - */ - stage("Clang Static Analyzer") { - agent { - docker { - image "debian:bookworm-backports" + stage("Coverage Tests") { + parallel { + /* + Run Pakfire through Clang's Static Analyzer... + */ + stage("Clang Static Analyzer") { + agent { + docker { + image "debian:bookworm-backports" - // Run as root inside the containers to install dependencies - args "-u root" + // Run as root inside the containers to install dependencies + args "-u root" - customWorkspace "${JOB_NAME}/${BUILD_ID}/clang-static-analyzer" - } - } + customWorkspace "${JOB_NAME}/${BUILD_ID}/clang-static-analyzer" + } + } - stages { - stage("Install Dependencies") { - steps { - script { - installBuildDepsDebian("bookworm", "clang") + stages { + stage("Install Dependencies") { + steps { + script { + installBuildDepsDebian("bookworm", "clang") - // Install Clang Tools - sh "apt-get install -y clang-tools" + // Install Clang Tools + sh "apt-get install -y clang-tools" + } + } + } + + stage("Configure") { + steps { + sh "./autogen.sh" + sh "scan-build ./configure --prefix=/usr --enable-debug" + } + } + + stage("Build") { + steps { + sh "scan-build -o scan-build-output make" + } } - } - } - stage("Configure") { - steps { - sh "./autogen.sh" - sh "scan-build ./configure --prefix=/usr --enable-debug" + stage("Publish Report") { + steps { + archiveArtifacts artifacts: "scan-build-output/**/*" + } + } } } - stage("Build") { - steps { - sh "scan-build -o scan-build-output make" + stage("LCOV") { + agent { + docker { + image "debian:trixie" + + // Run as root inside the containers to install dependencies + args "-u root" + + customWorkspace "${JOB_NAME}/${BUILD_ID}/lcov" + } } - } - stage("Publish Report") { - steps { - archiveArtifacts artifacts: "scan-build-output/**/*", - allowEmptyArchive: true + stages { + stage("Install Dependencies") { + steps { + script { + installBuildDepsDebian("trixie", "gcc") + + // Install lcov + sh "apt-get install -y lcov" + } + } + } + + stage("Configure") { + steps { + sh "./autogen.sh" + sh """ + CFLAGS="-O2 -g --coverage" \ + ./configure \ + --prefix=/usr \ + --enable-debug + """ + } + } + + stage("Build") { + steps { + sh "make" + } + } + + stage("Check") { + steps { + sh "make check || true" + } + } + + stage("Publish Report") { + steps { + // Capture coverage data + sh """ + lcov \ + --capture \ + --directory . \ + --output-file coverage.info \ + --ignore-errors range,range + """ + + // Generate HTML report + sh """ + genhtml \ + coverage.info \ + --output-directory lcov \ + --ignore-errors range,range + """ + + // Upload the report + archiveArtifacts artifacts: "lcov/**/*" + } + } } } } @@ -156,6 +233,148 @@ pipeline { } } } + + /* + Debian Packages + */ + stage("Build Debian Packages") { + // Only build packages for the master branch + when { + expression { env.BRANCH_NAME == "master" } + } + + matrix { + axes { + axis { + name "IMAGE" + values "debian:trixie", "debian:bookworm-backports" + } + + axis { + name "ARCH" + values "amd64", "arm64" + } + } + + agent { + docker { + image "${IMAGE}" + + // Run as root inside the containers to install dependencies + args "-u root" + + customWorkspace "${JOB_NAME}/${BUILD_ID}/${IMAGE.replace(":", "-")}/${ARCH}" + } + } + + stages { + stage("Setup Build Environment") { + steps { + // Add the architecture + sh "dpkg --add-architecture ${env.ARCH}" + sh "apt-get update" + + // Install required packages + sh """ + apt-get install -y \ + build-essential \ + crossbuild-essential-${env.ARCH} \ + devscripts \ + qemu-user-static + """ + } + } + + stage("Install Build Dependencies") { + steps { + // Install all build dependencies + sh "apt-get build-dep -y -a${env.ARCH} ." + } + } + + stage("Tag") { + steps { + sh "dch -m \"Jenkins Build ${BUILD_ID}\" -l .build-${BUILD_ID}." + } + } + + stage("Build") { + steps { + sh """ + dpkg-buildpackage \ + --host-arch ${env.ARCH} \ + --build=any + + # Move the packages + mkdir -pv uploads + mv -v ../*.deb uploads/ + """ + } + } + + stage("Upload Packages") { + steps { + archiveArtifacts artifacts: "uploads/**" + } + } + + stage("Create Repository") { + environment { + DISTRO = "${IMAGE.replace("debian:", "").replace("-backports", "")}" + } + + steps { + // Create a repository and generate Packages + sh """ + mkdir -pv \ + dists/${DISTRO}/main/binary-${ARCH} \ + pool/${DISTRO}/main/${ARCH} + + # Copy all packages + cp -v uploads/*.deb pool/${DISTRO}/main/${ARCH} + + # Generate Packages.gz + dpkg-scanpackages pool/${DISTRO}/main/${ARCH} \ + | gzip -9 > dists/${DISTRO}/main/binary-${ARCH}/Packages.gz + """ + + // Stash the packages + stash includes: "dists/**/*, pool/**/*", + name: "${DISTRO}-${ARCH}" + } + } + } + } + } + + stage("Update Debian Repository") { + agent { + docker { + image "debian:trixie" + + // Run as root inside the containers to install dependencies + args "-u root" + + customWorkspace "${JOB_NAME}/${BUILD_ID}/update-debian-repo" + } + } + + steps { + // Unstash all stashed packages from the matrix build + script { + for (distro in ["trixie", "bookworm"]) { + for (arch in ["amd64", "arm64"]) { + unstash "${distro}-${arch}" + } + } + } + + // Upload everything again + archiveArtifacts artifacts: "dists/**/*, pool/**/*" + + // XXX This needs to be published on a mirror server somewhere + } + } } }