From e9a2398592cac73ffdedf35bb836ad8e00b7fa2e Mon Sep 17 00:00:00 2001 From: masquare <11543761+masquare@users.noreply.github.com> Date: Thu, 12 Nov 2026 18:59:01 +0100 Subject: [PATCH] ci(release): open the PR for the next development version Right after the release job, a separate job opens a PR that moves each released package to its next development version. It turns on auto-merge, so the PR merges once it has the approvals that main needs. The job skips a package that main already moved. --- .github/scripts/release.py | 47 +++++++++++++++++++++++++++++++---- .github/workflows/release.yml | 28 +++++++++++++++++++++ 2 files changed, 70 insertions(+), 5 deletions(-) diff --git a/.github/scripts/release.py b/.github/scripts/release.py index ee4fa7cc1..ff7bbac1d 100644 --- a/.github/scripts/release.py +++ b/.github/scripts/release.py @@ -14,6 +14,7 @@ file records the commit that it was built from. - ``github-release`` creates the tag and the GitHub release of each released package. It reads the notes from the merged PR and attaches the files in ``dist/``. +- ``next-dev`` opens the PR for the next development version of the released packages. PyGithub makes the GitHub calls and GitPython makes the git calls. Only ``uv`` and git-cliff run as subprocesses, because they have no Python API. The option ``--dry-run`` does not push and does not @@ -32,7 +33,7 @@ from connector_notes import commits, notes as connector_notes, repo from git import Repo -from github import Auth, Github, UnknownObjectException +from github import Auth, Github, GithubException, UnknownObjectException from github.Repository import Repository @@ -115,10 +116,12 @@ def github() -> Repository: return Github(auth=Auth.Token(os.environ["GH_TOKEN"])).get_repo(os.environ["GITHUB_REPOSITORY"]) -def open_pr(branch: str, title: str, body: str, *, dry_run: bool) -> None: +def open_pr(branch: str, title: str, body: str, *, dry_run: bool, auto_merge: bool = False) -> None: """Commit the working tree to ``branch``, push it, and open its PR against main. - Update the PR if it is already open. + Update the PR if it is already open. With ``auto_merge``, the PR merges when it has the + approvals and checks that main needs. If the repository does not allow auto-merge, this only + warns. """ if dry_run: print(f"{title}\n{branch}\n\n{body}") @@ -137,7 +140,14 @@ def open_pr(branch: str, title: str, body: str, *, dry_run: bool) -> None: pull.edit(body=body) else: pull = remote.create_pull(title=title, body=body, head=branch, base="main") - append("GITHUB_STEP_SUMMARY", f"### {title}\n\n{pull.html_url}\n") + note = "" + if auto_merge: + try: + pull.enable_automerge(merge_method="SQUASH") + note = "\nIt merges when it has the approvals that main needs.\n" + except GithubException as error: + print(f"::warning title=Auto-merge is off::{error.data}") + append("GITHUB_STEP_SUMMARY", f"### {title}\n\n{pull.html_url}\n{note}") def next_version(git: Repo, package: str, requested: str) -> str: @@ -319,6 +329,28 @@ def smoke() -> None: print("::endgroup::") +def next_dev(entries: dict[str, str], *, dry_run: bool) -> None: + """Open the PR that moves each released package to its next development version. + + Do this only for packages that main still holds at the released version. + """ + names, tags = [], [] + for package, version in entries.items(): + if version_of(package) != version: + print(f"main already moved {package} past {version}.") + continue + run("uv", "version", "--package", package, "--bump", "minor", "--bump", "dev=0", "--frozen") + names.append(f"{package} {version_of(package).removesuffix('.dev0')}") + tags.append(f"{package}-v{version}") + if not names: + return + run("uv", "lock") + title = f"chore: start {' and '.join(names)} development" + released = " ".join(f"{package}={version}" for package, version in entries.items()) + body = f"This PR moves the released packages to their next development version ({released} released). Then builds from main do not look like a release." + open_pr("chore/start-development-after-" + "-".join(tags), title, body, dry_run=dry_run, auto_merge=True) + + def parse(text: str) -> dict[str, str]: """Read ``package=version`` pairs. @@ -338,6 +370,9 @@ def parse(text: str) -> dict[str, str]: commands.add_parser("released") commands.add_parser("smoke") commands.add_parser("github-release").add_argument("--released", required=True) + next_dev_parser = commands.add_parser("next-dev") + next_dev_parser.add_argument("--released", required=True) + next_dev_parser.add_argument("--dry-run", action="store_true") args = parser.parse_args() if args.command == "prepare": prepare(args.package, args.version, dry_run=args.dry_run) @@ -345,5 +380,7 @@ def parse(text: str) -> dict[str, str]: released() elif args.command == "smoke": smoke() - else: + elif args.command == "github-release": github_release(parse(args.released)) + else: + next_dev(parse(args.released), dry_run=args.dry_run) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 05b5aba1e..8dabd934e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,6 +8,7 @@ name: Release # 2. Merge the release PR. The same workflow then does these steps: # - It builds and tests the wheel and the sdist of each package. # - It creates the tag and the GitHub release. +# - It opens a PR for the next development version. You can merge this PR at any time. # - It waits for your approval in the pypi environment, then uploads to TestPyPI. # - It waits for your approval again, then uploads to PyPI. # The upload steps send the built files. They do not build. @@ -24,6 +25,8 @@ name: Release # The repository settings block PRs from GITHUB_TOKEN, and those PRs do not start CI. # - A trusted publisher on PyPI and TestPyPI for each package: workflow release.yml, environment # pypi. +# - The repository setting "Allow auto-merge". With it, the development version PR merges when it +# has the approvals that main needs. on: workflow_dispatch: @@ -107,6 +110,8 @@ jobs: permissions: contents: write pull-requests: read + outputs: + released: ${{ steps.released.outputs.released }} steps: - uses: actions/checkout@v5 with: @@ -171,3 +176,26 @@ jobs: path: dist/ - name: Publish to PyPI run: uv publish --check-url https://pypi.org/simple/ dist/* + + next-development-version: + # Run after the release job, at the same time as the publish jobs. + needs: release + runs-on: ubuntu-latest + steps: + - id: app-token + uses: actions/create-github-app-token@v2 + with: + app-id: ${{ vars.RELEASE_APP_ID }} + private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} + permission-contents: write + permission-pull-requests: write + - uses: actions/checkout@v5 + with: + ref: main + token: ${{ steps.app-token.outputs.token }} + - uses: astral-sh/setup-uv@v8.2.0 + - name: Open the development version PR + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + RELEASED: ${{ needs.release.outputs.released }} + run: uv run .github/scripts/release.py next-dev --released "$RELEASED"