Skip to content

Commit ff4ecbb

Browse files
committed
fix: fail when a release merge goes untagged
1 parent ef571ce commit ff4ecbb

4 files changed

Lines changed: 36 additions & 13 deletions

File tree

‎.github/workflows/release-pr.yml‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ jobs:
174174
fetch-depth: 0
175175
fetch-tags: true
176176
persist-credentials: false
177-
# With no merged pull request, as for a direct push, the script is given null and skips.
177+
# With no merged pull request, as for a direct push, the script is given null. It fails when the version is
178+
# untagged, and skips otherwise.
178179
- name: Read the merged pull request
179180
env:
180181
GH_TOKEN: ${{ github.token }}
@@ -190,7 +191,8 @@ jobs:
190191
echo "::error::More than one merged pull request has $GITHUB_SHA as its merge commit."
191192
exit 1
192193
fi
193-
# fail turns the run red: the version is not x.y.z+tibiash.N, or its tag points at another commit.
194+
# fail turns the run red: the version is not x.y.z+tibiash.N, its tag points at another commit, or it has no
195+
# tag and no merged pull request was found, as for a release merge GitHub did not list yet.
194196
- name: Decide
195197
id: decide
196198
env:
@@ -207,8 +209,9 @@ jobs:
207209
noop) echo "v$version already points at $GITHUB_SHA." ;;
208210
skip) echo "$GITHUB_SHA is not drptbl's merge of the App's release pull request, so nothing is tagged." ;;
209211
fail)
210-
echo "::error::v$version cannot be tagged at $GITHUB_SHA." \
211-
"The version is not x.y.z+tibiash.N, or the tag points at another commit."
212+
echo "::error::v$version cannot be tagged at $GITHUB_SHA. The version is not x.y.z+tibiash.N," \
213+
"its tag points at another commit, or it has no tag and no merged pull request was found." \
214+
"For a release merge, re-run this run once the pull request shows as merged."
212215
exit 1
213216
;;
214217
*)

‎README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ When a step fails:
5252

5353
* The Release PR workflow's `tag` job failed: re-run that run. A run dispatched on `main` checks the newest commit of
5454
`main`, not the merge commit. Until the version is tagged, the next proposal fails, so no version is proposed twice.
55+
When the error says the version has no tag and no merged pull request was found, GitHub had not listed the release
56+
merge yet. Re-run the run once the pull request shows as merged, or dispatch the workflow on `main` while the merge
57+
commit is still its newest commit. A direct push of an untagged version fails the same way.
5558
* The release workflow's `downstream` job failed: the release is published, so don't re-run the release run. Run
5659
`generator.yml` in tibia-sh/tibiawiki-mcp by hand with the version.
5760

‎scripts/release_pr.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,17 @@ def decide_tag(version: str, tags: dict[str, str], head: str, merged_pr: dict |
233233
app_login: The App's login, ``<slug>[bot]``.
234234
235235
Returns:
236-
``skip`` unless ``merged_pr`` is the App's ``release/next`` pull request, merged at ``head`` by the release
237-
approver, a user; else ``fail`` when the version is not ``x.y.z+tibiash.N`` or its tag points at another
238-
commit; else ``noop`` when the tag points at ``head``; else ``tag``.
236+
With no merged pull request, ``fail`` when the version is ``x.y.z+tibiash.N`` and has no tag: a release merge
237+
that GitHub did not list yet, or a direct push, which would otherwise leave the release untagged unseen.
238+
Otherwise ``skip`` unless ``merged_pr`` is the App's ``release/next`` pull request, merged at ``head`` by the
239+
release approver, a user; else ``fail`` when the version is not ``x.y.z+tibiash.N`` or its tag points at
240+
another commit; else ``noop`` when the tag points at ``head``; else ``tag``.
239241
"""
242+
tagged = tags.get(f"v{version}")
243+
if merged_pr is None and GENERATOR_VERSION.fullmatch(version) and tagged is None:
244+
return "fail"
240245
if not _approved_release_merge(merged_pr, head, app_login):
241246
return "skip"
242-
tagged = tags.get(f"v{version}")
243247
if not GENERATOR_VERSION.fullmatch(version) or tagged not in {None, head}:
244248
return "fail"
245249
return "noop" if tagged == head else "tag"

‎tests/test_release_pr.py‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,16 @@ def test_tags_the_approved_release_merge(self):
180180
def test_skips_an_ordinary_push_after_a_tagged_release(self):
181181
self.assertEqual("skip", self.decide(None, {"v9.0.0+tibiash.3": OLD}))
182182

183-
def test_skips_a_direct_push(self):
184-
self.assertEqual("skip", self.decide(None))
183+
def test_fails_an_untagged_version_with_no_merged_pr(self):
184+
# A release merge that commits/{sha}/pulls did not list yet, or a direct push of an untagged version.
185+
self.assertEqual("fail", self.decide(None))
186+
187+
def test_fails_an_untagged_version_with_no_merged_pr_and_no_tags(self):
188+
self.assertEqual("fail", self.decide(None, {}))
189+
190+
def test_skips_an_ordinary_merge_while_the_version_is_untagged(self):
191+
ordinary = merged_pr(head={"ref": "fix/parser", "sha": "c" * 40}, user={"login": "someone", "type": "User"})
192+
self.assertEqual("skip", self.decide(ordinary))
185193

186194
def test_skips_an_upstream_version(self):
187195
self.assertEqual("skip", self.decide(None, version="9.1.0"))
@@ -298,7 +306,11 @@ def tag_decision(self, pr: object) -> tuple[int, str]:
298306
def test_prints_the_decision_and_the_version(self):
299307
self.assertEqual((0, "decision=tag\nversion=9.0.0+tibiash.3\n"), self.tag_decision(merged_pr()))
300308

301-
def test_null_pr_is_a_skip(self):
309+
def test_null_pr_with_an_untagged_version_fails(self):
310+
self.assertEqual((0, "decision=fail\nversion=9.0.0+tibiash.3\n"), self.tag_decision(None))
311+
312+
def test_null_pr_with_a_tagged_version_skips(self):
313+
self.write("tags.txt", f"{OLD} refs/tags/v9.0.0+tibiash.3\n")
302314
self.assertEqual((0, "decision=skip\nversion=9.0.0+tibiash.3\n"), self.tag_decision(None))
303315

304316
def test_head_must_be_a_full_sha(self):
@@ -571,8 +583,9 @@ def test_decides_with_the_script_and_fails_red(self):
571583
noop) echo "v$version already points at $GITHUB_SHA." ;;
572584
skip) echo "$GITHUB_SHA is not drptbl's merge of the App's release pull request, so nothing is tagged." ;;
573585
fail)
574-
echo "::error::v$version cannot be tagged at $GITHUB_SHA." \\
575-
"The version is not x.y.z+tibiash.N, or the tag points at another commit."
586+
echo "::error::v$version cannot be tagged at $GITHUB_SHA. The version is not x.y.z+tibiash.N," \\
587+
"its tag points at another commit, or it has no tag and no merged pull request was found." \\
588+
"For a release merge, re-run this run once the pull request shows as merged."
576589
exit 1
577590
;;
578591
*)

0 commit comments

Comments
 (0)