def infer_function_environment_from_ci_environment(): import os import re from semver import Version # CircleCI is supported though contributions are welcome for other CI's. tag = os.environ["CIRCLE_TAG"] match = re.search(r"([a-z0-9-]+)@(.+)$", tag) if not match: raise ValueError( f'Malformed tag: {tag} (expected e.g. "[email protected]")') function_name, version = match.groups() if not Version.isvalid(version): raise ValueError(f"Version in tag {version} is not valid semver") return InferredFunctionEnvironment( function_name=function_name, version=version, sha1=None, )
def test_should_versioninfo_isvalid(): assert Version.isvalid("1.0.0") is True assert Version.isvalid("foo") is False