|
| 1 | +# .github/workflows/release-template.yml |
| 2 | +# Automated release workflow for the cookiecutter-robust-python template |
| 3 | +# Uses Calendar Versioning (CalVer): YYYY.MM.MICRO |
| 4 | + |
| 5 | +name: Release Template |
| 6 | + |
| 7 | +on: |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + |
| 12 | + workflow_dispatch: |
| 13 | + inputs: |
| 14 | + micro_version: |
| 15 | + description: 'Override micro version (leave empty for auto-increment)' |
| 16 | + required: false |
| 17 | + type: string |
| 18 | + |
| 19 | +jobs: |
| 20 | + bump_and_build: |
| 21 | + name: Bump Version & Build |
| 22 | + runs-on: ubuntu-latest |
| 23 | + outputs: |
| 24 | + version: ${{ steps.version.outputs.VERSION }} |
| 25 | + steps: |
| 26 | + - name: Checkout code |
| 27 | + uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + fetch-depth: 0 |
| 30 | + fetch-tags: true |
| 31 | + |
| 32 | + - name: Set up uv |
| 33 | + uses: astral-sh/setup-uv@v6 |
| 34 | + |
| 35 | + - name: Set up Python |
| 36 | + uses: actions/setup-python@v5 |
| 37 | + with: |
| 38 | + python-version-file: ".github/workflows/.python-version" |
| 39 | + |
| 40 | + - name: Configure Git |
| 41 | + run: | |
| 42 | + git config user.name "github-actions[bot]" |
| 43 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 44 | +
|
| 45 | + - name: Bump version and generate changelog |
| 46 | + run: | |
| 47 | + if [ -n "${{ inputs.micro_version }}" ]; then |
| 48 | + uvx nox -s bump-version -- ${{ inputs.micro_version }} |
| 49 | + else |
| 50 | + uvx nox -s bump-version |
| 51 | + fi |
| 52 | +
|
| 53 | + - name: Get version |
| 54 | + id: version |
| 55 | + run: | |
| 56 | + VERSION=$(uvx --from commitizen cz version -p) |
| 57 | + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT |
| 58 | +
|
| 59 | + - name: Push version bump commit |
| 60 | + run: git push origin HEAD |
| 61 | + |
| 62 | + - name: Build packages |
| 63 | + run: uvx nox -s build-python |
| 64 | + |
| 65 | + - name: Upload build artifacts |
| 66 | + uses: actions/upload-artifact@v4 |
| 67 | + with: |
| 68 | + name: dist-${{ steps.version.outputs.VERSION }} |
| 69 | + path: dist/ |
| 70 | + retention-days: 7 |
| 71 | + |
| 72 | + publish_testpypi: |
| 73 | + name: Publish to TestPyPI |
| 74 | + runs-on: ubuntu-latest |
| 75 | + needs: bump_and_build |
| 76 | + permissions: |
| 77 | + id-token: write |
| 78 | + steps: |
| 79 | + - name: Checkout code |
| 80 | + uses: actions/checkout@v4 |
| 81 | + |
| 82 | + - name: Set up uv |
| 83 | + uses: astral-sh/setup-uv@v6 |
| 84 | + |
| 85 | + - name: Download build artifacts |
| 86 | + uses: actions/download-artifact@v4 |
| 87 | + with: |
| 88 | + name: dist-${{ needs.bump_and_build.outputs.version }} |
| 89 | + path: dist/ |
| 90 | + |
| 91 | + - name: Publish to TestPyPI |
| 92 | + run: uvx nox -s publish-python -- --test-pypi |
| 93 | + |
| 94 | + publish_pypi: |
| 95 | + name: Tag & Publish to PyPI |
| 96 | + runs-on: ubuntu-latest |
| 97 | + needs: [bump_and_build, publish_testpypi] |
| 98 | + permissions: |
| 99 | + id-token: write |
| 100 | + contents: write |
| 101 | + steps: |
| 102 | + - name: Checkout code |
| 103 | + uses: actions/checkout@v4 |
| 104 | + with: |
| 105 | + fetch-depth: 0 |
| 106 | + ref: main |
| 107 | + |
| 108 | + - name: Set up uv |
| 109 | + uses: astral-sh/setup-uv@v6 |
| 110 | + |
| 111 | + - name: Set up Python |
| 112 | + uses: actions/setup-python@v5 |
| 113 | + with: |
| 114 | + python-version-file: ".github/workflows/.python-version" |
| 115 | + |
| 116 | + - name: Configure Git |
| 117 | + run: | |
| 118 | + git config user.name "github-actions[bot]" |
| 119 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 120 | +
|
| 121 | + - name: Pull latest (includes version bump) |
| 122 | + run: git pull origin main |
| 123 | + |
| 124 | + - name: Download build artifacts |
| 125 | + uses: actions/download-artifact@v4 |
| 126 | + with: |
| 127 | + name: dist-${{ needs.bump_and_build.outputs.version }} |
| 128 | + path: dist/ |
| 129 | + |
| 130 | + - name: Create and push tag |
| 131 | + run: uvx nox -s tag-version -- push |
| 132 | + |
| 133 | + - name: Publish to PyPI |
| 134 | + run: uvx nox -s publish-python |
| 135 | + |
| 136 | + - name: Extract release notes |
| 137 | + run: uvx nox -s get-release-notes -- release_notes.md |
| 138 | + |
| 139 | + - name: Create GitHub Release |
| 140 | + uses: softprops/action-gh-release@v2 |
| 141 | + with: |
| 142 | + tag_name: v${{ needs.bump_and_build.outputs.version }} |
| 143 | + name: v${{ needs.bump_and_build.outputs.version }} |
| 144 | + body_path: release_notes.md |
| 145 | + files: dist/* |
| 146 | + env: |
| 147 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments