From 2151c952c256ead9f215eb2efcdae57609c94bc1 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Thu, 22 Jun 2023 11:30:34 +0200 Subject: [PATCH 1/2] Don't trigger GitHub action twice on pre-releases --- .github/workflows/publish-to-pypi.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 5756a93c..3ff0b24b 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -2,7 +2,7 @@ name: Publish releases to PyPI on: release: - types: [published, prereleased] + types: [published] jobs: build-and-publish: From 1f105811b95dd74f5901c0cdb1b2701b32b2e105 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Thu, 22 Jun 2023 11:17:46 +0200 Subject: [PATCH 2/2] Validate release version --- .github/workflows/publish-to-pypi.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 3ff0b24b..30802f79 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -10,6 +10,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3.5.3 + - name: Get tag + id: vars + run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT - name: Set up Python 3.10 uses: actions/setup-python@v4.6.1 with: @@ -17,6 +20,13 @@ jobs: - name: Install build run: >- pip install build + - name: Validate tag matches Python project version + shell: python + run: |- + import tomli + with open("pyproject.toml", "rb") as f: + pyproject = tomli.load(f) + assert pyproject["project"]["version"] == "${{ steps.vars.outputs.tag }}" - name: Build run: >- python3 -m build