|
1 | | -name: Prepare Release |
| 1 | +name: Prepare release |
2 | 2 | on: |
3 | 3 | workflow_dispatch: |
4 | 4 | inputs: |
5 | 5 | bump: |
6 | | - description: "Version bump type" |
| 6 | + description: Version bump type |
7 | 7 | required: true |
8 | 8 | type: choice |
9 | | - options: |
10 | | - - auto |
11 | | - - major |
12 | | - - minor |
13 | | - - patch |
| 9 | + options: [auto, major, minor, patch] |
14 | 10 | default: auto |
15 | | -permissions: |
16 | | - contents: read |
17 | | -env: |
18 | | - FORCE_COLOR: 1 |
| 11 | +permissions: {} |
19 | 12 | jobs: |
20 | | - assemble: |
21 | | - if: github.ref == 'refs/heads/main' |
22 | | - runs-on: ubuntu-24.04 |
| 13 | + prepare: |
| 14 | + name: 🏷️ Prepare Towncrier release |
| 15 | + uses: tox-dev/github-workflows/.github/workflows/prepare-towncrier-release.yaml@259a3d3fb578d00517ffb73341fdd463259b0b2f # 6.0.1 |
23 | 16 | permissions: |
24 | 17 | contents: read |
25 | | - outputs: |
26 | | - version: ${{ steps.version.outputs.version }} |
27 | | - steps: |
28 | | - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
29 | | - with: |
30 | | - fetch-depth: 0 # The next version comes from the tags. |
31 | | - persist-credentials: false |
32 | | - - name: Install uv |
33 | | - uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0 |
34 | | - with: |
35 | | - python-version: "3.15" |
36 | | - enable-cache: false |
37 | | - - name: Require a news fragment |
38 | | - run: | |
39 | | - if ! compgen -G 'docs/changelog/*.*.rst' > /dev/null; then |
40 | | - echo '::error::add a docs/changelog/*.rst fragment before preparing a release' |
41 | | - exit 1 |
42 | | - fi |
43 | | - - name: Set up remote tracking |
44 | | - run: | |
45 | | - git remote -v |
46 | | - git fetch origin |
47 | | - git branch -a |
48 | | - - name: Calculate next version |
49 | | - id: version |
50 | | - env: |
51 | | - BUMP: ${{ inputs.bump }} |
52 | | - run: | |
53 | | - current=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0") |
54 | | - echo "Current version: $current" |
55 | | -
|
56 | | - IFS='.' read -r major minor patch <<< "$current" |
57 | | -
|
58 | | - bump_type="$BUMP" |
59 | | - if [ "$bump_type" = "auto" ]; then |
60 | | - feature_count=$(find docs/changelog -name "*.feature.rst" 2>/dev/null | wc -l) |
61 | | - breaking_count=$(find docs/changelog -name "*.breaking.rst" 2>/dev/null | wc -l) |
62 | | - if [ "$breaking_count" -gt 0 ]; then |
63 | | - bump_type="major" |
64 | | - echo "Auto-detected: major bump (found $breaking_count breaking changelog(s))" |
65 | | - elif [ "$feature_count" -gt 0 ]; then |
66 | | - bump_type="minor" |
67 | | - echo "Auto-detected: minor bump (found $feature_count feature changelog(s))" |
68 | | - else |
69 | | - bump_type="patch" |
70 | | - echo "Auto-detected: patch bump (no feature changelogs)" |
71 | | - fi |
72 | | - fi |
73 | | -
|
74 | | - case "$bump_type" in |
75 | | - major) |
76 | | - next="$((major + 1)).0.0" |
77 | | - ;; |
78 | | - minor) |
79 | | - next="$major.$((minor + 1)).0" |
80 | | - ;; |
81 | | - patch) |
82 | | - next="$major.$minor.$((patch + 1))" |
83 | | - ;; |
84 | | - esac |
85 | | -
|
86 | | - echo "Next version: $next" |
87 | | - echo "version=$next" >> "$GITHUB_OUTPUT" |
88 | | - - name: Build release patch |
89 | | - env: |
90 | | - VERSION: ${{ steps.version.outputs.version }} |
91 | | - run: | |
92 | | - set -euo pipefail |
93 | | - uvx towncrier build --yes --version "$VERSION" |
94 | | - uvx --with pre-commit-uv pre-commit run --files docs/changelog.rst || |
95 | | - uvx --with pre-commit-uv pre-commit run --files docs/changelog.rst |
96 | | - git diff HEAD --binary > "$RUNNER_TEMP/release.patch" |
97 | | - test -s "$RUNNER_TEMP/release.patch" |
98 | | - - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 |
99 | | - with: |
100 | | - name: release-patch |
101 | | - path: ${{ runner.temp }}/release.patch |
102 | | - if-no-files-found: error |
103 | | - push: |
104 | | - needs: assemble |
105 | | - runs-on: ubuntu-24.04 |
106 | | - environment: release-auth |
107 | | - permissions: |
108 | | - contents: read |
109 | | - steps: |
110 | | - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
111 | | - with: |
112 | | - fetch-depth: 0 |
113 | | - persist-credentials: false |
114 | | - - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 |
115 | | - with: |
116 | | - name: release-patch |
117 | | - path: ${{ runner.temp }}/release-patch |
118 | | - - name: Validate release patch |
119 | | - env: |
120 | | - VERSION: ${{ needs.assemble.outputs.version }} |
121 | | - run: | |
122 | | - set -euo pipefail |
123 | | - git fetch origin main |
124 | | - git reset --hard origin/main |
125 | | - git apply --check "$RUNNER_TEMP/release-patch/release.patch" |
126 | | - git apply --index "$RUNNER_TEMP/release-patch/release.patch" |
127 | | - while IFS= read -r path; do |
128 | | - case "$path" in |
129 | | - docs/changelog.rst|docs/changelog/*.rst) ;; |
130 | | - *) echo "::error::unexpected release path: $path"; exit 1 ;; |
131 | | - esac |
132 | | - done < <(git diff --cached --name-only) |
133 | | - grep -qE "^ v${VERSION//./\\.} \(" docs/changelog.rst |
134 | | - git diff --cached --check |
135 | | - - id: token |
136 | | - uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 |
137 | | - with: |
138 | | - client-id: ${{ vars.RELEASE_APP_CLIENT_ID }} |
139 | | - private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} |
140 | | - owner: ${{ github.repository_owner }} |
141 | | - repositories: ${{ github.event.repository.name }} |
142 | | - permission-contents: write |
143 | | - - name: Commit and tag the release |
144 | | - env: |
145 | | - VERSION: ${{ needs.assemble.outputs.version }} |
146 | | - GH_TOKEN: ${{ steps.token.outputs.token }} |
147 | | - APP_SLUG: ${{ steps.token.outputs.app-slug }} |
148 | | - run: | |
149 | | - set -euo pipefail |
150 | | - app_user_id=$(gh api "/users/${APP_SLUG}[bot]" --jq .id) |
151 | | - git config user.name "${APP_SLUG}[bot]" |
152 | | - git config user.email "${app_user_id}+${APP_SLUG}[bot]@users.noreply.github.com" |
153 | | - git commit -m "release $VERSION" |
154 | | - git tag -a "$VERSION" -m "release $VERSION" |
155 | | - gh auth setup-git --hostname github.com --force |
156 | | - git push --atomic origin HEAD:main "refs/tags/$VERSION" |
| 18 | + pull-requests: read |
| 19 | + with: |
| 20 | + bump: ${{ inputs.bump }} |
| 21 | + annotated: true |
| 22 | + secrets: |
| 23 | + RELEASE_APP_PRIVATE_KEY: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} |
0 commit comments