From ef72c7a1102d52d66da6db3b718bdf6f44446b6e Mon Sep 17 00:00:00 2001 From: gusto Date: Mon, 7 Aug 2023 18:39:24 +0300 Subject: [PATCH] Add ci build steps for libp2p node version (#290) * Add ci build steps for libp2p node version * Update ci/Jenkinsfile.nightly.integration Co-authored-by: Youngjoon Lee * Fix typos * Use features in cargo check * Feature and testcase matrix for integration tests * Use jenkins matrix to seperate steps for different features --------- Co-authored-by: Youngjoon Lee --- ci/Jenkinsfile.nightly.integration | 70 ++++++++++++++++++------------ ci/Jenkinsfile.prs.linux | 44 ++++++++++++------- ci/Jenkinsfile.prs.macos | 46 ++++++++++++-------- 3 files changed, 100 insertions(+), 60 deletions(-) diff --git a/ci/Jenkinsfile.nightly.integration b/ci/Jenkinsfile.nightly.integration index 0ee85987..e7b9b499 100644 --- a/ci/Jenkinsfile.nightly.integration +++ b/ci/Jenkinsfile.nightly.integration @@ -30,34 +30,23 @@ pipeline { } stages { - stage('Build') { - steps { - /* Node binary is required for integration tests */ - sh 'cargo build' - } - } + stage('Integration Tests') { + matrix { + axes { + axis { + name 'FEATURE' + values 'waku', 'libp2p' + } + } + stages { + stage('BuildAndTest') { + steps { + script { + /* To prevent rebuilding node for each test, tests are defined here */ + def tests = ['ten_nodes_happy', 'two_nodes_happy', 'ten_nodes_one_down'] - stage('Integration tests') { - steps { - script { - int iterations = params.ITERATIONS.toInteger() - - for (int i = 0; i < iterations; i++) { - echo "Running iteration ${i + 1} of ${iterations}" - - if (sh(script: 'cargo test ten_nodes_happy', returnStatus: true) != 0) { - error("Test failed on iteration ${i + 1}") - break - } - - if (sh(script: 'cargo test two_nodes_happy', returnStatus: true) != 0) { - error("Test failed on iteration ${i + 1}") - break - } - - if (sh(script: 'cargo test ten_nodes_one_down', returnStatus: true) != 0) { - error("Test failed on iteration ${i + 1}") - break + runBuildAndTestsForFeature(FEATURE, tests) + } } } } @@ -82,3 +71,30 @@ pipeline { } } +def runBuildAndTestsForFeature(feature, tests) { + echo "Building node for feature: ${feature}" + def build_cmd = "cargo build -p nomos-node --features ${feature}" + + if (sh(script: build_cmd, returnStatus: true) != 0) { + error("Build '${feature}' node failed") + return + } + + int iterations = params.ITERATIONS.toInteger() + runTestCases(tests, iterations) +} + +def runTestCases(test_cases, iterations) { + for (int i = 0; i < iterations; i++) { + echo "Running iteration ${i + 1} of ${iterations}" + + for (test_case in test_cases) { + def test_cmd = "cargo test -p tests --features ${feature} ${test_case}" + if (sh(script: test_cmd, returnStatus: true) != 0) { + error("Test '${test_case}' failed on iteration ${i + 1}") + return + } + } + } +} + diff --git a/ci/Jenkinsfile.prs.linux b/ci/Jenkinsfile.prs.linux index 814026ca..d5cd9649 100644 --- a/ci/Jenkinsfile.prs.linux +++ b/ci/Jenkinsfile.prs.linux @@ -21,24 +21,36 @@ pipeline { } stages { - stage('Check') { - steps { - sh 'cargo check --all --all-features' - sh 'cargo fmt -- --check' - sh 'cargo clippy --all --all-features -- --deny warnings' - } - } + stage('BuildAndTest') { + matrix { + axes { + axis { + name 'FEATURES' + values 'waku', 'libp2p' + } + } + stages { + stage('Check') { + steps { + sh "cargo check --all --features ${FEATURES}" + sh "cargo fmt -- --check" + sh "cargo clippy --all --features ${FEATURES} -- --deny warnings" + } + } - stage('Build') { - steps { - sh 'cargo build' - sh 'cargo build --all --all-features' - } - } + stage('Build') { + steps { + sh "cargo build" + sh "cargo build --all --features ${FEATURES}" + } + } - stage('Test') { - steps { - sh 'cargo test --all --all-features' + stage('Test') { + steps { + sh "cargo test --all --features ${FEATURES}" + } + } + } } } } diff --git a/ci/Jenkinsfile.prs.macos b/ci/Jenkinsfile.prs.macos index da7b8dd6..ad1d50fe 100644 --- a/ci/Jenkinsfile.prs.macos +++ b/ci/Jenkinsfile.prs.macos @@ -20,25 +20,37 @@ pipeline { } stages { - stage('Check') { - steps { script { - nix.shell('cargo check --all --all-features') - nix.shell('cargo fmt -- --check') - nix.shell('cargo clippy --all --all-features -- --deny warnings') - } } - } + stage('BuildAndTest') { + matrix { + axes { + axis { + name 'FEATURES' + values 'waku', 'libp2p' + } + } + stages { + stage('Check') { + steps { script { + nix.shell("cargo check --all --features ${FEATURES}") + nix.shell("cargo fmt -- --check") + nix.shell("cargo clippy --all --features ${FEATURES} -- --deny warnings") + } } + } - stage('Build') { - steps { script { - nix.shell('cargo build') - nix.shell('cargo build --all --all-features') - } } - } + stage('Build') { + steps { script { + nix.shell("cargo build") + nix.shell("cargo build --all --features ${FEATURES}") + } } + } - stage('Test') { - steps { script { - nix.shell('cargo test --all --all-features') - } } + stage('Test') { + steps { script { + nix.shell("cargo test --all --features ${FEATURES}") + } } + } + } + } } } post {