forked from linode/linode-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version
executable file
·41 lines (28 loc) · 935 Bytes
/
version
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
# Usage:
# ./bin/version
# Prints the current version
import os
import re
import subprocess
import sys
from distutils.version import LooseVersion
ENV_LINODE_CLI_VERSION = "LINODE_CLI_VERSION"
def get_version_env():
return os.getenv(ENV_LINODE_CLI_VERSION)
def get_version(ref="HEAD"):
# We want to override the version if an environment variable is specified.
# This is useful for certain release and testing pipelines.
describe = get_version_env()
if describe is None:
describe = call('git describe {} --tags'.format(ref))
# Strip the `v` prefix if specified
if describe.startswith("v"):
describe = describe[1:]
parts = LooseVersion(describe).version[:3]
return tuple(parts)
def call(cmd):
_, output = subprocess.getstatusoutput(cmd)
return output
major, minor, patch = get_version()
print("{}.{}.{}".format(major, minor, patch))