#!/usr/bin/python3

import datetime
import subprocess


def run(*args):
    return subprocess.check_output(args).decode().strip()


# Get a human readable name of this commit:
# - build from tag: v2.4.5
# - build without a tag: v2.4.5-3-gc238eff
commit_name = run("git", "describe",  "--tags", "--match", "v[0-9]*")

if "-" in commit_name:
    # Build without a tag - make this build newer than previous build
    # with a UTC timestamp, and add commit hash to make it easy to
    # locate the commit.
    utc_timestamp = datetime.datetime.utcnow().strftime("%Y%m%d%H%M")
    commit_hash = run("git", "rev-parse", "--short", "HEAD")
    release = f"0.{utc_timestamp}.git{commit_hash}"
else:
    # Build from tag - make this build newer than previous builds
    # without a tag.
    release = "1"

print(release)
