|
| 1 | +name: Auto release |
| 2 | + |
| 3 | +# Triggers on every push to master. Skips its own version-bump commits to |
| 4 | +# prevent an infinite loop. |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: [master] |
| 8 | + |
| 9 | +jobs: |
| 10 | + release: |
| 11 | + if: "!startsWith(github.event.head_commit.message, 'chore: bump version')" |
| 12 | + runs-on: ubuntu-latest |
| 13 | + environment: pypi |
| 14 | + permissions: |
| 15 | + contents: write # push version-bump commit + tag back to master |
| 16 | + id-token: write # OIDC trusted publishing to PyPI (no token needed) |
| 17 | + |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - uses: actions/setup-python@v5 |
| 24 | + with: |
| 25 | + python-version: "3.11" |
| 26 | + |
| 27 | + - name: Bump patch version |
| 28 | + id: version |
| 29 | + run: | |
| 30 | + python - << 'PYEOF' |
| 31 | + import re, os |
| 32 | + content = open("pyproject.toml").read() |
| 33 | + m = re.search(r'(version = ")(\d+\.\d+\.)(\d+)(")', content) |
| 34 | + new_ver = m.group(2) + str(int(m.group(3)) + 1) |
| 35 | + new_content = re.sub( |
| 36 | + r'(version = ")\d+\.\d+\.\d+(")', |
| 37 | + rf'\g<1>{new_ver}\2', |
| 38 | + content, count=1, |
| 39 | + ) |
| 40 | + open("pyproject.toml", "w").write(new_content) |
| 41 | + with open(os.environ["GITHUB_OUTPUT"], "a") as f: |
| 42 | + f.write(f"version={new_ver}\n") |
| 43 | + print(f"Bumped to {new_ver}") |
| 44 | + PYEOF |
| 45 | +
|
| 46 | + - name: Install build tools |
| 47 | + run: pip install hatchling build |
| 48 | + |
| 49 | + - name: Build |
| 50 | + run: python -m build |
| 51 | + |
| 52 | + - name: Publish to PyPI |
| 53 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 54 | + # Uses OIDC trusted publishing — no API token required. |
| 55 | + # Ensure this repo + workflow is registered at: |
| 56 | + # https://pypi.org/manage/project/vocametrix/settings/publishing/ |
| 57 | + |
| 58 | + - name: Commit version bump and push tag |
| 59 | + run: | |
| 60 | + git config user.name "github-actions[bot]" |
| 61 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 62 | + git add pyproject.toml |
| 63 | + git commit -m "chore: bump version to ${{ steps.version.outputs.version }}" |
| 64 | + git tag "v${{ steps.version.outputs.version }}" |
| 65 | + git push origin master --follow-tags |
0 commit comments