Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/verified-release-batch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,30 @@ jobs:
previous_tag: ${{ needs.count.outputs.base }}
publish: true
secrets: inherit

next-batch:
needs: [count, release]
if: >-
${{ !cancelled() && needs.count.result == 'success' &&
(needs.release.result == 'success' ||
(needs.release.result == 'skipped' &&
needs.count.outputs.base == format('v{0}', needs.count.outputs.version))) }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: refs/tags/v${{ needs.count.outputs.version }}
fetch-depth: 0
- name: Open an empty batch for the next patch
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.count.outputs.version }}
run: |
latest="$(gh api "repos/$GITHUB_REPOSITORY/releases/latest" --jq .tag_name)"
if [[ "$latest" == "v$VERSION" ]]; then
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
python3 scripts/start_release_batch.py --published-version "$VERSION"
fi
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ For example, an entry for a completed fix uses this structure. Use the actual co
}
```

Review establishes that a change fixes a distinct defect, meets the batch scope and has passed its acceptance case. Changes for one defect share one entry. At ten verified entries the branch push starts the existing stable build and publication workflow on that exact commit. The workflow checks the current public baseline again before publishing. A completed release starts a fresh batch based on its tag.
Review establishes that a change fixes a distinct defect, meets the batch scope and has passed its acceptance case. Changes for one defect share one entry. At ten verified entries the branch push starts the existing stable build and publication workflow on that exact commit. The workflow checks the current public baseline again before publishing. After publication, the workflow opens the next patch branch from the public tag with an empty manifest. The first reviewed backport on that branch supplies the new package version and release notes. A retry preserves work on an existing branch descended from the tag.

## Rejected alternatives

Expand All @@ -43,7 +43,7 @@ Maintainers can continue merging work while a release runs. Each eligible batch

## Validation

The batch tests exercise nine and ten fixes, duplicate entries, missing evidence, previous-release commits, disconnected history and an already published version. Stable workflow tests cover automatic and manual publication guards.
The batch tests exercise nine and ten fixes, duplicate entries, missing evidence, previous-release commits, disconnected history and an already published version. Stable workflow tests cover automatic and manual publication guards. Bare-remote tests exercise two successive patch releases, retry after another fix arrives, an unrelated existing branch, an unpublished commit and a dirty checkout.

## Supersedes

Expand Down
57 changes: 57 additions & 0 deletions scripts/start_release_batch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""Open an empty patch batch from a published stable tag in a detached CI checkout."""

import argparse
import json
from pathlib import Path
import subprocess

if __package__:
from .stable_release import validate_version
else:
from stable_release import validate_version


def start_next_batch(repo: Path, version: str) -> str:
validate_version(version)
major, minor, patch = map(int, version.split("."))
branch = f"release/auto-{major}.{minor}.{patch + 1}"
ref = f"refs/heads/{branch}"
tag = f"v{version}"

def git(*args: str) -> str:
return subprocess.check_output(["git", *args], cwd=repo, text=True).strip()

published = git("rev-parse", "--verify", f"refs/tags/{tag}^{{commit}}")
if git("rev-parse", "HEAD") != published:
raise ValueError("the checkout must match the published tag")

def already_open() -> bool:
if not git("ls-remote", "--heads", "origin", ref):
return False
git("fetch", "--quiet", "--no-tags", "origin", ref)
git("merge-base", "--is-ancestor", published, "FETCH_HEAD")
return True

if already_open():
return branch
if git("status", "--porcelain") or git("branch", "--show-current"):
raise ValueError("creating a batch requires a clean detached checkout")
manifest = Path("packaging/release-batch.json")
(repo / manifest).write_text(json.dumps({"base": tag, "fixes": []}, indent=2) + "\n",
encoding="utf-8")
git("add", "--", str(manifest))
git("commit", "-m", f"Start the verified patch batch after {tag}", "--", str(manifest))
try:
git("push", "origin", f"HEAD:{ref}")
except subprocess.CalledProcessError:
# A concurrent maintainer may already have started the new branch.
if not already_open():
raise
return branch


if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--published-version", required=True)
args = parser.parse_args()
print(start_next_batch(Path.cwd(), args.published_version))
67 changes: 67 additions & 0 deletions scripts/tests/test_start_release_batch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import json
from pathlib import Path
import subprocess
from tempfile import TemporaryDirectory
import unittest

from scripts.start_release_batch import start_next_batch


class StartReleaseBatchTests(unittest.TestCase):
def setUp(self):
temp = TemporaryDirectory()
self.addCleanup(temp.cleanup)
root = Path(temp.name)
self.repo = root / "source"
remote = root / "remote.git"
subprocess.run(["git", "init", "-q", "--bare", str(remote)], check=True)
subprocess.run(["git", "init", "-q", str(self.repo)], check=True)
self.git("config", "user.name", "Fixture")
self.git("config", "user.email", "fixture@example.invalid")
self.git("remote", "add", "origin", str(remote))
self.manifest = self.repo / "packaging/release-batch.json"
self.manifest.parent.mkdir()
self.manifest.write_text('{"base":"v2.6.0","fixes":[{"id":"previous-fix"}]}\n')
self.git("add", "packaging/release-batch.json")
self.git("commit", "-qm", "Released source")
self.git("tag", "v2.6.1")
self.git("checkout", "-q", "--detach")

def git(self, *args):
return subprocess.check_output(["git", *args], cwd=self.repo, text=True).strip()

def test_two_successive_releases_start_empty_patch_batches(self):
for previous, following in [("2.6.1", "2.6.2"), ("2.6.2", "2.6.3")]:
branch = start_next_batch(self.repo, previous)
self.assertEqual(branch, f"release/auto-{following}")
head = self.git("ls-remote", "origin", f"refs/heads/{branch}").split()[0]
self.assertEqual(self.git("rev-parse", head + "^"), self.git("rev-parse", "v" + previous))
self.assertEqual(json.loads(self.git("show", head + ":packaging/release-batch.json")),
{"base": "v" + previous, "fixes": []})
self.git("commit", "-q", "--allow-empty", "-m", "The next reviewed fix")
self.git("push", "-q", "origin", "HEAD:refs/heads/" + branch)
progressed = self.git("rev-parse", "HEAD")
self.git("tag", "v" + following)
self.git("checkout", "-q", "--detach", "v" + previous)
self.assertEqual(start_next_batch(self.repo, previous), branch)
self.assertEqual(self.git("ls-remote", "origin", branch).split()[0], progressed)
self.git("checkout", "-q", "--detach", "v" + following)

def test_existing_branch_from_another_baseline_is_preserved(self):
branch = "refs/heads/release/auto-2.6.2"
unrelated = subprocess.check_output(
["git", "commit-tree", self.git("rev-parse", "HEAD^{tree}"), "-m", "Other history"],
cwd=self.repo, text=True).strip()
self.git("push", "-q", "origin", f"{unrelated}:{branch}")
with self.assertRaises(subprocess.CalledProcessError):
start_next_batch(self.repo, "2.6.1")
self.assertEqual(self.git("ls-remote", "origin", branch).split()[0], unrelated)

def test_mismatched_or_dirty_checkout_cannot_create_a_batch(self):
(self.repo / "local-file").touch()
with self.assertRaisesRegex(ValueError, "clean detached"):
start_next_batch(self.repo, "2.6.1")
self.git("commit", "-q", "--allow-empty", "-m", "Unreleased source")
with self.assertRaisesRegex(ValueError, "published tag"):
start_next_batch(self.repo, "2.6.1")
self.assertEqual(self.git("ls-remote", "--heads", "origin"), "")
Loading