|
| 1 | +name: Semantic Release |
| 2 | + |
| 3 | +permissions: |
| 4 | + contents: write |
| 5 | + issues: write |
| 6 | + pull-requests: write |
| 7 | + |
| 8 | +on: |
| 9 | + push: |
| 10 | + branches: |
| 11 | + - main # Only release from main branch |
| 12 | + workflow_dispatch: # Allow manual trigger |
| 13 | + inputs: |
| 14 | + release_type: |
| 15 | + description: 'Release type (leave empty for auto)' |
| 16 | + required: false |
| 17 | + type: choice |
| 18 | + options: |
| 19 | + - '*' |
| 20 | + - patch |
| 21 | + - minor |
| 22 | + - major |
| 23 | + |
| 24 | +jobs: |
| 25 | + release: |
| 26 | + name: Semantic Release |
| 27 | + runs-on: ubuntu-latest |
| 28 | + if: ${{ !contains(github.event.head_commit.message, 'chore(release)') }} |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Checkout code |
| 32 | + uses: actions/checkout@v5 |
| 33 | + with: |
| 34 | + fetch-depth: 0 |
| 35 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 36 | + |
| 37 | + - name: Set up Python |
| 38 | + uses: actions/setup-python@v5 |
| 39 | + with: |
| 40 | + python-version: '3.12' |
| 41 | + |
| 42 | + - name: Set up uv |
| 43 | + uses: astral-sh/setup-uv@v7 |
| 44 | + with: |
| 45 | + enable-cache: true |
| 46 | + |
| 47 | + - name: Install dependencies |
| 48 | + run: | |
| 49 | + uv sync --all-extras |
| 50 | +
|
| 51 | + - name: Python Semantic Release |
| 52 | + id: release |
| 53 | + env: |
| 54 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + run: | |
| 56 | + git config user.name "github-actions[bot]" |
| 57 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 58 | + |
| 59 | + # Store the current version before running semantic-release |
| 60 | + BEFORE_VERSION=$(grep '^version = ' pyproject.toml | cut -d'"' -f2) |
| 61 | + echo "Version before: $BEFORE_VERSION" |
| 62 | + |
| 63 | + # Build semantic-release command |
| 64 | + RELEASE_CMD="uv run semantic-release version --no-changelog --no-vcs-release" |
| 65 | + |
| 66 | + # Add manual release type if specified |
| 67 | + if [ -n "${{ github.event.inputs.release_type }}" ]; then |
| 68 | + RELEASE_CMD="$RELEASE_CMD --${{ github.event.inputs.release_type }}" |
| 69 | + echo "Manual release: ${{ github.event.inputs.release_type }}" |
| 70 | + else |
| 71 | + echo "Automatic release based on commits" |
| 72 | + fi |
| 73 | + |
| 74 | + # Run semantic-release |
| 75 | + eval $RELEASE_CMD |
| 76 | + |
| 77 | + # Check if version changed |
| 78 | + AFTER_VERSION=$(grep '^version = ' pyproject.toml | cut -d'"' -f2) |
| 79 | + echo "Version after: $AFTER_VERSION" |
| 80 | + |
| 81 | + if [ "$BEFORE_VERSION" != "$AFTER_VERSION" ]; then |
| 82 | + echo "released=true" >> $GITHUB_OUTPUT |
| 83 | + echo "tag=v$AFTER_VERSION" >> $GITHUB_OUTPUT |
| 84 | + echo "version=$AFTER_VERSION" >> $GITHUB_OUTPUT |
| 85 | + echo "Released version $AFTER_VERSION (was $BEFORE_VERSION)" |
| 86 | + else |
| 87 | + echo "released=false" >> $GITHUB_OUTPUT |
| 88 | + echo "No release - version unchanged ($BEFORE_VERSION)" |
| 89 | + fi |
| 90 | +
|
| 91 | + - name: Build with uv |
| 92 | + run: uv build --no-sources |
| 93 | + |
| 94 | + - name: Publish to PyPI |
| 95 | + if: github.ref == 'refs/heads/main' |
| 96 | + env: |
| 97 | + UV_PUBLISH_TOKEN: ${{ secrets.PYPI_API_TOKEN }} |
| 98 | + run: uv publish |
0 commit comments