diff --git a/.github/workflows/ci-stable.yml b/.github/workflows/ci-stable.yml index 80d1200..3213470 100644 --- a/.github/workflows/ci-stable.yml +++ b/.github/workflows/ci-stable.yml @@ -140,16 +140,25 @@ jobs: raw = resp.read() return json.loads(raw) if raw else None + # Delete any pre-existing release branch (from a prior partial run) + # so the bump always starts from main's HEAD. Avoids STALE_DATA from + # createCommitOnBranch and prevents stacking multiple bump commits. + # Any open PR on the stale branch gets auto-closed when the branch + # is deleted, which is fine — we always open a fresh PR below. try: - api( - f"repos/{repo}/git/refs", - method="POST", - body={"ref": f"refs/heads/{branch}", "sha": head_oid}, - ) + api(f"repos/{repo}/git/refs/heads/{branch}", method="DELETE") + print(f"deleted stale branch: {branch}") except urllib.error.HTTPError as error: - if error.code != 422: # 422 = ref already exists; OK to reuse + if error.code not in (404, 422): # ref doesn't exist; nothing to clean raise + api( + f"repos/{repo}/git/refs", + method="POST", + body={"ref": f"refs/heads/{branch}", "sha": head_oid}, + ) + expected_oid = head_oid + def b64(path: str) -> str: with open(path, "rb") as fp: return base64.b64encode(fp.read()).decode("ascii") @@ -173,7 +182,7 @@ jobs: "message": { "headline": f"Bump version to v{version} [skip ci]", }, - "expectedHeadOid": head_oid, + "expectedHeadOid": expected_oid, "fileChanges": { "additions": [ {"path": "stable.toml", "contents": b64("stable.toml")},