Skip to content

Commit

Permalink
Merge pull request #21 from nitrictech/feature/auto-version
Browse files Browse the repository at this point in the history
Feature/auto version
  • Loading branch information
tjholm authored Jun 25, 2021
2 parents e850c4c + 50f1d2f commit 9e878f1
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 3 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/draft_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
on:
pull_request:
types: [closed]
branches:
- 'main'

jobs:
version:
if: github.event.pull_request.merged == true
name: Version and Draft Release
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Create a GitHub Draft Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.tag_version.outputs.new_tag }}
release_name: Release ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}
draft: true
prerelease: false
26 changes: 26 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Publish release to Pypi

on:
release:
types: [published]

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
with:
token: ${{secrets.SUBMOD_PAT}}
submodules: recursive
fetch-depth: 0 # needed to retrieve most recent tag
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Build
run: make build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
with:
token: ${{secrets.SUBMOD_PAT}}
submodules: recursive
#lfs: true
fetch-depth: 0 # needed to retrieve most recent tag
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
Expand Down
26 changes: 24 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
import setuptools
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:
return "0.0.0.dev0"


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", "tests.*"]),
license_files=("LICENSE.txt",),
classifiers=[
"Programming Language :: Python :: 3",
Expand Down

0 comments on commit 9e878f1

Please sign in to comment.