👷 Automate release preparation (#15661)

This commit is contained in:
Sebastián Ramírez
2026-05-31 18:00:38 +02:00
committed by GitHub
parent ee22a4b8ca
commit b4d58fddee
9 changed files with 666 additions and 3 deletions

View File

@@ -0,0 +1,56 @@
name: Create Draft Release
on:
pull_request:
types:
- closed
permissions: {}
jobs:
create-draft-release:
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release')
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: write
env:
PREPARE_RELEASE_VERSION_FILE: fastapi/__init__.py
PREPARE_RELEASE_RELEASE_NOTES_FILE: docs/en/docs/release-notes.md
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ github.event.repository.default_branch }}
persist-credentials: true
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version-file: ".python-version"
- name: Install uv
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
with:
# Before upgrading uv version, make sure astral-sh/setup-uv knows its checksum.
# See: https://github.com/astral-sh/setup-uv/issues/851#issuecomment-4282017837
version: "0.11.4"
- name: Extract release details
id: release-details
run: |
set -euo pipefail
version="$(uv run python scripts/prepare_release.py current-version)"
uv run python scripts/prepare_release.py release-notes > draft-release-notes.md
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Create draft release
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.release-details.outputs.version }}
run: |
set -euo pipefail
gh release create "$VERSION" \
--draft \
--title "$VERSION" \
--notes-file draft-release-notes.md \
--target "$(git rev-parse HEAD)"

View File

@@ -33,5 +33,5 @@ jobs:
steps:
- uses: agilepathway/label-checker@c3d16ad512e7cea5961df85ff2486bb774caf3c5 # v1.6.65
with:
one_of: breaking,security,feature,bug,refactor,upgrade,docs,lang-all,internal
one_of: breaking,security,feature,bug,refactor,upgrade,docs,lang-all,internal,release
repo_token: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -39,7 +39,7 @@ jobs:
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled == 'true' }}
with:
limit-access-to-actor: true
- uses: tiangolo/latest-changes@c9d329cb147f0ddf4fb631214e3f838ff17ccbbd # 0.4.1
- uses: tiangolo/latest-changes@eb3f6e7ff0073896ecb561e774a121de9418fa06 # 0.5.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
latest_changes_file: docs/en/docs/release-notes.md

80
.github/workflows/prepare-release.yml vendored Normal file
View File

@@ -0,0 +1,80 @@
name: Prepare Release
on:
workflow_dispatch:
inputs:
bump:
description: Release bump
required: true
type: choice
options:
- patch
- minor
- major
date:
description: Release date in YYYY-MM-DD format. Defaults to today.
required: false
type: string
permissions: {}
jobs:
prepare-release:
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: write
issues: write
pull-requests: write
env:
PREPARE_RELEASE_VERSION_FILE: fastapi/__init__.py
PREPARE_RELEASE_RELEASE_NOTES_FILE: docs/en/docs/release-notes.md
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
token: ${{ secrets.FASTAPI_LATEST_CHANGES }} # zizmor: ignore[secrets-outside-env]
persist-credentials: true
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version-file: ".python-version"
- name: Install uv
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
with:
# Before upgrading uv version, make sure astral-sh/setup-uv knows its checksum.
# See: https://github.com/astral-sh/setup-uv/issues/851#issuecomment-4282017837
version: "0.11.4"
- name: Prepare release
env:
PREPARE_RELEASE_BUMP: ${{ inputs.bump }}
PREPARE_RELEASE_DATE: ${{ inputs.date }}
run: uv run python scripts/prepare_release.py prepare
- name: Get release version
id: release-version
run: |
version="$(uv run python scripts/prepare_release.py current-version)"
echo "$version"
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Create release pull request
env:
GH_TOKEN: ${{ secrets.FASTAPI_LATEST_CHANGES }}
VERSION: ${{ steps.release-version.outputs.version }}
run: |
set -euo pipefail
branch="release-${VERSION}-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git switch -c "$branch"
git add $PREPARE_RELEASE_VERSION_FILE $PREPARE_RELEASE_RELEASE_NOTES_FILE
git commit -m "🔖 Release version ${VERSION}"
git push --set-upstream origin "$branch"
gh pr create \
--base master \
--head "$branch" \
--title "🔖 Release version ${VERSION}" \
--body "Prepare release ${VERSION}." \
--label release

View File

@@ -3,7 +3,7 @@ name: Publish
on:
release:
types:
- created
- published
permissions: {}