|
4 | 4 | push: |
5 | 5 | branches: |
6 | 6 | - main |
| 7 | + tags: |
| 8 | + - 'v*' |
7 | 9 | workflow_dispatch: |
8 | 10 |
|
9 | 11 | concurrency: |
10 | 12 | group: cicd-${{ github.ref }} |
11 | 13 | cancel-in-progress: true |
12 | 14 |
|
13 | 15 | permissions: |
14 | | - contents: read |
| 16 | + contents: write |
15 | 17 | id-token: write |
16 | 18 | attestations: write |
17 | 19 | security-events: write |
|
26 | 28 | uses: ./.github/workflows/stage-2-test.yaml |
27 | 29 | secrets: inherit |
28 | 30 |
|
29 | | - build-stage: |
| 31 | + release-stage: |
30 | 32 | needs: test-stage |
| 33 | + if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 34 | + runs-on: ubuntu-latest |
| 35 | + outputs: |
| 36 | + new_release_published: ${{ steps.release.outputs.new_release_published }} |
| 37 | + new_release_version: ${{ steps.release.outputs.new_release_version }} |
| 38 | + steps: |
| 39 | + - name: Checkout code |
| 40 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 41 | + with: |
| 42 | + fetch-depth: 0 |
| 43 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + |
| 45 | + - name: Read tool versions |
| 46 | + id: tool-versions |
| 47 | + run: | |
| 48 | + echo "python=$(awk '/^python / {print $2}' .tool-versions)" >> "$GITHUB_OUTPUT" |
| 49 | + echo "uv=$(awk '/^uv / {print $2}' .tool-versions)" >> "$GITHUB_OUTPUT" |
| 50 | +
|
| 51 | + - name: Set up Python |
| 52 | + uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 |
| 53 | + with: |
| 54 | + python-version: ${{ steps.tool-versions.outputs.python }} |
| 55 | + |
| 56 | + - name: Install uv |
| 57 | + uses: astral-sh/setup-uv@887a942a15af3a7626099df99e897a18d9e5ab3a # v5.1.0 |
| 58 | + with: |
| 59 | + version: ${{ steps.tool-versions.outputs.uv }} |
| 60 | + enable-cache: true |
| 61 | + |
| 62 | + - name: Run semantic-release |
| 63 | + id: release |
| 64 | + env: |
| 65 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 66 | + run: | |
| 67 | + uv pip install python-semantic-release --system |
| 68 | +
|
| 69 | + # Detect next version (--print exits without side effects) |
| 70 | + VERSION=$(semantic-release version --print 2>/dev/null) || true |
| 71 | +
|
| 72 | + if [[ -n "$VERSION" ]] && ! git ls-remote --tags origin "refs/tags/v$VERSION" | grep -q .; then |
| 73 | + echo "Next version detected: $VERSION" |
| 74 | +
|
| 75 | + # Create and push the tag (no commit needed, tag push is not blocked by branch protection) |
| 76 | + git tag "v$VERSION" |
| 77 | + git push origin "v$VERSION" |
| 78 | +
|
| 79 | + echo "new_release_published=true" >> "$GITHUB_OUTPUT" |
| 80 | + echo "new_release_version=v$VERSION" >> "$GITHUB_OUTPUT" |
| 81 | + else |
| 82 | + echo "No new release needed (version: ${VERSION:-none}, tag may already exist)" |
| 83 | + echo "new_release_published=false" >> "$GITHUB_OUTPUT" |
| 84 | + echo "new_release_version=" >> "$GITHUB_OUTPUT" |
| 85 | + fi |
| 86 | +
|
| 87 | + build-stage: |
| 88 | + needs: [test-stage, release-stage] |
| 89 | + if: | |
| 90 | + always() && |
| 91 | + needs.test-stage.result == 'success' && |
| 92 | + ( |
| 93 | + github.ref_type == 'tag' || |
| 94 | + needs.release-stage.outputs.new_release_published == 'true' |
| 95 | + ) |
31 | 96 | uses: ./.github/workflows/stage-3-build.yaml |
| 97 | + with: |
| 98 | + version: ${{ needs.release-stage.outputs.new_release_version }} |
| 99 | + new_release_published: ${{ needs.release-stage.outputs.new_release_published == 'true' }} |
32 | 100 | secrets: inherit |
0 commit comments