|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + |
| 10 | +jobs: |
| 11 | + build: |
| 12 | + name: Build distributions |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: Set up Python |
| 22 | + uses: actions/setup-python@v5 |
| 23 | + with: |
| 24 | + python-version: "3.13" |
| 25 | + |
| 26 | + - name: Set up uv |
| 27 | + uses: astral-sh/setup-uv@v8.1.0 |
| 28 | + with: |
| 29 | + enable-cache: true |
| 30 | + |
| 31 | + - name: Validate release tag matches package version |
| 32 | + env: |
| 33 | + RELEASE_TAG: ${{ github.event.release.tag_name }} |
| 34 | + run: | |
| 35 | + set -euo pipefail |
| 36 | + PACKAGE_VERSION="$(python -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])')" |
| 37 | + EXPECTED_TAG="v${PACKAGE_VERSION}" |
| 38 | +
|
| 39 | + if [ "${RELEASE_TAG}" != "${EXPECTED_TAG}" ]; then |
| 40 | + echo "Release tag ${RELEASE_TAG} does not match expected tag ${EXPECTED_TAG} derived from project version ${PACKAGE_VERSION}." |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | +
|
| 44 | + - name: Validate release commit is on main |
| 45 | + env: |
| 46 | + RELEASE_TAG: ${{ github.event.release.tag_name }} |
| 47 | + run: | |
| 48 | + set -euo pipefail |
| 49 | + git fetch --no-tags origin main |
| 50 | + RELEASE_SHA="$(git rev-list -n 1 "refs/tags/${RELEASE_TAG}")" |
| 51 | +
|
| 52 | + if ! git merge-base --is-ancestor "${RELEASE_SHA}" origin/main; then |
| 53 | + echo "Release tag ${RELEASE_TAG} points to commit ${RELEASE_SHA}, which is not contained in origin/main." |
| 54 | + exit 1 |
| 55 | + fi |
| 56 | +
|
| 57 | + - name: Build source distribution and wheel |
| 58 | + run: uv build --sdist --wheel --out-dir dist |
| 59 | + |
| 60 | + - name: Validate built artifacts |
| 61 | + run: uvx twine check dist/* |
| 62 | + |
| 63 | + - name: Upload built distributions |
| 64 | + uses: actions/upload-artifact@v4 |
| 65 | + with: |
| 66 | + name: python-package-distributions |
| 67 | + path: dist/ |
| 68 | + |
| 69 | + publish: |
| 70 | + name: Publish to PyPI |
| 71 | + runs-on: ubuntu-latest |
| 72 | + needs: build |
| 73 | + environment: |
| 74 | + name: pypi |
| 75 | + url: https://pypi.org/project/wagtail-honeypot/ |
| 76 | + permissions: |
| 77 | + id-token: write |
| 78 | + |
| 79 | + steps: |
| 80 | + - name: Download built distributions |
| 81 | + uses: actions/download-artifact@v4 |
| 82 | + with: |
| 83 | + name: python-package-distributions |
| 84 | + path: dist/ |
| 85 | + |
| 86 | + - name: Publish distributions to PyPI |
| 87 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 88 | + with: |
| 89 | + packages-dir: dist/ |
0 commit comments