diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2a26387..634d691 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.11", "3.13"] + python-version: ["3.11", "3.13"] steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 282a7f1..c8dbfaa 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,21 +1,46 @@ name: Publish -# Builds and publishes to PyPI when a GitHub Release is published. -# Uses PyPI Trusted Publishing (OIDC) — no API token stored in the repo. -# Configure the trusted publisher once at: +# Publishes to PyPI when a merge to main changes the version in +# src/cloro/_version.py, then creates the vX.Y.Z tag and GitHub Release. +# A Release published by hand also publishes, as before. +# Uses PyPI Trusted Publishing (OIDC): no API token is stored in the repo. +# The trusted publisher is configured at: # https://pypi.org/manage/project/cloro/settings/publishing/ on: + push: + branches: [main] release: types: [published] workflow_dispatch: jobs: + check: + if: github.event_name == 'push' + runs-on: ubuntu-latest + outputs: + version: ${{ steps.v.outputs.version }} + new: ${{ steps.v.outputs.new }} + steps: + - uses: actions/checkout@v4 + - id: v + run: | + version=$(sed -n 's/^__version__ = "\(.*\)"/\1/p' src/cloro/_version.py) + echo "version=$version" >> "$GITHUB_OUTPUT" + if git ls-remote --exit-code --tags origin "refs/tags/v$version" > /dev/null; then + echo "new=false" >> "$GITHUB_OUTPUT" + else + echo "new=true" >> "$GITHUB_OUTPUT" + fi + build-and-publish: + needs: check + if: always() && (github.event_name != 'push' || needs.check.outputs.new == 'true') runs-on: ubuntu-latest environment: pypi permissions: id-token: write # required for Trusted Publishing + contents: write # required to create the release steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 @@ -29,3 +54,8 @@ jobs: uses: pypa/gh-action-pypi-publish@release/v1 with: skip-existing: true + - name: Create the GitHub release + if: github.event_name == 'push' + env: + GH_TOKEN: ${{ github.token }} + run: gh release create "v${{ needs.check.outputs.version }}" --target "$GITHUB_SHA" --title "v${{ needs.check.outputs.version }}" --generate-notes