2020-03-23 15:30:14 +01:00
|
|
|
import groovy.transform.Field
|
|
|
|
|
2020-06-11 18:19:14 +02:00
|
|
|
public static @Field PR_CHANGES_CACHE = []
|
2020-03-12 16:06:53 +01:00
|
|
|
|
2020-07-16 21:17:39 +02:00
|
|
|
// if all the changed files in a PR match one of these regular
|
|
|
|
// expressions then CI will be skipped for that PR
|
2020-03-12 16:06:53 +01:00
|
|
|
def getSkippablePaths() {
|
|
|
|
return [
|
|
|
|
/^docs\//,
|
|
|
|
/^rfcs\//,
|
|
|
|
/^.ci\/.+\.yml$/,
|
2020-05-04 20:08:50 +02:00
|
|
|
/^.ci\/es-snapshots\//,
|
2020-06-11 18:19:14 +02:00
|
|
|
/^.ci\/pipeline-library\//,
|
2020-08-18 05:48:22 +02:00
|
|
|
/^.ci\/Jenkinsfile_[^\/]+$/,
|
2020-03-12 16:06:53 +01:00
|
|
|
/^\.github\//,
|
|
|
|
/\.md$/,
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2020-07-16 21:17:39 +02:00
|
|
|
// exclusion regular expressions that will invalidate paths that
|
|
|
|
// match one of the skippable path regular expressions
|
|
|
|
def getNotSkippablePaths() {
|
|
|
|
return [
|
|
|
|
// this file is auto-generated and changes to it need to be validated with CI
|
|
|
|
/^docs\/developer\/architecture\/code-exploration.asciidoc$/,
|
2020-08-05 21:05:17 +02:00
|
|
|
// don't skip CI on prs with changes to plugin readme files (?i) is for case-insensitive matching
|
|
|
|
/(?i)\/plugins\/[^\/]+\/readme\.(md|asciidoc)$/,
|
2020-07-16 21:17:39 +02:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2020-03-12 16:06:53 +01:00
|
|
|
def areChangesSkippable() {
|
|
|
|
if (!githubPr.isPr()) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
def skippablePaths = getSkippablePaths()
|
2020-07-16 21:17:39 +02:00
|
|
|
def notSkippablePaths = getNotSkippablePaths()
|
2020-03-12 16:06:53 +01:00
|
|
|
def files = getChangedFiles()
|
|
|
|
|
|
|
|
// 3000 is the max files GH API will return
|
|
|
|
if (files.size() >= 3000) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
files = files.findAll { file ->
|
2020-07-16 21:17:39 +02:00
|
|
|
def skippable = skippablePaths.find { regex -> file =~ regex} && !notSkippablePaths.find { regex -> file =~ regex }
|
|
|
|
return !skippable
|
2020-03-12 16:06:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return files.size() < 1
|
|
|
|
} catch (ex) {
|
|
|
|
buildUtils.printStacktrace(ex)
|
|
|
|
print "Error while checking to see if CI is skippable based on changes. Will run CI."
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def getChanges() {
|
2020-03-23 15:30:14 +01:00
|
|
|
if (!PR_CHANGES_CACHE && env.ghprbPullId) {
|
|
|
|
withGithubCredentials {
|
2020-06-11 18:19:14 +02:00
|
|
|
def changes = githubPrs.getChanges(env.ghprbPullId)
|
|
|
|
if (changes) {
|
|
|
|
PR_CHANGES_CACHE.addAll(changes)
|
|
|
|
}
|
2020-03-23 15:30:14 +01:00
|
|
|
}
|
2020-03-12 16:06:53 +01:00
|
|
|
}
|
2020-03-23 15:30:14 +01:00
|
|
|
|
|
|
|
return PR_CHANGES_CACHE
|
2020-03-12 16:06:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
def getChangedFiles() {
|
|
|
|
def changes = getChanges()
|
|
|
|
def changedFiles = changes.collect { it.filename }
|
|
|
|
def renamedFiles = changes.collect { it.previousFilename }.findAll { it }
|
|
|
|
|
|
|
|
return changedFiles + renamedFiles
|
|
|
|
}
|
|
|
|
|
|
|
|
return this
|