@@ -140,16 +140,25 @@ jobs:
140140 raw = resp.read()
141141 return json.loads(raw) if raw else None
142142
143+ # Delete any pre-existing release branch (from a prior partial run)
144+ # so the bump always starts from main's HEAD. Avoids STALE_DATA from
145+ # createCommitOnBranch and prevents stacking multiple bump commits.
146+ # Any open PR on the stale branch gets auto-closed when the branch
147+ # is deleted, which is fine — we always open a fresh PR below.
143148 try:
144- api(
145- f"repos/{repo}/git/refs",
146- method="POST",
147- body={"ref": f"refs/heads/{branch}", "sha": head_oid},
148- )
149+ api(f"repos/{repo}/git/refs/heads/{branch}", method="DELETE")
150+ print(f"deleted stale branch: {branch}")
149151 except urllib.error.HTTPError as error:
150- if error.code != 422: # 422 = ref already exists; OK to reuse
152+ if error.code not in (404, 422) : # ref doesn't exist; nothing to clean
151153 raise
152154
155+ api(
156+ f"repos/{repo}/git/refs",
157+ method="POST",
158+ body={"ref": f"refs/heads/{branch}", "sha": head_oid},
159+ )
160+ expected_oid = head_oid
161+
153162 def b64(path: str) -> str:
154163 with open(path, "rb") as fp:
155164 return base64.b64encode(fp.read()).decode("ascii")
@@ -173,7 +182,7 @@ jobs:
173182 "message": {
174183 "headline": f"Bump version to v{version} [skip ci]",
175184 },
176- "expectedHeadOid": head_oid ,
185+ "expectedHeadOid": expected_oid ,
177186 "fileChanges": {
178187 "additions": [
179188 {"path": "stable.toml", "contents": b64("stable.toml")},
0 commit comments