|
14 | 14 | # |
15 | 15 | # The check's details_url deep-links the store's cest-latest.html for this |
16 | 16 | # publish. Ingest writes that file synchronously inside the publish POST, so |
17 | | -# it exists now or never (a failed summary step logs a warning server-side |
18 | | -# and never fails the publish): probe it once, and on a miss post the check |
19 | | -# without the link rather than linking a 404. |
20 | | -# |
21 | | -# The store path is <branch>/<short-sha> with "/" mapped to "_", built by |
22 | | -# src/tests/multi-server/all.mk; read the leaf off prof-results/ rather than |
23 | | -# recomputing it, so the URL cannot drift from the publish. |
| 17 | +# it exists now or never: probe it once, and on a miss post the check without |
| 18 | +# the link rather than linking a 404. The store path is <branch>/<short-sha> |
| 19 | +# with "/" mapped to "_", built by src/tests/multi-server/all.mk; read the |
| 20 | +# leaf off prof-results/ rather than recomputing it, so the URL cannot drift |
| 21 | +# from the publish. |
24 | 22 | # |
25 | 23 |
|
26 | 24 | set -eu |
|
62 | 60 | [ $# -eq 1 ] || { usage >&2; exit 2; } |
63 | 61 | store=${1%/} |
64 | 62 |
|
65 | | -for var in GH_TOKEN GITHUB_SHA GITHUB_REPOSITORY GITHUB_API_URL; do |
66 | | - eval "val=\${$var:-}" |
67 | | - [ -n "$val" ] || { echo "ERROR: $var is not set" >&2; exit 2; } |
68 | | -done |
| 63 | +: "${GH_TOKEN:?}" "${GITHUB_SHA:?}" "${GITHUB_REPOSITORY:?}" "${GITHUB_API_URL:?}" |
69 | 64 |
|
70 | | -# The name stays short and stable; the verdict lives in the title. Check |
71 | | -# runs created with the Actions GITHUB_TOKEN get attached to an arbitrary |
72 | | -# workflow's check suite (GitHub limitation, community discussion #24616), |
73 | | -# so the workflow-name prefix GitHub renders cannot be relied on. |
74 | | -check_name='profiling' |
| 65 | +check_name='profiling: CEst regression' |
| 66 | +api="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY" |
75 | 67 |
|
| 68 | +gh_api() |
| 69 | +{ |
| 70 | + curl -sS --connect-timeout 5 --max-time 20 \ |
| 71 | + -H "Authorization: Bearer $GH_TOKEN" \ |
| 72 | + -H "Accept: application/vnd.github+json" "$@" |
| 73 | +} |
| 74 | + |
| 75 | +# Run the gate. An empty report file stands in when the analyzer dies before |
| 76 | +# writing one, so the check always has a summary body. |
76 | 77 | curl -fsSL -o cest-analyzer "$store/dashboard/bin/cest-analyzer" |
77 | 78 | chmod +x ./cest-analyzer |
78 | 79 | : > cest-latest.md |
|
82 | 83 | echo "cest-analyzer exit code: $rc" |
83 | 84 | [ -s cest-latest.md ] || echo "No comparison report was produced." > cest-latest.md |
84 | 85 |
|
85 | | -leaf=$(cd prof-results 2>/dev/null && ls -d */*/ 2>/dev/null | head -1) || leaf="" |
86 | | -details="$store/data/${leaf%/}/cest-latest.html" |
87 | | -if [ -z "$leaf" ] || ! curl -sfI --connect-timeout 5 --max-time 20 -o /dev/null "$details"; then |
88 | | - echo "warning: $details is not fetchable; posting the check without a details link" |
89 | | - details="" |
90 | | -fi |
91 | | - |
92 | 86 | case "$rc" in |
93 | | -0) conclusion=success; title="no performance degradation detected" ;; |
94 | | -1) conclusion=neutral; title="latest results need review, performance degradation detected" ;; |
95 | | -*) conclusion=neutral; title="gate did not run (analyzer exit $rc)" ;; |
| 87 | +0) conclusion=success; title="No CEst regression" ;; |
| 88 | +1) conclusion=neutral; title="CEst regression vs the previous profiling run" ;; |
| 89 | +*) conclusion=neutral; title="Profiling gate did not run (analyzer exit $rc)" ;; |
96 | 90 | esac |
97 | 91 |
|
| 92 | +# The summary link, if this publish's cest-latest.html is really there. |
| 93 | +details="" |
| 94 | +leaf=$(ls -d prof-results/*/*/ 2>/dev/null | head -n 1) |
| 95 | +if [ -n "$leaf" ]; then |
| 96 | + details="$store/data/${leaf#prof-results/}" |
| 97 | + details="${details%/}/cest-latest.html" |
| 98 | + curl -sfI --connect-timeout 5 --max-time 20 -o /dev/null "$details" || { |
| 99 | + echo "warning: $details is not fetchable; posting the check without a details link" |
| 100 | + details="" |
| 101 | + } |
| 102 | +fi |
| 103 | + |
98 | 104 | # GitHub caps output.summary at 65535 characters; trim below the cap. |
99 | | -payload=$(jq -n --arg name "$check_name" --arg sha "$GITHUB_SHA" \ |
100 | | - --arg conclusion "$conclusion" --arg title "$title" --arg details "$details" \ |
| 105 | +payload=$(jq -n --arg name "$check_name" --arg conclusion "$conclusion" \ |
| 106 | + --arg title "$title" --arg details "$details" \ |
101 | 107 | --rawfile summary cest-latest.md \ |
102 | | - '{name: $name, head_sha: $sha, status: "completed", conclusion: $conclusion, |
| 108 | + '{name: $name, status: "completed", conclusion: $conclusion, |
103 | 109 | output: {title: $title, summary: $summary[0:60000]}} |
104 | 110 | + (if $details != "" then {details_url: $details} else {} end)') |
105 | 111 |
|
106 | | -# One check per commit: a re-run updates the existing run in place. |
107 | | -id=$(curl -sS -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \ |
108 | | - --get --data-urlencode "check_name=$check_name" \ |
109 | | - "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/check-runs" \ |
| 112 | +# One check per commit: update the existing run if there is one, else create |
| 113 | +# (head_sha is only valid on create). |
| 114 | +id=$(gh_api --get --data-urlencode "check_name=$check_name" \ |
| 115 | + "$api/commits/$GITHUB_SHA/check-runs" \ |
110 | 116 | | jq -r '.check_runs[0].id // empty') || id="" |
| 117 | + |
111 | 118 | if [ -n "$id" ]; then |
112 | | - code=$(curl -sS -o /dev/null -w '%{http_code}' -X PATCH \ |
113 | | - -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \ |
114 | | - -d "$(printf '%s' "$payload" | jq 'del(.head_sha)')" \ |
115 | | - "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/check-runs/$id") || code=000 |
116 | | - action="update" |
| 119 | + action=update |
| 120 | + code=$(gh_api -o /dev/null -w '%{http_code}' -X PATCH \ |
| 121 | + -d "$payload" "$api/check-runs/$id") || code=000 |
117 | 122 | else |
118 | | - code=$(curl -sS -o /dev/null -w '%{http_code}' -X POST \ |
119 | | - -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \ |
120 | | - -d "$payload" \ |
121 | | - "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/check-runs") || code=000 |
122 | | - action="create" |
| 123 | + action=create |
| 124 | + payload=$(printf '%s' "$payload" | jq --arg sha "$GITHUB_SHA" '. + {head_sha: $sha}') |
| 125 | + code=$(gh_api -o /dev/null -w '%{http_code}' -X POST \ |
| 126 | + -d "$payload" "$api/check-runs") || code=000 |
123 | 127 | fi |
124 | 128 |
|
125 | 129 | case "$code" in |
|
0 commit comments