Skip to content

Commit

Permalink
Moved verify changes to shared libraries.
Browse files Browse the repository at this point in the history
  • Loading branch information
serban-nicusor-toptal committed Mar 20, 2020
1 parent 0cda64d commit 966907b
Showing 1 changed file with 10 additions and 64 deletions.
74 changes: 10 additions & 64 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import org.stan.Utils

def utils = new org.stan.Utils()
def skipRemainingStages = false

def setupCXX(failOnError = true) {
errorStr = failOnError ? "-Werror " : ""
writeFile(file: "make/local", text: "CXX=${env.CXX} ${errorStr}")
}


def runTests(String testPath, Boolean separateMakeStep=true) {
if (separateMakeStep) {
sh "./runTests.py -j${env.PARALLEL} ${testPath} --make-only"
Expand All @@ -30,24 +30,6 @@ def deleteDirWin() {
deleteDir()
}

def sourceCodePaths(){
// These paths will be passed to git diff
// If there are changes to them, CI/CD will continue else skip
def paths = ['make', 'src/stan', 'src/test', 'Jenkinsfile', 'makefile', 'runTests.py',
'lib/stan_math/stan', 'lib/stan_math/make', 'lib/stan_math/lib', 'lib/stan_math/test',
'lib/stan_math/runTests.py', 'lib/stan_math/runChecks.py', 'lib/stan_math/makefile',
'lib/stan_math/Jenkinsfile', 'lib/stan_math/.clang-format'
]

def bashArray = ""

for(path in paths){
bashArray += path + (path != paths[paths.size() - 1] ? " " : "")
}

return bashArray
}

String cmdstan_pr() { params.cmdstan_pr ?: "downstream_tests" }
String stan_pr() {
if (env.BRANCH_NAME == 'downstream_tests') {
Expand All @@ -73,9 +55,6 @@ pipeline {
string(defaultValue: 'downstream_tests', name: 'cmdstan_pr',
description: 'PR to test CmdStan upstream against e.g. PR-630')
}
environment {
scPaths = sourceCodePaths()
}
options {
skipDefaultCheckout()
preserveStashes(buildCount: 7)
Expand Down Expand Up @@ -188,48 +167,15 @@ pipeline {
retry(3) { checkout scm }
sh 'git clean -xffd'

def commitHash = sh(script: "git rev-parse HEAD | tr '\\n' ' '", returnStdout: true)
def changeTarget = ""

if (env.CHANGE_TARGET) {
println "This build is a PR, checking out target branch to compare changes."
changeTarget = env.CHANGE_TARGET
sh(script: "git pull && git checkout ${changeTarget}", returnStdout: false)
}
else{
println "This build is not PR, checking out current branch and extract HEAD^1 commit to compare changes or develop when downstream_tests."
if (env.BRANCH_NAME == "downstream_tests"){
sh(script: "git checkout develop && git pull", returnStdout: false)
changeTarget = sh(script: "git rev-parse HEAD^1 | tr '\\n' ' '", returnStdout: true)
sh(script: "git checkout ${commitHash}", returnStdout: false)
}
else{
sh(script: "git pull && git checkout ${env.BRANCH_NAME}", returnStdout: false)
changeTarget = sh(script: "git rev-parse HEAD^1 | tr '\\n' ' '", returnStdout: true)
}
}

println "Comparing differences between current ${commitHash} and target ${changeTarget}."

def bashScript = """
for i in ${env.scPaths};
do
git diff ${commitHash} ${changeTarget} -- \$i
done
"""

def differences = sh(script: bashScript, returnStdout: true)
// These paths will be passed to git diff
// If there are changes to them, CI/CD will continue else skip
def paths = ['make', 'src/stan', 'src/test', 'Jenkinsfile', 'makefile', 'runTests.py',
'lib/stan_math/stan', 'lib/stan_math/make', 'lib/stan_math/lib', 'lib/stan_math/test',
'lib/stan_math/runTests.py', 'lib/stan_math/runChecks.py', 'lib/stan_math/makefile',
'lib/stan_math/Jenkinsfile', 'lib/stan_math/.clang-format'
].join(" ")

println differences

if (differences?.trim()) {
println "There are differences in the source code, CI/CD will run."
skipRemainingStages = false
}
else{
println "There aren't any differences in the source code, CI/CD will not run."
skipRemainingStages = true
}
skipRemainingStages = utils.verifyChanges(paths)
}
}
post {
Expand Down Expand Up @@ -352,4 +298,4 @@ pipeline {
unstable { script { utils.mailBuildResults("UNSTABLE", "stan-buildbot@googlegroups.com") } }
failure { script { utils.mailBuildResults("FAILURE", "stan-buildbot@googlegroups.com") } }
}
}
}

0 comments on commit 966907b

Please sign in to comment.