forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprChanges.groovy
82 lines (69 loc) · 2.06 KB
/
prChanges.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import groovy.transform.Field
public static @Field PR_CHANGES_CACHE = []
// if all the changed files in a PR match one of these regular
// expressions then CI will be skipped for that PR
def getSkippablePaths() {
return [
/^docs\//,
/^rfcs\//,
/^.ci\/.+\.yml$/,
/^.ci\/es-snapshots\//,
/^.ci\/pipeline-library\//,
/^.ci\/Jenkinsfile_[^\/]+$/,
/^\.github\//,
/\.md$/,
/^\.backportrc\.json$/,
/^\.buildkite\//,
]
}
// 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\/plugin-list.asciidoc$/,
// don't skip CI on prs with changes to plugin readme files (?i) is for case-insensitive matching
/(?i)\/plugins\/[^\/]+\/readme\.(md|asciidoc)$/,
]
}
def areChangesSkippable() {
if (!githubPr.isPr()) {
return false
}
try {
def skippablePaths = getSkippablePaths()
def notSkippablePaths = getNotSkippablePaths()
def files = getChangedFiles()
// 3000 is the max files GH API will return
if (files.size() >= 3000) {
return false
}
files = files.findAll { file ->
def skippable = skippablePaths.find { regex -> file =~ regex} && !notSkippablePaths.find { regex -> file =~ regex }
return !skippable
}
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() {
if (!PR_CHANGES_CACHE && env.ghprbPullId) {
withGithubCredentials {
def changes = githubPrs.getChanges(env.ghprbPullId)
if (changes) {
PR_CHANGES_CACHE.addAll(changes)
}
}
}
return PR_CHANGES_CACHE
}
def getChangedFiles() {
def changes = getChanges()
def changedFiles = changes.collect { it.filename }
def renamedFiles = changes.collect { it.previousFilename }.findAll { it }
return changedFiles + renamedFiles
}
return this