Skip to content

Commit 4acb280

Browse files
committed
ci: tidy check-profiling-results.sh
1 parent 8fdbd61 commit 4acb280

1 file changed

Lines changed: 47 additions & 43 deletions

File tree

scripts/ci/check-profiling-results.sh

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
#
1515
# The check's details_url deep-links the store's cest-latest.html for this
1616
# 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.
2422
#
2523

2624
set -eu
@@ -62,17 +60,20 @@ esac
6260
[ $# -eq 1 ] || { usage >&2; exit 2; }
6361
store=${1%/}
6462

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:?}"
6964

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"
7567

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.
7677
curl -fsSL -o cest-analyzer "$store/dashboard/bin/cest-analyzer"
7778
chmod +x ./cest-analyzer
7879
: > cest-latest.md
@@ -82,44 +83,47 @@ rc=0
8283
echo "cest-analyzer exit code: $rc"
8384
[ -s cest-latest.md ] || echo "No comparison report was produced." > cest-latest.md
8485

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-
9286
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)" ;;
9690
esac
9791

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+
98104
# 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" \
101107
--rawfile summary cest-latest.md \
102-
'{name: $name, head_sha: $sha, status: "completed", conclusion: $conclusion,
108+
'{name: $name, status: "completed", conclusion: $conclusion,
103109
output: {title: $title, summary: $summary[0:60000]}}
104110
+ (if $details != "" then {details_url: $details} else {} end)')
105111

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" \
110116
| jq -r '.check_runs[0].id // empty') || id=""
117+
111118
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
117122
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
123127
fi
124128

125129
case "$code" in

0 commit comments

Comments
 (0)