kerrickstaley / genanki

A Python 3 library for generating Anki decks
MIT License
2.06k stars 161 forks source link

Mismatch between git tag v1.13.1 and version 0.13.1 #142

Open bbrewington opened 2 months ago

bbrewington commented 2 months ago
bbrewington commented 2 months ago

Your call on whether to add this to your deploy notes in README.md, or to build into automation, but here's a way you could automate this check (if it's something I can PR in, glad to!)

import re
import subprocess

def get_version_from_file():
    with open('genanki/version.py') as f:
        content = f.read()
    version_match = re.search(r"__version__\s*=\s*['\"]([^'\"]+)['\"]", content)
    if version_match:
        return version_match.group(1)
    raise RuntimeError("Unable to find version string in genanki/version.py")

def get_latest_git_tag():
    try:
        tag = subprocess.check_output(['git', 'describe', '--tags', '--abbrev=0']).decode('utf-8').strip('v\n')
        return tag
    except subprocess.CalledProcessError:
        raise RuntimeError("Unable to get the latest Git tag")

def main():
    file_version = get_version_from_file()
    git_tag_version = get_latest_git_tag()

    if file_version == git_tag_version:
        print(f"Version check passed: {file_version} == {git_tag_version}")
    else:
        raise RuntimeError(f"Version mismatch: {file_version} != {git_tag_version}")

if __name__ == '__main__':
    main()