Skip to content

Commit 4eed4a3

Browse files
authored
Fix nightly smoke dispatch picking a stale create-release run (#14949)
* Resolve latest nightly without filtered runs listing A source=nightly dispatch with an empty run-id sometimes picked a months-old create-release run. The workflow runs listing, when filtered by branch and status, intermittently returns an outdated result set: repeated identical calls returned runs from May, June or two weeks ago instead of the latest. The May run had expired artifacts, which surfaced as "produced none of the expected artifacts"; a run within the 90-day artifact retention would instead have been tested silently as if it were the latest nightly. Listing without server-side filters and selecting the newest successful main run in jq returned the correct run on every call. The listing is still external state, so an auto-resolved run older than three days now fails with a message asking for an explicit run-id rather than testing a stale build. An explicit run-id bypasses the check. * Compare nightly run age in seconds for the staleness check Integer division to whole days truncated partial days, so a run just under four days old passed the three-day limit.
1 parent 5757cfc commit 4eed4a3

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

‎.github/workflows/test-smokes-built.yml‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,21 @@ jobs:
267267
run: |
268268
run_id="$RUN_ID_INPUT"
269269
if [ -z "$run_id" ]; then
270-
run_id="$(gh run list --repo "$GITHUB_REPOSITORY" --workflow create-release.yml \
271-
--branch main --status success --limit 1 --json databaseId --jq '.[0].databaseId // empty')"
272-
fi
273-
if [ -z "$run_id" ]; then
274-
echo "::error::No successful create-release run was found. Provide a run ID or complete a create-release run first."
275-
exit 1
270+
# The runs listing intermittently returns an outdated result set when
271+
# filtered by branch or status, so filter and sort client-side.
272+
latest="$(gh run list --repo "$GITHUB_REPOSITORY" --workflow create-release.yml \
273+
--limit 30 --json databaseId,createdAt,headBranch,conclusion \
274+
--jq '[.[] | select(.headBranch == "main" and .conclusion == "success")] | sort_by(.createdAt) | last // empty | "\(.databaseId) \(.createdAt)"')"
275+
read -r run_id created_at <<<"$latest"
276+
if [ -z "$run_id" ]; then
277+
echo "::error::No successful create-release run was found. Provide a run ID or complete a create-release run first."
278+
exit 1
279+
fi
280+
age_seconds=$(( $(date +%s) - $(date -d "$created_at" +%s) ))
281+
if [ "$age_seconds" -gt $(( 3 * 86400 )) ]; then
282+
echo "::error::Latest successful create-release run ${run_id} is $(( age_seconds / 86400 )) days old (${created_at}); the runs listing may be outdated. Provide a run ID explicitly."
283+
exit 1
284+
fi
276285
fi
277286
sha="$(gh run view "$run_id" --repo "$GITHUB_REPOSITORY" --json headSha --jq '.headSha // empty')"
278287
if [ -z "$sha" ]; then

0 commit comments

Comments
 (0)