Skip to content

Commit

Permalink
ci: pull setup.py version from git tag
Browse files Browse the repository at this point in the history
If the current commit isn't tagged a 'dev' tag will be generated from the most recently tag + number of commits
  • Loading branch information
jyecusch committed Jun 25, 2021
1 parent e850c4c commit 74d5ddb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import setuptools
from tools.git_tag import get_current_version_tag

with open("README.md", "r") as readme_file:
long_description = readme_file.read()

setuptools.setup(
name="nitric",
version="0.1.0",
version=get_current_version_tag(),
author="Nitric",
author_email="[email protected]",
description="The Nitric SDK for Python 3",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/nitrictech/python-sdk",
packages=setuptools.find_packages(),
packages=setuptools.find_packages(".", exclude=["tests", "tools"]),
license_files=("LICENSE.txt",),
classifiers=[
"Programming Language :: Python :: 3",
Expand Down
Empty file added tools/__init__.py
Empty file.
21 changes: 21 additions & 0 deletions tools/git_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import re
from subprocess import Popen, PIPE


def get_current_version_tag():
process = Popen(["git", "describe", "--tags", "--match", "v[0-9]*"], stdout=PIPE)
(output, err) = process.communicate()
process.wait()

tags = str(output, "utf-8").strip().split("\n")

version_tags = [tag for tag in tags if re.match(r"^v?(\d*\.){2}\d$", tag)]
dev_tags = [tag for tag in tags if re.match(r"^v?(\d*\.){2}\d-\d*-[a-z\d]{8}$", tag)]

if len(version_tags) == 1:
return version_tags.pop()[1:]
elif len(dev_tags) == 1:
base_tag, num_commits = dev_tags.pop().split("-")[:2]
return "{}.dev{}".format(base_tag, num_commits)[1:]
else:
raise Exception("Unable to determine or construct version from git tags.")

0 comments on commit 74d5ddb

Please sign in to comment.