commit | 70cd333e8741028120e1e6281e332e3428ed289c | [log] [tgz] |
---|---|---|
author | Mykyta Karpin <mkarpin@mirantis.com> | Mon Sep 16 18:31:03 2019 +0300 |
committer | Mykyta Karpin <mkarpin@mirantis.com> | Mon Sep 16 18:31:03 2019 +0300 |
tree | e036dee05fa3e0eeb310a1532078f5b9146b02c4 | |
parent | ce61671a5f5d6182162f70259e95cf32f0c2491a [diff] [blame] |
Method for check compatibility with semver Based on recommended semver regex [1] [1] https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string Change-Id: I1299631c9aa556e1b8dff4a2fa80b0dbb9632b7f Related-Prod: https://mirantis.jira.com/browse/PROD-33012
diff --git a/src/com/mirantis/mk/Common.groovy b/src/com/mirantis/mk/Common.groovy index c0059bb..8eee149 100644 --- a/src/com/mirantis/mk/Common.groovy +++ b/src/com/mirantis/mk/Common.groovy
@@ -1023,3 +1023,14 @@ Random rand = new Random(System.currentTimeMillis()) return (1..n).collect { pool[rand.nextInt(pool.size())] }.join() } + +/** + * Checks whether string is semver complaint version + * @param string version +*/ + +def isSemVer(version){ + // Official regex for Semver2 (https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string) + String semVerRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/ + return version ==~ semVerRegex +} \ No newline at end of file