|
| 1 | +name: Publish to PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + publish: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + id-token: write |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + token: ${{ secrets.GH_PAT }} |
| 21 | + |
| 22 | + - name: Set up Python |
| 23 | + uses: actions/setup-python@v5 |
| 24 | + with: |
| 25 | + python-version: '3.12' |
| 26 | + |
| 27 | + - name: Install uv |
| 28 | + uses: astral-sh/setup-uv@v4 |
| 29 | + |
| 30 | + - name: Install dependencies |
| 31 | + run: uv sync --all-extras |
| 32 | + |
| 33 | + - name: Run tests |
| 34 | + run: uv run pytest |
| 35 | + |
| 36 | + - name: Configure Git |
| 37 | + run: | |
| 38 | + git config user.name "github-actions[bot]" |
| 39 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 40 | +
|
| 41 | + - name: Determine version bump type |
| 42 | + id: version |
| 43 | + run: | |
| 44 | + COMMIT_MSG=$(git log -1 --pretty=%B) |
| 45 | + if echo "$COMMIT_MSG" | grep -iq "^feat!:\|BREAKING CHANGE"; then |
| 46 | + echo "bump=major" >> $GITHUB_OUTPUT |
| 47 | + elif echo "$COMMIT_MSG" | grep -iq "^feat:"; then |
| 48 | + echo "bump=minor" >> $GITHUB_OUTPUT |
| 49 | + else |
| 50 | + echo "bump=patch" >> $GITHUB_OUTPUT |
| 51 | + fi |
| 52 | +
|
| 53 | + - name: Bump version |
| 54 | + run: | |
| 55 | + # Get current version from pyproject.toml |
| 56 | + CURRENT_VERSION=$(grep -oP 'version = "\K[^"]+' pyproject.toml) |
| 57 | + IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION" |
| 58 | + |
| 59 | + BUMP_TYPE="${{ steps.version.outputs.bump }}" |
| 60 | + |
| 61 | + if [ "$BUMP_TYPE" = "major" ]; then |
| 62 | + MAJOR=$((MAJOR + 1)) |
| 63 | + MINOR=0 |
| 64 | + PATCH=0 |
| 65 | + elif [ "$BUMP_TYPE" = "minor" ]; then |
| 66 | + MINOR=$((MINOR + 1)) |
| 67 | + PATCH=0 |
| 68 | + else |
| 69 | + PATCH=$((PATCH + 1)) |
| 70 | + fi |
| 71 | + |
| 72 | + NEW_VERSION="$MAJOR.$MINOR.$PATCH" |
| 73 | + |
| 74 | + # Update version in pyproject.toml |
| 75 | + sed -i "s/version = \"$CURRENT_VERSION\"/version = \"$NEW_VERSION\"/" pyproject.toml |
| 76 | + |
| 77 | + echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV |
| 78 | +
|
| 79 | + - name: Commit and push version bump |
| 80 | + run: | |
| 81 | + git add pyproject.toml |
| 82 | + git commit -m "chore: bump version to ${{ env.NEW_VERSION }} [skip ci]" |
| 83 | + git push |
| 84 | +
|
| 85 | + - name: Build package |
| 86 | + run: uv build |
| 87 | + |
| 88 | + - name: Publish to PyPI |
| 89 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 90 | + with: |
| 91 | + password: ${{ secrets.PYPI_API_TOKEN }} |
0 commit comments