|
3 | 3 | # |
4 | 4 | # 1. Validate (push event) finished and succeeded on exactly this SHA. |
5 | 5 | # 2. If the SHA was merged from a PR, every check on that PR passed or was |
6 | | -# skipped. Blender Smoke runs on PRs only, so this is its evidence. |
| 6 | +# skipped (that includes the PR's Blender Smoke run). |
| 7 | +# 3. If it was a direct push, Blender Smoke (push event) finished and |
| 8 | +# succeeded on this SHA -- unless every file the push changed matches the |
| 9 | +# workflow's paths-ignore, in which case no smoke run exists to wait for. |
7 | 10 | # |
8 | | -# Env: GH_TOKEN, SHA, GITHUB_REPOSITORY. Optional: GATE_EVENT (default push), |
9 | | -# GATE_TIMEOUT seconds (default 1500), GATE_POLL seconds (default 20). |
| 11 | +# Env: GH_TOKEN, SHA, GITHUB_REPOSITORY. Optional: BEFORE (the push's previous |
| 12 | +# head, to diff the whole push), GATE_EVENT (default push), GATE_TIMEOUT seconds |
| 13 | +# for Validate (default 1500), SMOKE_TIMEOUT seconds (default 3600), GATE_POLL |
| 14 | +# seconds (default 20). |
10 | 15 | set -euo pipefail |
11 | 16 |
|
12 | 17 | repo="${GITHUB_REPOSITORY:?}" |
13 | 18 | sha="${SHA:?}" |
14 | 19 | event="${GATE_EVENT:-push}" |
15 | | -deadline=$((SECONDS + ${GATE_TIMEOUT:-1500})) |
16 | 20 |
|
17 | | -while :; do |
18 | | - read -r status conclusion < <( |
19 | | - gh run list --repo "$repo" --workflow validate.yml --commit "$sha" \ |
20 | | - --event "$event" --limit 1 --json status,conclusion \ |
21 | | - --jq '.[0] // {} | "\(.status // "none") \(.conclusion // "none")"' |
22 | | - ) |
23 | | - [ "$status" = "completed" ] && break |
24 | | - if [ "$SECONDS" -ge "$deadline" ]; then |
25 | | - echo "::error::Validate did not finish for $sha (last status: $status)" |
| 21 | +# wait_green WORKFLOW_FILE LABEL TIMEOUT: poll until the newest run of the |
| 22 | +# workflow on $sha completes, then require success. |
| 23 | +wait_green() { |
| 24 | + local wf="$1" label="$2" deadline=$((SECONDS + $3)) status conclusion |
| 25 | + while :; do |
| 26 | + read -r status conclusion < <( |
| 27 | + gh run list --repo "$repo" --workflow "$wf" --commit "$sha" \ |
| 28 | + --event "$event" --limit 1 --json status,conclusion \ |
| 29 | + --jq '.[0] // {} | "\(.status // "none") \(.conclusion // "none")"' |
| 30 | + ) |
| 31 | + [ "$status" = "completed" ] && break |
| 32 | + if [ "$SECONDS" -ge "$deadline" ]; then |
| 33 | + echo "::error::$label did not finish for $sha (last status: $status)" |
| 34 | + exit 1 |
| 35 | + fi |
| 36 | + echo "$label status for $sha: $status; waiting" |
| 37 | + sleep "${GATE_POLL:-20}" |
| 38 | + done |
| 39 | + if [ "$conclusion" != "success" ]; then |
| 40 | + echo "::error::$label concluded '$conclusion' for $sha; not releasing" |
26 | 41 | exit 1 |
27 | 42 | fi |
28 | | - echo "Validate status for $sha: $status; waiting" |
29 | | - sleep "${GATE_POLL:-20}" |
30 | | -done |
| 43 | + echo "$label: success" |
| 44 | +} |
31 | 45 |
|
32 | | -if [ "$conclusion" != "success" ]; then |
33 | | - echo "::error::Validate concluded '$conclusion' for $sha; not releasing" |
34 | | - exit 1 |
35 | | -fi |
36 | | -echo "Validate: success" |
| 46 | +# smoke_applies: 0 when some changed file falls outside blender-smoke.yml's |
| 47 | +# paths-ignore ("**.md", "docs/**", "assets/**"). Unreadable file lists count |
| 48 | +# as "applies" so the gate fails toward waiting, not toward skipping. |
| 49 | +smoke_applies() { |
| 50 | + local files |
| 51 | + if [ -n "${BEFORE:-}" ] && [ "${BEFORE}" != "0000000000000000000000000000000000000000" ]; then |
| 52 | + files=$(gh api "repos/$repo/compare/$BEFORE...$sha" --jq '.files[].filename' 2>/dev/null) || return 0 |
| 53 | + else |
| 54 | + files=$(gh api "repos/$repo/commits/$sha" --jq '.files[].filename' 2>/dev/null) || return 0 |
| 55 | + fi |
| 56 | + [ -n "$files" ] || return 0 |
| 57 | + while IFS= read -r f; do |
| 58 | + case "$f" in |
| 59 | + *.md|docs/*|assets/*) ;; |
| 60 | + *) return 0 ;; |
| 61 | + esac |
| 62 | + done <<< "$files" |
| 63 | + return 1 |
| 64 | +} |
| 65 | + |
| 66 | +wait_green validate.yml Validate "${GATE_TIMEOUT:-1500}" |
37 | 67 |
|
38 | 68 | pr=$(gh api "repos/$repo/commits/$sha/pulls" --jq '.[0].number // empty') |
39 | 69 | if [ -z "$pr" ]; then |
40 | | - echo "No PR is associated with $sha (direct push); Validate alone gates this release" |
| 70 | + if smoke_applies; then |
| 71 | + wait_green blender-smoke.yml "Blender Smoke" "${SMOKE_TIMEOUT:-3600}" |
| 72 | + else |
| 73 | + echo "Direct push changed only smoke-ignored paths; Validate alone gates this release" |
| 74 | + fi |
41 | 75 | exit 0 |
42 | 76 | fi |
43 | 77 |
|
|
0 commit comments