feat(ci): publish precompiled query regression helpers with pin update PRs

Signed-off-by: WenyXu <wenymedia@gmail.com>
This commit is contained in:
WenyXu
2026-10-28 13:59:45 +00:00
parent f5140844f4
commit 910eb0f377
11 changed files with 487 additions and 9 deletions
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
set -euo pipefail
: "${CARGO_TARGET_DIR:?CARGO_TARGET_DIR must be configured by the runner}"
revision="$(git rev-parse HEAD)"
repository=greptime-registry.cn-hangzhou.cr.aliyuncs.com/tools/query-regression-helpers
# A rerun gets a distinct tag; consumers always use the registry digest.
tag="${repository}:${revision}-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
staging="$(mktemp -d)"
trap 'rm -rf -- "$staging"' EXIT
cargo build --profile nightly -p cmd --features dev-tools \
--bin query_perf_fixture --bin query_regression_runner
for binary in query_perf_fixture query_regression_runner; do
"$CARGO_TARGET_DIR/nightly/$binary" --help >/dev/null
cp "$CARGO_TARGET_DIR/nightly/$binary" "$staging/$binary"
done
docker build --build-arg "SOURCE_REVISION=$revision" \
--file docker/query-regression-helpers/Dockerfile --tag "$tag" "$staging"
docker push "$tag"
image="$(docker image inspect "$tag" --format '{{index .RepoDigests 0}}')"
[[ "$image" == "$repository@sha256:"* ]]
# Verify the published artifact through the same extraction path as consumers.
python3 .github/scripts/query-regression-helpers.py "$image" "$staging/extracted"
for binary in query_perf_fixture query_regression_runner; do
cmp "$staging/$binary" "$staging/extracted/$binary"
done
# Hold the revision and cases constant: compare source-built versus extracted
# fixture normalization twice. Keep the raw outputs as workflow artifacts.
mkdir -p helpers-validation
printf '%s\n' "$revision" > helpers-validation/source-revision.txt
printf '%s\n' "$image" > helpers-validation/image.txt
for iteration in 1 2; do
while IFS= read -r case; do
name="$(basename "$(dirname "$case")")"
for mode in source image; do
binary="$staging/query_perf_fixture"
[[ "$mode" != image ]] || binary="$staging/extracted/query_perf_fixture"
"$binary" plan --case "$case" > "helpers-validation/${name}-${iteration}-${mode}.json"
done
cmp "helpers-validation/${name}-${iteration}-source.json" \
"helpers-validation/${name}-${iteration}-image.json"
done < <(find tests/perf/query_cases -name case.toml -type f | sort)
done
printf 'image=%s\n' "$image" >> "$GITHUB_OUTPUT"
printf 'Published helpers: `%s` (source `%s`)\n' "$image" "$revision" >> "$GITHUB_STEP_SUMMARY"
@@ -0,0 +1,68 @@
#!/usr/bin/env python3
# Copyright 2023 Greptime Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Extract digest-pinned query regression tools from an artifact image."""
import argparse
import json
import re
import subprocess
from pathlib import Path
BINARIES = ("query_perf_fixture", "query_regression_runner")
PIN = Path(__file__).resolve().parents[1] / "query-regression-helpers-image.txt"
def resolve_image(value, pin=PIN):
if value == "pinned":
value = pin.read_text().strip()
if not re.fullmatch(r"[a-zA-Z0-9][a-zA-Z0-9._/:@-]*@sha256:[0-9a-f]{64}", value):
raise ValueError("helpers_image requires an image@sha256 digest; publish and merge the pin-update PR before using 'pinned'")
return value
def run(*args):
return subprocess.check_output(args, text=True).strip()
def extract(image, destination):
image = resolve_image(image)
destination.mkdir(parents=True, exist_ok=True)
run("docker", "pull", image)
metadata = json.loads(run("docker", "image", "inspect", image))[0]
revision = (metadata.get("Config", {}).get("Labels") or {}).get("org.opencontainers.image.revision", "")
if not re.fullmatch(r"[0-9a-f]{40}", revision):
raise ValueError("Helper image is missing its source revision label")
container = run("docker", "create", image, "/query_perf_fixture", "--help")
try:
for binary in BINARIES:
target = destination / binary
run("docker", "cp", f"{container}:/{binary}", str(target))
target.chmod(0o755)
run(str(target.resolve()), "--help")
finally:
run("docker", "rm", "--force", "--volumes", container)
provenance = {"image": image, "image_id": metadata["Id"], "source_revision": revision}
(destination / "helpers-image.json").write_text(json.dumps(provenance, indent=2) + "\n")
print(json.dumps(provenance))
return provenance
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("image")
parser.add_argument("destination", type=Path)
args = parser.parse_args()
extract(args.image, args.destination)
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
set -euo pipefail
: "${HELPERS_IMAGE:?Published image digest is required}"
repository=greptime-registry.cn-hangzhou.cr.aliyuncs.com/tools/query-regression-helpers
[[ "$HELPERS_IMAGE" =~ ^${repository}@sha256:[0-9a-f]{64}$ ]]
branch="ci/update-query-regression-helpers-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
git config user.name greptimedb-ci
git config user.email greptimedb-ci@greptime.com
git fetch origin main
git checkout -b "$branch" origin/main
pin=.github/query-regression-helpers-image.txt
printf '%s\n' "$HELPERS_IMAGE" > "$pin"
git add "$pin"
if git diff --cached --quiet; then
echo 'Helper image pin is already current.'
exit 0
fi
git commit -s -m 'ci(query-regression): update precompiled helpers image'
git push origin "HEAD:refs/heads/$branch"
body="$(mktemp)"
trap 'rm -f -- "$body"' EXIT
cat > "$body" <<EOF
I hereby agree to the terms of the [GreptimeDB CLA](https://github.com/GreptimeTeam/.github/blob/main/CLA.md).
## Refer to a related PR or issue link (optional)
${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}
## What's changed and what's your intention?
Update the query-regression helper image to \`$HELPERS_IMAGE\`, built from \`$GITHUB_SHA\`.
The publishing job extracted both binaries from the published digest, ran their help commands, and checked that they matched the build outputs.
Runs opting into \`helpers_image: pinned\` use this version after merge. Source-build defaults are unchanged.
## PR Checklist
- [ ] I have written the necessary rustdoc comments.
- [x] I have added the necessary unit tests and integration tests.
- [ ] This PR requires documentation updates.
- [x] API changes are backward compatible.
- [x] Schema or data changes are backward compatible.
- [ ] This PR needs to be backported to release branches, and I have added the matching labels.
EOF
gh pr create --draft --base main --head "$branch" \
--title 'ci(query-regression): update precompiled helpers image' --body-file "$body"