Skip to content

Commit

Permalink
added semver pattern for the most thorough users
Browse files Browse the repository at this point in the history
  • Loading branch information
why-not-try-calmer committed Oct 2, 2023
1 parent aee77f1 commit 6618d23
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 2 additions & 0 deletions qgispluginci/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class Parameters:
"""

release_version_patterns = {
# See https://github.com/semver/semver/blob/master/semver.md#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
"semver": r"^(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-]+)*))?$",
"v3": re.compile(r"^v\d+\.\d+\.\d+$"),
"v2": re.compile(r"^v\d+\.\d+$"),
"double": re.compile(r"\d+\.\d+\.\d+$"),
Expand Down
16 changes: 5 additions & 11 deletions test/test_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,24 +207,18 @@ def test_release_changelog(self):
self.assertEqual(0, len(re.findall(r"commitSha1=\d+", str(data))))

def test_release_version(self):
patterns = {
"v3": r"^v\d+\.\d+\.\d+$",
"v2": r"^v\d+\.\d+$",
"double": r"\d+\.\d+\.\d+$",
"simple": r"\d+\.\d+$",
}
valid_tags = ["v1.1.1", "v1.1", "1.0.1", "1.1"]
valid_tags = ["v1.1.1", "v1.1", "1.0.1", "1.1", "1.0.0-alpha", "1.0.0-dev"]
invalid_tags = ["1", "v1"]
valid_results = {tag: [] for tag in valid_tags}
invalid_results = {tag: [] for tag in invalid_tags}

for key, cand in product(patterns, valid_results):
if re.match(patterns[key], cand):
for key, cand in product(Parameters.release_version_patterns, valid_results):
if re.match(Parameters.release_version_patterns[key], cand):
valid_results[cand].append(key)
self.assertTrue(all(valid_results.values()))

for key, cand in product(patterns, invalid_results):
if re.match(patterns[key], cand):
for key, cand in product(Parameters.release_version_patterns, invalid_results):
if re.match(Parameters.release_version_patterns[key], cand):
invalid_results[cand].append(key)
self.assertFalse(any(invalid_results.values()))

Expand Down

0 comments on commit 6618d23

Please sign in to comment.