fix(release): avoid pre-creating tags before release API call (#413)

Let createRelease own tag creation with target_commitish and remove preflight tag-ref waits to reduce tag visibility races that lead to untagged release behavior.
This commit is contained in:
cucadmuh
2026-05-01 23:29:21 +03:00
committed by GitHub
parent ade4bd8675
commit 47f88374e5
+1 -40
View File
@@ -112,24 +112,7 @@ jobs:
echo "Tag '$TAG' already points to expected source commit $EXPECTED_SHA" echo "Tag '$TAG' already points to expected source commit $EXPECTED_SHA"
fi fi
else else
echo "::warning::Tag '$TAG' does not exist yet. Creating it at $EXPECTED_SHA." echo "Tag '$TAG' does not exist yet; it will be created by createRelease with target_commitish=$EXPECTED_SHA."
git tag "$TAG" "$EXPECTED_SHA"
if ! git push origin "refs/tags/$TAG"; then
echo "::warning::Initial tag push failed (possible race). Re-checking remote tag..."
git fetch --force --tags origin
if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then
TAG_SHA="$(git rev-list -n 1 "refs/tags/$TAG")"
if [ "$TAG_SHA" = "$EXPECTED_SHA" ]; then
echo "::warning::Tag '$TAG' appeared concurrently and already points to expected commit."
else
echo "::error::Tag '$TAG' exists on remote at $TAG_SHA, expected $EXPECTED_SHA"
exit 1
fi
else
echo "::error::Tag '$TAG' still missing after push attempt."
exit 1
fi
fi
fi fi
- name: extract changelog - name: extract changelog
id: changelog id: changelog
@@ -173,28 +156,6 @@ jobs:
throw new Error(`Invalid RELEASE_COMMIT_SHA '${targetCommitish ?? ""}'`); throw new Error(`Invalid RELEASE_COMMIT_SHA '${targetCommitish ?? ""}'`);
} }
// Wait until the tags/<tag> ref is visible in REST API.
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
let tagVisible = false;
for (let attempt = 1; attempt <= 10; attempt++) {
try {
await github.rest.git.getRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${tag}`,
});
tagVisible = true;
break;
} catch (e) {
if (e.status !== 404) throw e;
core.warning(`Tag ref '${tag}' not visible in REST API yet (attempt ${attempt}/10); retrying...`);
await sleep(1000 * attempt);
}
}
if (!tagVisible) {
throw new Error(`Tag ref 'tags/${tag}' is still not visible in REST API after retries`);
}
let releaseId = null; let releaseId = null;
try { try {
const { data } = await github.rest.repos.getReleaseByTag({ const { data } = await github.rest.repos.getReleaseByTag({