From 58dd5f6efeb5dc1418baacfbed2fcc504c5514e6 Mon Sep 17 00:00:00 2001 From: Michael Goerz Date: Wed, 30 Dec 2020 14:02:30 -0500 Subject: [PATCH] Add workflow for pushing to PyPI --- .github/workflows/release.yml | 63 +++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..6d5477f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,63 @@ +name: Release + +on: [push, release] + +# Releases work as follows (driven by ./scripts/release.py): +# +# 1. A non-tagged version with a relase `__version__` (anything not ending in +# `+dev` or `-dev`) is pushed to `master`. Since we always add the `+dev` +# suffix after a release, there will only ever be one such commit per +# release. This commit should trigger a release to Test-PyPI, in this +# workflow. +# +# 2. Once the workflows for the release commit pass, the commit is tagged as +# `v<__version__>` and the tag is pushed to Github. This triggers the +# automatic creation of an official "Release" on Github. +# +# 3. The automatic creation of the Release triggers this workflow again, +# causing a release to the regular PyPI +# + +jobs: + + push_release_to_pypi: + name: Push Package Release to PyPI + runs-on: ubuntu-18.04 + steps: + + - uses: actions/checkout@v2 + + - uses: actions/setup-python@v2 + name: Install Python 3.8 + with: + python-version: 3.8 + + - name: Install Prerequisites + run: pip install wheel twine + + - name: Get the version + id: get_version + run: echo ::set-output name=VERSION::$(python -c 'print([line.split("=")[-1].strip()[1:-1] for line in open("./src/qalgebra/__init__.py", encoding="utf8").readlines() if line.startswith("__version__")][0], end="")') + + - name: Build Source and Wheel Package + run: | + python setup.py sdist + python setup.py bdist_wheel + + - name: Check distribution files + run: twine check dist/* + + - name: Publish package to Test - PyPI (TODO) + if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads') && ! endsWith(steps.get_version.outputs.VERSION, "-dev") && ! endsWith(steps.get_version.outputs.VERSION, "+dev") + # TODO: restrict to master + run: | + echo "This is a non-dev release which should be pushed to Test-PyPI" + + - name: Publish package to PyPI + if: github.event_name == 'release' + uses: pypa/gh-action-pypi-publish@master + # TODO: switch to regular PyPI + with: + user: __token__ + password: ${{ secrets.TEST_PYPI_API_TOKEN }} + repository_url: https://test.pypi.org/legacy/