mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[Core] Add dynamic versioning based on git tag (#790)
This commit is contained in:
parent
03791b9fbc
commit
80756ba490
@ -1 +1,37 @@
|
|||||||
from core.config import Config
|
from core.config import Config
|
||||||
|
from subprocess import run, PIPE
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
__all__ = ["Config", "__version__"]
|
||||||
|
version_info = namedtuple("VersionInfo", "major minor patch")
|
||||||
|
|
||||||
|
BASE_VERSION = version_info(3, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
|
def get_latest_version():
|
||||||
|
try:
|
||||||
|
p = run(
|
||||||
|
"git describe --abbrev=0 --tags".split(),
|
||||||
|
stdout=PIPE
|
||||||
|
)
|
||||||
|
except FileNotFoundError:
|
||||||
|
# No git
|
||||||
|
return BASE_VERSION
|
||||||
|
|
||||||
|
if p.returncode != 0:
|
||||||
|
return BASE_VERSION
|
||||||
|
|
||||||
|
stdout = p.stdout.strip().decode()
|
||||||
|
if stdout.startswith("v"):
|
||||||
|
numbers = stdout[1:].split('.')
|
||||||
|
args = [0, 0, 0]
|
||||||
|
for i in range(3):
|
||||||
|
try:
|
||||||
|
args[i] = int(numbers[i])
|
||||||
|
except (IndexError, ValueError):
|
||||||
|
args[i] = 0
|
||||||
|
return version_info(*args)
|
||||||
|
return BASE_VERSION
|
||||||
|
|
||||||
|
__version__ = get_latest_version()
|
||||||
|
|
||||||
|
|||||||
6
tests/core/test_version.py
Normal file
6
tests/core/test_version.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import core
|
||||||
|
|
||||||
|
|
||||||
|
def test_version_working():
|
||||||
|
assert hasattr(core, '__version__')
|
||||||
|
assert core.__version__ >= (3, 0, 0)
|
||||||
Loading…
x
Reference in New Issue
Block a user