diff --git a/Jenkinsfile b/Jenkinsfile index 0a5f1cb39..461b79616 100755 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -18,7 +18,7 @@ // That PR should be landed with out deleting the PR branch. // Then a second PR submitted to comment out the @Library line, and when it // is landed, both PR branches can be deleted. -//@Library(value='pipeline-lib@my_branch_name') _ +@Library(value='pipeline-lib@osalyk/SRE-322') _ /* groovylint-disable-next-line CompileStatic */ job_status_internal = [:] diff --git a/vars/getCommitTags.groovy b/vars/getCommitTags.groovy new file mode 100755 index 000000000..e9e9c4e3e --- /dev/null +++ b/vars/getCommitTags.groovy @@ -0,0 +1,22 @@ +// vars/getCommitTags.groovy + + +def call() { + def commitMsg = sh( + script: "git log -1 --pretty=%B", + returnStdout: true + ).trim() + + def commitTags = [] + + commitMsg.split("\n").each { line -> + if (line.toLowerCase().startsWith("test-tag:")) { + def value = line.split(":", 2)[1].trim() + if (value) { + commitTags.addAll(value.split()) + } + } + } + + return commitTags as Set +} diff --git a/vars/getTestTag.groovy b/vars/getTestTag.groovy new file mode 100755 index 000000000..3abfbffab --- /dev/null +++ b/vars/getTestTag.groovy @@ -0,0 +1,56 @@ +// vars/getTestTag.groovy + + +def call(Map commitPragmaMapping, List paths, String defaultTag = 'pr') { + + def commitTags = getCommitTags() as Set + + def allTags = [] as Set + allTags.addAll(commitTags) + + def ftestTagMap = new org.example.ftest.FtestTagMap( + org.example.ftest.FtestTagMap.allFtestPythonFiles() + ) + + paths.each { path -> + commitPragmaMapping.each { pattern, config -> + if (path ==~ /${pattern}/) { + + def testTagConfig = config.get('test-tag', defaultTag) + + if (testTagConfig instanceof String) { + testTagConfig = [ + tags: testTagConfig, + handler: 'direct' + ] + } + + def handler = testTagConfig.handler + + if (handler == 'FtestTagMap') { + try { + allTags.addAll(ftestTagMap.minimalTags(path)) + } catch (Exception e) { + allTags.addAll(testTagConfig.tags.split(' ')) + } + } else if (handler == 'direct') { + allTags.addAll(testTagConfig.tags.split(' ')) + } else { + error "Invalid handler: ${handler}" + } + + if (testTagConfig.get('stop_on_match', config.get('stop_on_match', false))) { + return + } + } + } + } + + def validTags = ftestTagMap.uniqueTags() + invalid = allTags - validTags + if (invalid) { + error "test-tag does not match any tests: ${invalid.join(', ')}" + } + + return allTags.sort().join(' ') +}