Skip to content

Commit 9e878f1

Browse files
authored
Merge pull request #21 from nitrictech/feature/auto-version
Feature/auto version
2 parents e850c4c + 50f1d2f commit 9e878f1

4 files changed

Lines changed: 81 additions & 3 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
on:
2+
pull_request:
3+
types: [closed]
4+
branches:
5+
- 'main'
6+
7+
jobs:
8+
version:
9+
if: github.event.pull_request.merged == true
10+
name: Version and Draft Release
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v2
16+
- name: Bump version and push tag
17+
id: tag_version
18+
uses: mathieudutour/github-tag-action@v5.5
19+
with:
20+
github_token: ${{ secrets.GITHUB_TOKEN }}
21+
- name: Create a GitHub Draft Release
22+
uses: actions/create-release@v1
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
with:
26+
tag_name: ${{ steps.tag_version.outputs.new_tag }}
27+
release_name: Release ${{ steps.tag_version.outputs.new_tag }}
28+
body: ${{ steps.tag_version.outputs.changelog }}
29+
draft: true
30+
prerelease: false

.github/workflows/publish.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Publish release to Pypi
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v2.3.1
13+
with:
14+
token: ${{secrets.SUBMOD_PAT}}
15+
submodules: recursive
16+
fetch-depth: 0 # needed to retrieve most recent tag
17+
- name: Set up Python 3.8
18+
uses: actions/setup-python@v2
19+
with:
20+
python-version: 3.8
21+
- name: Build
22+
run: make build
23+
- name: Publish to PyPI
24+
uses: pypa/gh-action-pypi-publish@master
25+
with:
26+
password: ${{ secrets.PYPI_API_TOKEN }}

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
with:
1616
token: ${{secrets.SUBMOD_PAT}}
1717
submodules: recursive
18-
#lfs: true
18+
fetch-depth: 0 # needed to retrieve most recent tag
1919
- name: Set up Python ${{ matrix.python-version }}
2020
uses: actions/setup-python@v2
2121
with:

setup.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,40 @@
11
import setuptools
2+
import re
3+
from subprocess import Popen, PIPE
4+
5+
6+
def get_current_version_tag():
7+
process = Popen(["git", "describe", "--tags", "--match", "v[0-9]*"], stdout=PIPE)
8+
(output, err) = process.communicate()
9+
process.wait()
10+
11+
tags = str(output, "utf-8").strip().split("\n")
12+
13+
version_tags = [tag for tag in tags if re.match(r"^v?(\d*\.){2}\d$", tag)]
14+
dev_tags = [tag for tag in tags if re.match(r"^v?(\d*\.){2}\d-\d*-[a-z\d]{8}$", tag)]
15+
16+
if len(version_tags) == 1:
17+
return version_tags.pop()[1:]
18+
elif len(dev_tags) == 1:
19+
base_tag, num_commits = dev_tags.pop().split("-")[:2]
20+
return "{}.dev{}".format(base_tag, num_commits)[1:]
21+
else:
22+
return "0.0.0.dev0"
23+
224

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

628
setuptools.setup(
729
name="nitric",
8-
version="0.1.0",
30+
version=get_current_version_tag(),
931
author="Nitric",
1032
author_email="team@nitric.io",
1133
description="The Nitric SDK for Python 3",
1234
long_description=long_description,
1335
long_description_content_type="text/markdown",
1436
url="https://github.com/nitrictech/python-sdk",
15-
packages=setuptools.find_packages(),
37+
packages=setuptools.find_packages(exclude=["tests", "tests.*"]),
1638
license_files=("LICENSE.txt",),
1739
classifiers=[
1840
"Programming Language :: Python :: 3",

0 commit comments

Comments
 (0)