To use simply run
PACKAGE='<your package name>' python <(curl -Ls https://git.io/JvQsH)
#!/usr/bin/env python3 | |
""" | |
see https://gist.github.com/samuelcolvin/3b662d40e28213fbcd046743cb7068d8 for details | |
""" | |
import os | |
import re | |
import sys | |
from importlib import import_module | |
def main(version_env_var='GITHUB_REF', package_env_var='PACKAGE') -> int: | |
package = os.getenv(package_env_var) | |
if not package: | |
print(f'✖ "{package_env_var}" env variable not found') | |
return 2 | |
module = import_module(package) | |
raw_version = module.VERSION | |
if not isinstance(raw_version, str): | |
print(f'✖ version "{raw_version!r}" is not a string') | |
return 2 | |
version = raw_version.lower() | |
git_ref = os.getenv(version_env_var, 'none') | |
tag = re.sub('^refs/tags/v*', '', git_ref.lower()) | |
if tag == version: | |
print(f'✓ {version_env_var} env var {git_ref!r} matches package version: {tag!r} == {version!r}') | |
return 0 | |
else: | |
print(f'✖ {version_env_var} env var {git_ref!r} does not match package version: {tag!r} != {version!r}') | |
return 1 | |
if __name__ == '__main__': | |
sys.exit(main()) |