Skip to content

Commit 7228bc8

Browse files
committed
fix(gitee-release): delete and recreate release for "latest" (anomalyco#42)
1 parent 0d9dec0 commit 7228bc8

3 files changed

Lines changed: 23 additions & 15 deletions

File tree

‎packages/ellamaka/test/create-gitee-release.test.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ describe("create-gitee-release.mjs", () => {
106106
expect(JSON.parse(mocked.calls[1][1].body as string).tag_name).toBe("v0.1.0")
107107
})
108108

109-
test("updates an existing release", async () => {
110-
const mocked = makeFetch([response(200, { id: 99 }), response(200, { id: 99 })])
109+
test("deletes and recreates an existing release", async () => {
110+
const mocked = makeFetch([response(200, { id: 99 }), response(204, ""), response(201, { id: 100 })])
111111
const result = await script.createOrGetRelease({
112112
fetch: mocked.fetch,
113113
baseUrl: "https://gitee.test/api/v5",
@@ -119,9 +119,11 @@ describe("create-gitee-release.mjs", () => {
119119
token: "TOKEN",
120120
})
121121

122-
expect(result).toEqual({ id: 99, created: false })
123-
expect(mocked.calls[1][1].method).toBe("PATCH")
124-
expect(JSON.parse(mocked.calls[1][1].body as string).body).toBe("updated notes")
122+
expect(result).toEqual({ id: 100, created: true })
123+
expect(mocked.calls).toHaveLength(3)
124+
expect(mocked.calls[1][1].method).toBe("DELETE")
125+
expect(mocked.calls[2][1].method).toBe("POST")
126+
expect(JSON.parse(mocked.calls[2][1].body as string).body).toBe("updated notes")
125127
})
126128

127129
test("treats null lookup body as missing release", async () => {

‎scripts/create-gitee-release.mjs‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ export async function createOrGetRelease({ fetch, baseUrl, owner, repo, tag, ver
7373
const tagBody = tagResp.status === 404 ? null : await readJson(tagResp, "lookup release by tag")
7474

7575
if (tagBody && typeof tagBody === "object" && tagBody.id) {
76-
const updateUrl = `${baseUrl}/repos/${owner}/${repo}/releases/${tagBody.id}?access_token=${encodeURIComponent(token)}`
77-
const updateResp = await fetch(updateUrl, {
78-
method: "PATCH",
79-
headers: { "Content-Type": "application/json" },
80-
body: JSON.stringify(buildUpdateBody({ version, tag, notesContent, token, productName })),
81-
})
82-
const updated = await readJson(updateResp, "update release")
83-
if (!updated || !updated.id) throw new Error(`Update returned no id: ${JSON.stringify(updated)}`)
84-
return { id: updated.id, created: false }
76+
// Delete and recreate so created_at reflects the current release date.
77+
// PATCH preserves the original created_at, which keeps the release from
78+
// appearing as "latest" on the Gitee homepage.
79+
const deleteUrl = `${baseUrl}/repos/${owner}/${repo}/releases/${tagBody.id}?access_token=${encodeURIComponent(token)}`
80+
const deleteResp = await fetch(deleteUrl, { method: "DELETE" })
81+
if (deleteResp.status !== 204) {
82+
const text = await deleteResp.text()
83+
throw new Error(`delete release failed: HTTP ${deleteResp.status} — ${text}`)
84+
}
8585
}
8686

8787
const createUrl = `${baseUrl}/repos/${owner}/${repo}/releases`

‎scripts/tag-release.sh‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,14 @@ POLL_INTERVAL=15
123123
i=0
124124
while true; do
125125
i=$((i + 1))
126-
STATUS=$(gh run view "$RUN_ID" -R wopal-cn/ellamaka --json status,conclusion -q '[.status, .conclusion] | join(" ")' 2>/dev/null || echo "unknown")
126+
FULL=$(gh run view "$RUN_ID" -R wopal-cn/ellamaka --json status,conclusion,jobs -q '
127+
"\(.status) \(.conclusion // "")",
128+
(.jobs // [] | map(" [\(.status)] \(.name): \(.conclusion // "running...")") | join("\n"))
129+
' 2>/dev/null || echo "unknown")
130+
131+
STATUS=$(echo "$FULL" | head -n 1)
127132
echo " [$i] $STATUS"
133+
echo "$FULL" | tail -n +2
128134

129135
case "$STATUS" in
130136
"completed success") break ;;

0 commit comments

Comments
 (0)