release: rc notes resolve to the base version; publish without jq
release_notes.py 'notes v0.6.0-rc1' looked for a CHANGELOG section literally named v0.6.0-rc1. check() already used base_version(); extract_notes() did not. So the release workflow cut the tag, passed every gate, and then died extracting the body -- the candidate existed but was never published. Caught in an rc, which is the entire point of having them. Also: the Gitea publish and issue steps used jq, which is not guaranteed on a self-hosted runner. A publish step that dies on a missing tool leaves a tag with no release behind it, and a bug report that dies on one is a warning system that does not warn. Both now use python3, which setup-python guarantees.
This commit is contained in:
@@ -193,24 +193,36 @@ jobs:
|
|||||||
API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}
|
API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}
|
||||||
TITLE: "Incompatible with upcoming TrueNAS: ${{ steps.report.outputs.refs }}"
|
TITLE: "Incompatible with upcoming TrueNAS: ${{ steps.report.outputs.refs }}"
|
||||||
run: |
|
run: |
|
||||||
body="$(jq -Rs . < /tmp/issue.md)"
|
# python3, not jq: jq is not guaranteed on a self-hosted runner, and a bug
|
||||||
title="$(printf '%s' "$TITLE" | jq -Rs .)"
|
# report that dies on a missing tool is a warning system that does not warn.
|
||||||
|
python3 - <<'PY'
|
||||||
|
import json, os, urllib.error, urllib.request
|
||||||
|
|
||||||
# Same title => same issue. Comment on it instead of filing a new one.
|
api, token, title = os.environ["API"], os.environ["TOKEN"], os.environ["TITLE"]
|
||||||
number="$(curl -sf -H "Authorization: token $TOKEN" \
|
with open("/tmp/issue.md", encoding="utf-8") as fh:
|
||||||
"$API/issues?state=all&type=issues" \
|
body = fh.read()
|
||||||
| jq -r --arg t "$TITLE" '.[] | select(.title == $t) | .number' | head -1)"
|
headers = {"Authorization": f"token {token}",
|
||||||
|
"Content-Type": "application/json"}
|
||||||
|
|
||||||
if [ -n "$number" ]; then
|
def call(url, method, data=None):
|
||||||
curl -sS -X POST "$API/issues/$number/comments" \
|
req = urllib.request.Request(
|
||||||
-H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
url, method=method, headers=headers,
|
||||||
-d "$(printf '{"body":%s}' "$body")" -o /dev/null -w 'comment -> %{http_code}\n'
|
data=json.dumps(data).encode() if data else None)
|
||||||
curl -sS -X PATCH "$API/issues/$number" \
|
with urllib.request.urlopen(req) as r: # noqa: S310
|
||||||
-H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
return json.load(r) if r.length != 0 else {}
|
||||||
-d '{"state":"open"}' -o /dev/null -w 'reopen -> %{http_code}\n'
|
|
||||||
else
|
# Same title => same issue. Comment on it rather than filing a new one every
|
||||||
curl -sS -X POST "$API/issues" \
|
# morning: a bot that duplicates itself daily gets muted, and then it is not
|
||||||
-H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
# a warning system any more.
|
||||||
-d "$(printf '{"title":%s,"body":%s}' "$title" "$body")" \
|
issues = call(f"{api}/issues?state=all&type=issues", "GET")
|
||||||
-o /dev/null -w 'create -> %{http_code}\n'
|
match = next((i for i in issues if i["title"] == title), None)
|
||||||
fi
|
|
||||||
|
if match:
|
||||||
|
n = match["number"]
|
||||||
|
call(f"{api}/issues/{n}/comments", "POST", {"body": body})
|
||||||
|
call(f"{api}/issues/{n}", "PATCH", {"state": "open"})
|
||||||
|
print(f"commented on and reopened issue #{n}")
|
||||||
|
else:
|
||||||
|
made = call(f"{api}/issues", "POST", {"title": title, "body": body})
|
||||||
|
print(f"filed issue #{made['number']}")
|
||||||
|
PY
|
||||||
|
|||||||
@@ -164,27 +164,45 @@ jobs:
|
|||||||
*-rc*|*-beta*|*-alpha*) prerelease=true ;;
|
*-rc*|*-beta*|*-alpha*) prerelease=true ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# jq -Rs so the notes are JSON-encoded properly: the changelog is full of
|
# python3, not jq. The changelog is full of quotes, backticks and newlines,
|
||||||
# quotes, backticks and newlines, and hand-built JSON would mangle them.
|
# so the body must be properly JSON-encoded -- but `jq` is not guaranteed on
|
||||||
body="$(jq -Rs . < /tmp/notes.md)"
|
# a self-hosted Gitea runner, and a publish step that dies on a missing tool
|
||||||
payload="$(printf '{"tag_name":%s,"name":%s,"body":%s,"prerelease":%s}' \
|
# leaves a tag with no release behind it. python3 is guaranteed: setup-python
|
||||||
"$(printf '%s' "$TAG" | jq -Rs .)" \
|
# ran above.
|
||||||
"$(printf '%s' "$TAG" | jq -Rs .)" \
|
python3 - "$TAG" "$API" "$TOKEN" "$prerelease" <<'PY'
|
||||||
"$body" "$prerelease")"
|
import json, sys, urllib.error, urllib.request
|
||||||
|
|
||||||
existing="$(curl -sf -H "Authorization: token $TOKEN" \
|
tag, api, token, prerelease = sys.argv[1:5]
|
||||||
"$API/releases/tags/$TAG" 2>/dev/null || true)"
|
with open("/tmp/notes.md", encoding="utf-8") as fh:
|
||||||
|
body = fh.read()
|
||||||
|
|
||||||
if [ -n "$existing" ]; then
|
payload = {
|
||||||
id="$(printf '%s' "$existing" | jq -r .id)"
|
"tag_name": tag, "name": tag, "body": body,
|
||||||
echo "Release $TAG exists (id=$id) — updating notes."
|
"prerelease": prerelease == "true",
|
||||||
curl -sS -X PATCH "$API/releases/$id" \
|
}
|
||||||
-H "Authorization: token $TOKEN" \
|
headers = {
|
||||||
-H "Content-Type: application/json" \
|
"Authorization": f"token {token}",
|
||||||
-d "$payload" -o /dev/null -w 'PATCH -> %{http_code}\n'
|
"Content-Type": "application/json",
|
||||||
else
|
}
|
||||||
curl -sS -X POST "$API/releases" \
|
|
||||||
-H "Authorization: token $TOKEN" \
|
def call(url, method, data=None):
|
||||||
-H "Content-Type: application/json" \
|
req = urllib.request.Request(
|
||||||
-d "$payload" -o /dev/null -w 'POST -> %{http_code}\n'
|
url, method=method, headers=headers,
|
||||||
fi
|
data=json.dumps(data).encode() if data else None)
|
||||||
|
with urllib.request.urlopen(req) as r: # noqa: S310
|
||||||
|
return r.status, json.load(r) if r.length != 0 else {}
|
||||||
|
|
||||||
|
try:
|
||||||
|
_, existing = call(f"{api}/releases/tags/{tag}", "GET")
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
if e.code != 404:
|
||||||
|
raise
|
||||||
|
existing = None
|
||||||
|
|
||||||
|
if existing:
|
||||||
|
status, _ = call(f"{api}/releases/{existing['id']}", "PATCH", payload)
|
||||||
|
print(f"updated release {tag} -> {status}")
|
||||||
|
else:
|
||||||
|
status, _ = call(f"{api}/releases", "POST", payload)
|
||||||
|
print(f"created release {tag} (prerelease={payload['prerelease']}) -> {status}")
|
||||||
|
PY
|
||||||
|
|||||||
@@ -205,3 +205,31 @@ class TestSignificance:
|
|||||||
assert version_tuple("0.4.2") > version_tuple("0.4.1")
|
assert version_tuple("0.4.2") > version_tuple("0.4.1")
|
||||||
# Pre-release suffixes are dropped, not ranked above the release.
|
# Pre-release suffixes are dropped, not ranked above the release.
|
||||||
assert version_tuple("v0.5.0-rc1") == version_tuple("v0.5.0")
|
assert version_tuple("v0.5.0-rc1") == version_tuple("v0.5.0")
|
||||||
|
|
||||||
|
|
||||||
|
class TestCandidateNotesResolveToTheBaseVersion:
|
||||||
|
"""`notes v0.6.0-rc1` must return v0.6.0's section.
|
||||||
|
|
||||||
|
A candidate ships the same code as the release it is a candidate for, and the
|
||||||
|
CHANGELOG only ever has the one section. Without this, the release workflow cut
|
||||||
|
v0.6.0-rc1, passed every gate, and then died extracting the body -- so the tag
|
||||||
|
existed but nothing was ever published. Caught in an rc, which is the entire
|
||||||
|
point of having them.
|
||||||
|
"""
|
||||||
|
|
||||||
|
CHANGELOG = "# C\n\n## v0.6.0 — 2026-07-13\n\n### Added\n- the thing\n\n## v0.5.1 — 2026-07-13\n\n- older\n"
|
||||||
|
|
||||||
|
def test_an_rc_resolves_to_its_base_version(self):
|
||||||
|
body = extract_notes(self.CHANGELOG, "v0.6.0-rc1")
|
||||||
|
assert "the thing" in body
|
||||||
|
assert "older" not in body
|
||||||
|
|
||||||
|
def test_rc10_too(self):
|
||||||
|
assert "the thing" in extract_notes(self.CHANGELOG, "v0.6.0-rc10")
|
||||||
|
|
||||||
|
def test_the_plain_version_still_works(self):
|
||||||
|
assert "the thing" in extract_notes(self.CHANGELOG, "v0.6.0")
|
||||||
|
|
||||||
|
def test_a_genuinely_missing_section_still_raises(self):
|
||||||
|
with pytest.raises(KeyError):
|
||||||
|
extract_notes(self.CHANGELOG, "v9.9.9-rc1")
|
||||||
|
|||||||
@@ -107,10 +107,15 @@ def changelog_versions(text: str) -> list[str]:
|
|||||||
def extract_notes(text: str, version: str) -> str:
|
def extract_notes(text: str, version: str) -> str:
|
||||||
"""The body of one version's section, without its heading.
|
"""The body of one version's section, without its heading.
|
||||||
|
|
||||||
|
A release candidate resolves to its BASE version: v0.6.0-rc2 ships the same code
|
||||||
|
as v0.6.0 and therefore the same notes, and the CHANGELOG only ever has the one
|
||||||
|
section. Without this, the release workflow cut the tag, passed every gate, and
|
||||||
|
then died extracting the body -- so the candidate existed but was never published.
|
||||||
|
|
||||||
Raises KeyError if the version has no section -- a release with an empty or
|
Raises KeyError if the version has no section -- a release with an empty or
|
||||||
wrong body is worse than a failed release.
|
wrong body is worse than a failed release.
|
||||||
"""
|
"""
|
||||||
want = normalise(version)
|
want = base_version(version)
|
||||||
lines = text.splitlines()
|
lines = text.splitlines()
|
||||||
|
|
||||||
start = None
|
start = None
|
||||||
|
|||||||
Reference in New Issue
Block a user