2026-08-18 06:56:56 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
# Pure helpers for drill/drill.sh's generated release-record draft (#152).
|
|
|
|
|
|
|
|
|
|
drill_default_run_id() {
|
|
|
|
|
local version="$1" run_date="$2"
|
|
|
|
|
printf 'drill-%s-%s-01\n' "$version" "${run_date//-/}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
drill_resolve_ref_sha() {
|
|
|
|
|
local repo="$1" ref="$2" remote refs sha
|
|
|
|
|
case "$ref" in
|
|
|
|
|
[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
|
|
|
|
|
printf '%s\n' "$ref"
|
|
|
|
|
return
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
case "$repo" in
|
|
|
|
|
/*|./*|../*|http://*|https://*|git@*) remote="$repo" ;;
|
|
|
|
|
*) remote="https://github.com/$repo.git" ;;
|
|
|
|
|
esac
|
|
|
|
|
refs="$(git ls-remote "$remote" \
|
|
|
|
|
"refs/heads/$ref" "refs/tags/$ref" "refs/tags/$ref^{}" 2>/dev/null)" || return 1
|
|
|
|
|
sha="$(printf '%s\n' "$refs" | awk -v ref="$ref" '
|
|
|
|
|
$2 == "refs/tags/" ref "^{}" { peeled=$1 }
|
|
|
|
|
$2 == "refs/heads/" ref { head=$1 }
|
|
|
|
|
$2 == "refs/tags/" ref { tag=$1 }
|
2026-08-18 07:00:36 +00:00
|
|
|
END { if (peeled) print peeled; else if (tag) print tag; else if (head) print head }
|
2026-08-18 06:56:56 +00:00
|
|
|
')"
|
|
|
|
|
[ -n "$sha" ] || return 1
|
|
|
|
|
printf '%s\n' "$sha"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
drill_write_record() {
|
|
|
|
|
local path="$1" version="$2" run_id="$3" host="$4" run_date="$5"
|
|
|
|
|
local box_repo="$6" box_ref="$7" box_sha="$8" rig_repo="$9"
|
|
|
|
|
shift 9
|
|
|
|
|
local rig_ref="$1" rig_sha="$2" invocation="$3" passed="$4" failed="$5"
|
|
|
|
|
local elapsed="$6" findings_name="$7" tmp finding plain total minutes
|
|
|
|
|
local -n record_findings="$findings_name"
|
|
|
|
|
|
|
|
|
|
if [ -e "$path" ]; then
|
|
|
|
|
echo "drill: record path already exists; refusing to overwrite evidence: $path" >&2
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
[ -d "$(dirname "$path")" ] || {
|
|
|
|
|
echo "drill: record directory does not exist: $(dirname "$path")" >&2
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
total=$((passed + failed))
|
|
|
|
|
minutes=$((elapsed / 60))
|
|
|
|
|
tmp="$(mktemp "$path.tmp.XXXXXX")" || return 1
|
|
|
|
|
{
|
|
|
|
|
printf '# Release drill — %s\n\n' "$version"
|
|
|
|
|
printf '> Generated draft: verify the facts and add operator judgement before commit.\n\n'
|
|
|
|
|
printf -- "- **Run ID:** \`%s\`\n" "$run_id"
|
|
|
|
|
printf -- '- **Host:** %s\n' "$host"
|
|
|
|
|
printf -- '- **Date:** %s\n' "$run_date"
|
|
|
|
|
printf -- '- **Candidate refs:**\n'
|
|
|
|
|
printf " - box \`%s\` @ \`%s\` (\`%s\`)\n" "$box_ref" "$box_sha" "$box_repo"
|
|
|
|
|
printf " - rig \`%s\` @ \`%s\` (\`%s\`)\n" "$rig_ref" "$rig_sha" "$rig_repo"
|
|
|
|
|
printf '\n## What ran\n\n'
|
|
|
|
|
printf "\`%s\` — phases A, B, C, E, D, M.\n" "$invocation"
|
|
|
|
|
printf '\n## Result\n\n'
|
|
|
|
|
printf '**%s/%s passed, %s failed.** %s minutes wall clock.\n\n' \
|
|
|
|
|
"$passed" "$total" "$failed" "$minutes"
|
|
|
|
|
if [ "${#record_findings[@]}" -eq 0 ]; then
|
|
|
|
|
printf -- '- No failures or notes recorded by the harness.\n'
|
|
|
|
|
else
|
|
|
|
|
for finding in "${record_findings[@]}"; do
|
|
|
|
|
plain="$(printf '%s' "$finding" | sed $'s/\033\\[[0-9;]*m//g')"
|
|
|
|
|
printf -- '- %s\n' "$plain"
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
} > "$tmp" || { rm -f "$tmp"; return 1; }
|
|
|
|
|
mv "$tmp" "$path"
|
|
|
|
|
}
|