From 91ba147a7b432b3bb4e3f1b39e4bc794ef5ef882 Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Thu, 20 May 2021 10:40:29 +0200 Subject: [PATCH] Upload to PyPI on release --- .github/workflows/pypi-release.yml | 37 ++++++++++++++++++++++++++++++ MANIFEST.in | 1 + VERSION | 1 + setup.py | 3 ++- 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/pypi-release.yml create mode 100644 VERSION diff --git a/.github/workflows/pypi-release.yml b/.github/workflows/pypi-release.yml new file mode 100644 index 0000000..e2f8687 --- /dev/null +++ b/.github/workflows/pypi-release.yml @@ -0,0 +1,37 @@ +name: PyPI publish on release +on: + release: + types: [published] +defaults: + run: + shell: + bash +jobs: + build-package: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - name: Verify tag matches version + run: | + set -ex + version=$(cat VERSION) + tag="${GITHUB_REF/refs\/tags\/}" + if [[ "v$version" != "$tag" ]]; then + exit 1 + fi + - uses: actions/setup-python@v2 + with: + python-version: 3.9 + - run: | + python -m pip install -U pip setuptools twine + - run: | + python setup.py sdist + - name: Setup PyPI config + run: | + cat << EOF > ~/.pypirc + [pypi] + username=__token__ + password=${{ secrets.PYPI_TOKEN }} + EOF + - run: | + twine upload --repository testpypi dist/*.tar.gz diff --git a/MANIFEST.in b/MANIFEST.in index 1ae57f6..1085f6c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,4 @@ +include VERSION include README.md include LICENSE.txt include requirements*.txt diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..5a5831a --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.0.7 diff --git a/setup.py b/setup.py index 395e653..32eaf13 100644 --- a/setup.py +++ b/setup.py @@ -6,8 +6,9 @@ import setuptools.command.develop from setuptools import find_packages, setup -version = "0.0.7" cwd = os.path.dirname(os.path.abspath(__file__)) +with open(os.path.join(cwd, "VERSION")) as fin: + version = fin.read().strip() class build_py(setuptools.command.build_py.build_py): # pylint: disable=too-many-ancestors