|
12 | 12 | types: [completed] |
13 | 13 | branches: ['main', 'beta', 'httpx'] |
14 | 14 |
|
15 | | -# The release is created with a GitHub App token; the default token only needs |
16 | | -# read access for checkout and `gh release view`. |
| 15 | +# The release is created with a GitHub App token. The "Build changelog" step |
| 16 | +# commits the rendered CHANGELOG.md back to the release branch, so the default |
| 17 | +# token needs write access to contents. |
17 | 18 | permissions: |
18 | | - contents: read |
| 19 | + contents: write |
19 | 20 |
|
20 | 21 | jobs: |
21 | 22 | create-release: |
|
80 | 81 | exit 1 |
81 | 82 | fi |
82 | 83 |
|
| 84 | + # Render changelog.d/ fragments into CHANGELOG.md and commit before the |
| 85 | + # release is cut. Reuses the version already read from pyproject.toml, so |
| 86 | + # there is no separate towncrier version to keep in sync. --generate-notes |
| 87 | + # below remains as a fallback for the GitHub release body. |
| 88 | + - name: Build changelog |
| 89 | + env: |
| 90 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 91 | + run: | |
| 92 | + VERSION="${{ steps.version.outputs.version }}" |
| 93 | + BRANCH="${{ inputs.branch || github.event.workflow_run.head_branch }}" |
| 94 | +
|
| 95 | + # Nothing to do if there are no fragments to consume. |
| 96 | + if ! ls changelog.d/*.md >/dev/null 2>&1; then |
| 97 | + echo "No changelog fragments; skipping towncrier build." |
| 98 | + exit 0 |
| 99 | + fi |
| 100 | +
|
| 101 | + pip install --quiet towncrier |
| 102 | + towncrier build --yes --version "$VERSION" |
| 103 | +
|
| 104 | + git config user.name "github-actions[bot]" |
| 105 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 106 | + git add CHANGELOG.md changelog.d/ |
| 107 | + if ! git diff --cached --quiet; then |
| 108 | + git commit -m "docs: update changelog for $VERSION" |
| 109 | + git push origin "HEAD:$BRANCH" |
| 110 | + fi |
| 111 | +
|
83 | 112 | - name: Create release |
84 | 113 | if: steps.check-release.outputs.exists == 'false' |
85 | 114 | env: |
|
0 commit comments