Skip to content

Commit

Permalink
Raise ValueError on misspecified version.
Browse files Browse the repository at this point in the history
  • Loading branch information
tillahoffmann committed Jul 6, 2022
1 parent 0697dcd commit 2228e46
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@
import re


ref = os.environ.get("GITHUB_REF", "")
match = re.match(r"^/refs/tags/([\d\.]+)$", ref)
if match:
version = match.group(1)
with open("VERSION", "w") as fp:
fp.write(version)
print(f"wrote version {version} to VERSION file")
print(f"cannot extract version from ref {ref}")
def __main__():
try:
ref = os.environ["GITHUB_REF"]
except KeyError:
print("GITHUB_REF environment variable is not defined")
return

match = re.match(r"^refs/tags/(\d+\.\d+\.\d+)$", ref)
if match:
version = match.group(1)
with open("VERSION", "w") as fp:
fp.write(version)
print(f"wrote version {version} to VERSION file")
else:
raise ValueError(f"cannot extract version from ref {ref}")


if __name__ == "__main__":
__main__()

0 comments on commit 2228e46

Please sign in to comment.