From caef84cebbb8d6ac272e0627befdcc0f588120ec Mon Sep 17 00:00:00 2001 From: Mike Gerber Date: Fri, 4 Aug 2023 16:10:54 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20GitHub=20Actions:=20Add=20releas?= =?UTF-8?q?e=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release-check-version-tag | 14 +++++ .github/workflows/release.yml | 58 +++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100755 .github/workflows/release-check-version-tag create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release-check-version-tag b/.github/workflows/release-check-version-tag new file mode 100755 index 0000000..7348a42 --- /dev/null +++ b/.github/workflows/release-check-version-tag @@ -0,0 +1,14 @@ +#!/bin/bash + +# We call setuptools.setup() here as we may rely on setuptools to interpret +# a dynamic version field. (Reading pyproject.toml is not enough in that case.) +expected_git_tag="v$(python -c 'from setuptools import setup; setup()' --version)" +actual_git_tag="$(git describe --tags)" + +if [[ "$expected_git_tag" == "$actual_git_tag" ]]; then + echo "OK: Python package version $expected_git_tag matches git tag" + exit 0 +else + echo "ERROR: Python package version $expected_git_tag does NOT match git tag $actual_git_tag" + exit 1 +fi diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..5d5bfcb --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,58 @@ +name: release + +on: + push: + tags: + - "v*.*.*" + +env: + PYPI_URL: https://pypi.org/p/dinglehopper + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Check git tag vs package version + run: python3 -m pip install --upgrade setuptools && .github/workflows/release-check-version-tag + - name: Build package + run: python3 -m pip install --upgrade build && python3 -m build + - name: Test + run: python3 -m pip install -r requirements-dev.txt && pytest + - name: Upload dist + uses: actions/upload-artifact@v3 + with: + name: dist + path: dist/ + + github-release: + needs: build + runs-on: ubuntu-latest + steps: + - name: Download dist + uses: actions/download-artifact@v3 + with: + name: dist + path: dist/ + - name: Create release on GitHub + uses: softprops/action-gh-release@v1 + with: + files: dist/* + + pypi-publish: + needs: build + runs-on: ubuntu-latest + environment: + name: pypi + url: ${{ env.PYPI_URL }} + permissions: + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing + steps: + - name: Download dist + uses: actions/download-artifact@v3 + with: + name: dist + path: dist/ + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1