-
Notifications
You must be signed in to change notification settings - Fork 4
support exact match in isGitRegionMatch #257
Conversation
After reading the title it was very clear to me the expectation, but it was when I read the implementation when I had doubts about the name of the Is it possible to rename it to make it clear that it will use an AND or an OR to match patterns? I don't like Wdyt? Apart from the above comment, LGTM! 👍 So please let's not block it if the name is accurate for everybody |
60eab99
to
cba0167
Compare
vars/isGitRegionMatch.groovy
Outdated
|
||
*/ | ||
def call(Map params = [:]) { | ||
if(!isUnix()){ | ||
error('isGitRegionMatch: windows is not supported yet.') | ||
} | ||
def regexps = params.containsKey('regexps') ? params.regexps : error('isGitRegionMatch: Missing regexps argument.') | ||
def patterns = params.containsKey('regexps') ? params.regexps : error('isGitRegionMatch: Missing regexps argument.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to rename regexps
as patterns
but it's already used I cannot warranty I'll break some compatibility :(
} | ||
|
||
def isGlob(comparator) { | ||
return comparator.equals('glob') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather compare with the glob
match. Although I could potentially use the Comparator enum if required:
Although for this particular use case we could just leave as it is
|
||
def isGrepPatternFound(compareWith, pattern) { | ||
log(level: 'DEBUG', text: "isGrepPatternFound: '${compareWith}' with pattern: '${pattern}'") | ||
return sh(script: "echo '${compareWith}' | grep '${pattern}'", returnStatus: true) == 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the grep for the given line rather than the given file content
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love to move this logic with some more groovish grep pattern but so far I don't see an easy way to transform the grep in groovy
} | ||
|
||
def isGrepPatternFoundInFile(file, pattern) { | ||
return sh(script: "grep '${pattern}' ${file}", returnStatus: true) == 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the grep for the given file
I need to figure out what's going on with a warning, as it does behave as expected but that particular expected to call log output might to be important to be reviewed
|
I am using it on elastic/beats#14484, so merge, merge, merge 😃 |
#257 (comment) was indeed a genuine failure as ITsGiven v1v/elasticsearch@master...ae8a6f8
|
What does this PR do?
changeset doesn't allow complex match and exact matches.
Potentially it could be added to the jenkins plugin itself but https://issues.jenkins-ci.org/browse/JENKINS-44849 seems to be a blocker in our case, as the very first build won't have any changeset
Extend the current step to support:
regexps
param is not anymore supported butpatterns
is the new oneWith this particular feature, we can look for any patterns that match the existing changeset. Or being more accurate to given a list of patterns whether they all match with every entry in the changeset.
Given the below changeset:
Then:
isGitRegionMatch(patterns: ["^folder**/*"])
-> returnstrue
(GLOB format)isGitRegionMatch(patterns: ["^folder.*"], comparator: 'regex')
-> returnstrue
(REGEXP format)isGitRegionMatch(patterns: [".*/file.*", "folder/.*", "foo/bar/*.txt], comparator: 'regex')
-> returnstrue
(REGEXP format)isGitRegionMatch(patterns: [".*/file.*", "folder/.*", "foo/bar/*.txt], comparator: 'regex', shouldMatchAll: true)
-> returnsfalse
(REGEXP format)isGitRegionMatch(patterns: ["**/file*", "folder/**", "foo/bar/*], shouldMatchAll: true)
-> returnsfalse
(GLOB format)Why is it important?
More granularity when a certain stage should be launched.
See elastic/apm-server#2891
Related issues
Closes #ISSUE
Test Cases
ITs
Given the diff v1v/elasticsearch@master...b49fbe0
isGitRegionMatch(patterns: ["^.ci/*"])
isGitRegionMatch(patterns: ["^.foo/*"])
isGitRegionMatch(patterns: ["^.ci", "**/Jenkinsfile"])
isGitRegionMatch(patterns: ["^.ci", "**/Jenkinsfile"], shouldMatchAll: true)
isGitRegionMatch(patterns: ["^.ci", "**/Jenkinsfile1"], shouldMatchAll: true)
isGitRegionMatch(patterns: ["^.ci.*", ".*/Jenkinsfile"], comparator: 'regex', shouldMatchAll: true)
isGitRegionMatch(patterns: ["^.ci.*", ".*/Jenkinsfile.+"], comparator: 'regex', shouldMatchAll: true)