From 0d8f4becd0c0d218c1ba49a90645c9357991deae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Thu, 1 Jul 2021 12:40:05 +0200 Subject: [PATCH] ci: build and test only what changed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a pretty cure regex-based test, but should work. For the diff to work this refspec needs to be added to the fetch ``` +refs/heads/master:refs/remotes/@{remote}/master ``` Signed-off-by: Jakub SokoĊ‚owski --- ci/Jenkinsfile.prs | 57 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/ci/Jenkinsfile.prs b/ci/Jenkinsfile.prs index c56cd929e..32714331a 100644 --- a/ci/Jenkinsfile.prs +++ b/ci/Jenkinsfile.prs @@ -41,7 +41,11 @@ pipeline { } stages { - stage('Deps') { steps { + stage('Deps') { steps { script { + /* Avoid checking multiple times. */ + v1changed = versionWasChanged('v1') + v2changed = versionWasChanged('v2') + /* Building Nim compiler takes a while. */ cache(maxCacheSize: 250, caches: [[ $class: 'ArbitraryFileCache', excludes: '', includes: '**/*', path: 'vendor/nimbus-build-system/vendor/Nim/bin', @@ -49,28 +53,43 @@ pipeline { sh "make V=${params.VERBOSITY} update" } sh "make V=${params.VERBOSITY} deps" - } } + } } } stage('Binaries') { parallel { - stage('V1') { steps { sh "make V=${params.VERBOSITY} v1" } } - stage('V2') { steps { sh "make V=${params.VERBOSITY} v2" } } + stage('V1') { + when { expression { v1changed } } + steps { sh "make V=${params.VERBOSITY} v1" } + } + stage('V2') { + when { expression { v2changed } } + steps { sh "make V=${params.VERBOSITY} v2" } + } } } stage('Run Tests') { parallel { - stage('V1') { steps { sh "make V=${params.VERBOSITY} test1" } } - stage('V2') { steps { sh "make V=${params.VERBOSITY} test2" } } + stage('V1') { + when { expression { v1changed } } + steps { sh "make V=${params.VERBOSITY} test1" } + } + stage('V2') { + when { expression { v2changed } } + steps { sh "make V=${params.VERBOSITY} test2" } + } } } - stage('Upload') { steps { script { - def out = genOutputFilename() - sh "mv build/wakunode2 ${out}" - env.PKG_URL = s3.uploadArtifact(out) - jenkins.setBuildDesc(Waku: env.PKG_URL) - } } } + stage('Upload') { + when { expression { v2changed } } + steps { script { + def out = genOutputFilename() + sh "mv build/wakunode2 ${out}" + env.PKG_URL = s3.uploadArtifact(out) + jenkins.setBuildDesc(Waku: env.PKG_URL) + } } + } } // stages post { success { script { github.notifyPR(true) } } @@ -98,3 +117,17 @@ def genOutputFilename() { "wakunode2", utils.timestamp(), utils.gitCommit(), getAgentLabel() ].join('-') + (env.NODE_NAME.startsWith('windows') ? '.exe' : '.bin') } + +def versionWasChanged(version) { + def changes = sh( + script: "git diff --name-only origin/${env.CHANGE_TARGET}", + returnStdout: true + ) + if (changes =~ "(?m)^(Makefile|waku.nimble|config.nims|vendor).*") { + return true + } + if (changes =~ "(?m)^(waku|tests|examples)/(${version}|common)/.*") { + return true + } + return false +}