From bc256ea026c71d79b6a3343a494c9eadb487ea34 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Tue, 7 Sep 2021 21:21:28 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20MAINTAIN:=20Add=20release=20work?= =?UTF-8?q?flow=20(#117)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/check_release_tag.py | 19 ++++++++ .github/workflows/release.yml | 62 ++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 .github/workflows/check_release_tag.py create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/check_release_tag.py b/.github/workflows/check_release_tag.py new file mode 100644 index 0000000..da36956 --- /dev/null +++ b/.github/workflows/check_release_tag.py @@ -0,0 +1,19 @@ +"""Check that the GitHub release tag matches the package version.""" +import argparse +import pathlib +import re + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("GITHUB_REF", help="The GITHUB_REF environmental variable") + parser.add_argument("INIT_PATH", help="Path to the init file") + args = parser.parse_args() + assert args.GITHUB_REF.startswith( + "refs/tags/v" + ), f'GITHUB_REF should start with "refs/tags/v": {args.GITHUB_REF}' + tag_version = args.GITHUB_REF[11:] + data = pathlib.Path(args.INIT_PATH).read_text("utf8") + pypi_version = re.search(r"__version__ = ['\"](.*?)['\"]", data).group(1) + assert ( + tag_version == pypi_version + ), f"The tag version {tag_version} != {pypi_version} specified in {args.INIT_PATH}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..b1c5bff --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,62 @@ +name: release + +# Automate deployment to PyPI when creating a release tag vX.Y.Z +# will only be published to PyPI if the git tag matches the release version +# and the pre-commit and tests pass + +on: + push: + tags: + - "v[0-9]+.[0-9]+.[0-9]+*" + +jobs: + + check-release-tag: + + # Only run this job on the main repository and not on forks + if: github.repository == 'aiidateam/disk-objectstore' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - run: python .github/workflows/check_release_tag.py $GITHUB_REF disk_objectstore/__init__.py + + pre-commit: + + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - uses: pre-commit/action@v2.0.0 + + publish: + + name: Publish to PyPI + needs: [check-release-tag, pre-commit] + runs-on: ubuntu-latest + + steps: + - name: Checkout source + uses: actions/checkout@v2 + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Build package + run: | + pip install wheel + python setup.py sdist bdist_wheel + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@v1.1.0 + with: + user: __token__ + password: ${{ secrets.PYPI_KEY }}