From 0f3cf48c0e4b75c2a785f1f95bd5b99a94e80416 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 1 Dec 2023 16:00:29 +0100 Subject: [PATCH] update CI --- automation/Dockerfile | 10 +++- automation/Jenkinsfile | 123 ++++++++++++++++++++++++----------------- coverage.py | 6 ++ 3 files changed, 88 insertions(+), 51 deletions(-) diff --git a/automation/Dockerfile b/automation/Dockerfile index 09132c5..1e0c30a 100644 --- a/automation/Dockerfile +++ b/automation/Dockerfile @@ -6,10 +6,18 @@ RUN apt-get update RUN apt-get --yes upgrade # tzdata is a dependency, won't install otherwise ARG DEBIAN_FRONTEND=noninteractive +RUN apt-get --yes install rsync # set CROSS_CONTAINER_IN_CONTAINER to inform `cross` that it is executed from within a container ENV CROSS_CONTAINER_IN_CONTAINER=true RUN rustup install nightly && \ rustup target add thumbv7em-none-eabihf armv7-unknown-linux-gnueabihf && \ - rustup component add rustfmt clippy + rustup component add rustfmt clippy llvm-tools-preview + +# SSH stuff to allow deployment to doc server +RUN adduser --uid 114 jenkins + +# Add documentation server to known hosts +RUN echo "|1|/LzCV4BuTmTb2wKnD146l9fTKgQ=|NJJtVjvWbtRt8OYqFgcYRnMQyVw= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNL8ssTonYtgiR/6RRlSIK9WU1ywOcJmxFTLcEblAwH7oifZzmYq3XRfwXrgfMpylEfMFYfCU8JRqtmi19xc21A=" >> /etc/ssh/ssh_known_hosts +RUN echo "|1|CcBvBc3EG03G+XM5rqRHs6gK/Gg=|oGeJQ+1I8NGI2THIkJsW92DpTzs= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNL8ssTonYtgiR/6RRlSIK9WU1ywOcJmxFTLcEblAwH7oifZzmYq3XRfwXrgfMpylEfMFYfCU8JRqtmi19xc21A=" >> /etc/ssh/ssh_known_hosts diff --git a/automation/Jenkinsfile b/automation/Jenkinsfile index b9d4ea4..bf0078f 100644 --- a/automation/Jenkinsfile +++ b/automation/Jenkinsfile @@ -1,57 +1,80 @@ pipeline { - agent { - dockerfile { - dir 'automation' - reuseNode true - } + agent { + dockerfile { + dir 'automation' + reuseNode true + args '--network host' } + } - stages { - stage('Rust Toolchain Info') { - steps { - sh 'rustc --version' - } - } - stage('Clippy') { - steps { - sh 'cargo clippy' - } - } - stage('Docs') { - steps { - sh 'cargo +nightly doc --all-features' - } - } - stage('Rustfmt') { - steps { - sh 'cargo fmt --all --check' - } - } - stage('Test') { - steps { - sh 'cargo test --all-features' - } - } - stage('Check with all features') { - steps { - sh 'cargo check --all-features' - } - } - stage('Check with no features') { - steps { - sh 'cargo check --no-default-features' - } - } - stage('Check Cross Embedded Bare Metal') { - steps { - sh 'cargo check --target thumbv7em-none-eabihf --no-default-features' - } - } - stage('Check Cross Embedded Linux') { - steps { - sh 'cargo check --target armv7-unknown-linux-gnueabihf' - } + stages { + stage('Rust Toolchain Info') { + steps { + sh 'rustc --version' + } + } + stage('Clippy') { + steps { + sh 'cargo clippy' + } + } + stage('Docs') { + steps { + sh 'cargo +nightly doc --all-features' } } + stage('Rustfmt') { + steps { + sh 'cargo fmt --all --check' + } + } + stage('Test') { + steps { + sh 'cargo test --all-features' + } + } + stage('Check with all features') { + steps { + sh 'cargo check --all-features' + } + } + stage('Check with no features') { + steps { + sh 'cargo check --no-default-features' + } + } + stage('Check Cross Embedded Bare Metal') { + steps { + sh 'cargo check --target thumbv7em-none-eabihf --no-default-features' + } + } + stage('Check Cross Embedded Linux') { + steps { + sh 'cargo check --target armv7-unknown-linux-gnueabihf' + } + } + stage('Run test with Coverage') { + when { + anyOf { + branch 'main'; + branch pattern: 'cov-deployment*' + } + } + steps { + script { + withEnv(['RUSTFLAGS=-Cinstrument-coverage', 'LLVM_PROFILE_FILE=target/coverage/%p-%m.profraw']) { + echo "Executing tests with coverage" + sh 'cargo test' + sh 'grcov . -s . --binary-path ./target/debug -t html --branch --ignore-not-existing -o ./target/debug/coverage/' + + sshagent(credentials: ['documentation-buildfix']) { + // Deploy to Apache webserver + sh 'rsync -r --delete buildfix@documentation.irs.uni-stuttgart.de:/projects/spacepackets-rs/coverage/latest' + } + } + } + } + } + } } diff --git a/coverage.py b/coverage.py index b7210a4..8e1b845 100755 --- a/coverage.py +++ b/coverage.py @@ -1,12 +1,17 @@ #!/usr/bin/env python3 import os +import logging import argparse import webbrowser +_LOGGER = logging.getLogger() + def generate_cov_report(open_report: bool): + logging.basicConfig(level=logging.INFO) os.environ["RUSTFLAGS"] = "-Cinstrument-coverage" os.environ["LLVM_PROFILE_FILE"] = "target/coverage/%p-%m.profraw" + _LOGGER.info("Executing tests with coverage") os.system("cargo test") os.system( "grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing " @@ -15,6 +20,7 @@ def generate_cov_report(open_report: bool): if open_report: coverage_report_path = os.path.abspath("./target/debug/coverage/index.html") webbrowser.open_new_tab(coverage_report_path) + _LOGGER.info("Done") def main():