Merge pull request #50 from Integration-Automation/dev #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish to PyPI | |
| on: | |
| push: | |
| branches: ["main"] | |
| permissions: | |
| contents: write | |
| concurrency: | |
| group: publish-pypi | |
| cancel-in-progress: false | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| if: "!contains(github.event.head_commit.message, 'chore: bump version')" | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install build tools | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build twine | |
| - name: Bump patch version in stable.toml and dev.toml | |
| id: bump | |
| run: | | |
| python <<'EOF' | |
| import os | |
| import pathlib | |
| import re | |
| def bump(path: pathlib.Path) -> str: | |
| text = path.read_text(encoding="utf-8") | |
| match = re.search(r'^version\s*=\s*"(\d+)\.(\d+)\.(\d+)"', text, re.MULTILINE) | |
| if not match: | |
| raise SystemExit(f"Could not find version in {path}") | |
| major, minor, patch = (int(part) for part in match.groups()) | |
| new_version = f"{major}.{minor}.{patch + 1}" | |
| new_text = re.sub( | |
| r'^(version\s*=\s*)"\d+\.\d+\.\d+"', | |
| rf'\1"{new_version}"', | |
| text, | |
| count=1, | |
| flags=re.MULTILINE, | |
| ) | |
| path.write_text(new_text, encoding="utf-8") | |
| return new_version | |
| stable_version = bump(pathlib.Path("stable.toml")) | |
| dev_version = bump(pathlib.Path("dev.toml")) | |
| with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as output: | |
| output.write(f"new_version={stable_version}\n") | |
| output.write(f"dev_version={dev_version}\n") | |
| print(f"stable.toml -> {stable_version}") | |
| print(f"dev.toml -> {dev_version}") | |
| EOF | |
| - name: Use stable.toml as pyproject.toml | |
| run: cp stable.toml pyproject.toml | |
| - name: Build distribution | |
| run: python -m build | |
| - name: Publish to PyPI | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
| run: twine upload --non-interactive dist/* | |
| - name: Commit and tag version bump | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add stable.toml dev.toml | |
| git commit -m "chore: bump version to ${{ steps.bump.outputs.new_version }}" | |
| git tag "v${{ steps.bump.outputs.new_version }}" | |
| git push origin main | |
| git push origin "v${{ steps.bump.outputs.new_version }}" | |
| - name: Create GitHub Release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh release create "v${{ steps.bump.outputs.new_version }}" \ | |
| dist/* \ | |
| --title "v${{ steps.bump.outputs.new_version }}" \ | |
| --generate-notes |