Skip to content

Commit f3844cf

Browse files
authored
fix(ci): load Hangar page during old-tag backfills (#84)
1 parent 94204aa commit f3844cf

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

‎.github/workflows/release.yml‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ jobs:
284284
env:
285285
HANGAR_API_TOKEN: ${{ secrets.HANGAR_API_TOKEN }}
286286
RELEASE_TAG: ${{ steps.release-tag.outputs.tag }}
287+
# The checkout may be an old release tag that predates the Hangar
288+
# page source. Read it from the exact commit supplying this workflow.
289+
WORKFLOW_SHA: ${{ github.workflow_sha }}
287290
run: |
288291
set -euo pipefail
289292
@@ -296,6 +299,10 @@ jobs:
296299
echo "::error::Release tag is empty; cannot publish a Hangar version."
297300
exit 1
298301
fi
302+
if [ -z "${WORKFLOW_SHA:-}" ]; then
303+
echo "::error::Workflow commit is empty; cannot load the authoritative Hangar page."
304+
exit 1
305+
fi
299306
300307
API="https://hangar.papermc.io/api/v1"
301308
PROJECT="Connect"
@@ -333,7 +340,16 @@ jobs:
333340
334341
# Sync the public resource page before creating an immutable version.
335342
# If the token lacks edit_page, fail before partially publishing.
336-
jq -n --rawfile content .github/hangar-description.md \
343+
# Backfills check out the release tag, which may predate this file,
344+
# so fetch it from the immutable commit that supplied the workflow.
345+
curl -sS --fail -A "$UA" \
346+
"https://raw.githubusercontent.com/$GITHUB_REPOSITORY/$WORKFLOW_SHA/.github/hangar-description.md" \
347+
-o "$TMP/hangar-description.md"
348+
if [ ! -s "$TMP/hangar-description.md" ]; then
349+
echo "::error::The authoritative Hangar resource page is empty."
350+
exit 1
351+
fi
352+
jq -n --rawfile content "$TMP/hangar-description.md" \
337353
'{path: "", content: $content}' > "$TMP/page.json"
338354
PAGE_CODE="$(api "$TMP/page-response.json" \
339355
-X PATCH "$API/pages/edit/$PROJECT" \

‎core/src/test/java/com/minekube/connect/release/ReleaseHangarPublishTest.java‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,28 @@ void hangarPublishSyncsTheCheckedInResourcePage() throws Exception {
178178
"release workflow does not sync the checked-in resource page");
179179
}
180180

181+
@Test
182+
@SuppressWarnings("unchecked")
183+
void hangarDescriptionComesFromTheWorkflowCommitWhenBackfillingAnOldTag() throws Exception {
184+
List<Map<String, Object>> steps = readBuildJobSteps();
185+
Map<String, Object> step = hangarStep(steps);
186+
187+
Object env = step.get("env");
188+
assertTrue(env instanceof Map, "\"" + HANGAR_STEP + "\" declares no env block");
189+
Object workflowSha = ((Map<String, Object>) env).get("WORKFLOW_SHA");
190+
assertTrue(workflowSha instanceof String
191+
&& ((String) workflowSha).contains("github.workflow_sha"),
192+
"\"" + HANGAR_STEP + "\" does not identify the commit containing its workflow");
193+
194+
String script = hangarScript(steps);
195+
assertTrue(script.contains("$GITHUB_REPOSITORY/$WORKFLOW_SHA/"
196+
+ ".github/hangar-description.md"),
197+
"Hangar description is not loaded from the exact workflow commit");
198+
assertTrue(script.contains("--rawfile content \"$TMP/hangar-description.md\""),
199+
"Hangar page sync still reads the checked-out release tag, where a backfill file "
200+
+ "may not exist");
201+
}
202+
181203
@Test
182204
void hangarPublishVerifiesStoredDigestsAndJarMagic() throws Exception {
183205
String script = hangarScript(readBuildJobSteps());

0 commit comments

Comments
 (0)