fix: trigger CD workflow automatically on push to main (#3) #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: CD | |
| on: | |
| push: | |
| branches: ["main"] | |
| workflow_dispatch: | |
| inputs: | |
| bump: | |
| description: "Version bump type" | |
| required: true | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| jobs: | |
| ci: | |
| uses: ./.github/workflows/ci.yml | |
| release: | |
| needs: ci | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/main' | |
| environment: | |
| name: pypi | |
| permissions: | |
| id-token: write | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| with: | |
| enable-cache: true | |
| - name: Install Python | |
| run: uv python install | |
| - name: Configure git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Bump version | |
| id: version | |
| run: | | |
| uv version --bump ${{ inputs.bump || 'patch' }} | |
| VERSION=$(uv version --short) | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| - name: Commit version bump | |
| run: | | |
| git add pyproject.toml uv.lock | |
| git commit -m "chore: release v${{ steps.version.outputs.version }}" | |
| git push | |
| - name: Create and push tag | |
| run: | | |
| git tag "v${{ steps.version.outputs.version }}" | |
| git push origin "v${{ steps.version.outputs.version }}" | |
| - name: Build | |
| run: uv build | |
| - name: Create GitHub release | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| gh release create "v${{ steps.version.outputs.version }}" dist/* \ | |
| --title "v${{ steps.version.outputs.version }}" \ | |
| --generate-notes | |
| - name: Publish to PyPI | |
| run: uv publish |