Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved verify changes from Jenkinsfile to Shared Libraries. #2905

Merged
merged 1 commit into from
Mar 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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") } }
}
}
}