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"
+1
View File
@@ -100,6 +100,7 @@ jobs:
python3 tests/perf/test_query_regression_runner_otlp_trace_load.py
python3 tests/perf/test_query_regression_summary_otlp.py
python3 tests/perf/test_query_regression_case_selection.py
python3 tests/perf/test_query_regression_helpers.py
python3 tests/perf/test_query_regression_nightly_refs.py
python3 tests/perf/test_query_regression_slash.py
python3 tests/perf/test_aliyun_ecs_runner_scripts.py
@@ -0,0 +1,132 @@
name: Publish query regression helpers
on:
workflow_dispatch:
workflow_call:
push:
branches: [main]
paths:
- src/cmd/src/bin/query_perf_fixture.rs
- src/cmd/src/bin/query_perf_fixture/**
- src/cmd/src/bin/query_regression_runner.rs
- src/cmd/src/bin/query_regression_runner/**
- docker/query-regression-helpers/**
- .github/workflows/publish-query-regression-helpers.yml
- .github/scripts/publish-query-regression-helpers.sh
- Cargo.lock
permissions:
contents: read
# Serialize publication so pin-update PRs follow source order.
concurrency:
group: publish-query-regression-helpers
cancel-in-progress: false
jobs:
provision:
if: ${{ github.repository == 'GreptimeTeam/greptimedb' }}
runs-on: ubuntu-latest
timeout-minutes: 45
outputs:
label: ${{ steps.provision.outputs.label }}
instance_id: ${{ steps.provision.outputs.instance_id }}
runner_name: ${{ steps.provision.outputs.runner_name }}
steps:
- name: Checkout trusted provisioning scripts
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
ref: ${{ github.sha }}
persist-credentials: false
- name: Provision ECS runner
id: provision
uses: ./.github/actions/aliyun-ecs-create
with:
access-key-id: ${{ secrets.ALICLOUD_ECS_ACCESS_KEY_ID }}
access-key-secret: ${{ secrets.ALICLOUD_ECS_ACCESS_KEY_SECRET }}
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
region-id: ${{ vars.ALIYUN_ECS_REGION_ID }}
vswitch-id: ${{ vars.ALIYUN_ECS_VSWITCH_ID }}
security-group-id: ${{ vars.ALIYUN_ECS_SECURITY_GROUP_ID }}
instance-type: ${{ vars.ALIYUN_ECS_INSTANCE_TYPE }}
# Preserve query regression's original resource and janitor budgets.
system-disk-gib: '80'
ttl-hours: '4'
enable-docker: 'true'
resource-group-id: ${{ vars.ALIYUN_ECS_RESOURCE_GROUP_ID }}
image-id: ${{ vars.QUERY_REGRESSION_ECS_IMAGE_ID }}
runner-uid: ${{ vars.QUERY_REGRESSION_RUNNER_UID || '1001' }}
runner-gid: ${{ vars.QUERY_REGRESSION_RUNNER_GID || '1001' }}
publish:
needs: provision
runs-on: ${{ needs.provision.outputs.label }}
timeout-minutes: 150
outputs:
image: ${{ steps.publish.outputs.image }}
env:
CARGO_HOME: /home/runner/.cargo
CARGO_TARGET_DIR: /home/runner/query-regression-target
RUSTUP_HOME: /opt/rustup
RUSTUP_TOOLCHAIN: nightly-2026-03-21
RUSTUP_AUTO_INSTALL: "0"
CARGO_INCREMENTAL: "0"
RUSTFLAGS: -D warnings -C link-arg=-fuse-ld=mold
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Login to registry
uses: docker/login-action@v3
with:
registry: greptime-registry.cn-hangzhou.cr.aliyuncs.com
username: ${{ secrets.ALICLOUD_USERNAME }}
password: ${{ secrets.ALICLOUD_PASSWORD }}
- name: Build, verify and publish helpers
id: publish
run: bash .github/scripts/publish-query-regression-helpers.sh
- name: Upload helper validation evidence
if: always()
uses: actions/upload-artifact@v4
with:
name: helpers-validation
path: helpers-validation/
if-no-files-found: warn
update-pin:
needs: publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
- name: Open image pin update PR
env:
GH_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
HELPERS_IMAGE: ${{ needs.publish.outputs.image }}
run: bash .github/scripts/update-query-regression-helpers-image.sh
teardown:
if: ${{ always() && needs.provision.outputs.instance_id != '' }}
needs: [provision, publish]
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout trusted teardown scripts
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
ref: ${{ github.sha }}
persist-credentials: false
- name: Teardown ECS runner
uses: ./.github/actions/aliyun-ecs-delete
with:
access-key-id: ${{ secrets.ALICLOUD_ECS_ACCESS_KEY_ID }}
access-key-secret: ${{ secrets.ALICLOUD_ECS_ACCESS_KEY_SECRET }}
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
region-id: ${{ vars.ALIYUN_ECS_REGION_ID }}
instance-id: ${{ needs.provision.outputs.instance_id }}
runner-name: ${{ needs.provision.outputs.runner_name }}
+37 -9
View File
@@ -36,6 +36,11 @@ on:
required: false
type: string
default: ""
helpers_image:
description: Helpers image@sha256 or pinned (empty builds helpers from source)
required: false
type: string
default: ""
cargo_profile:
description: Cargo profile to build base and candidate binaries with
required: false
@@ -100,6 +105,11 @@ on:
required: false
type: string
default: ""
helpers_image:
description: Helpers image@sha256 or pinned (empty builds helpers from source)
required: false
type: string
default: ""
cargo_profile:
description: Cargo profile to build base and candidate binaries with
required: true
@@ -152,6 +162,7 @@ jobs:
python3 tests/perf/test_query_regression_runner_otlp_trace_load.py
python3 tests/perf/test_query_regression_summary_otlp.py
python3 tests/perf/test_query_regression_case_selection.py
python3 tests/perf/test_query_regression_helpers.py
python3 tests/perf/test_query_regression_nightly_refs.py
python3 tests/perf/test_query_regression_slash.py
python3 tests/perf/test_aliyun_ecs_runner_scripts.py
@@ -191,7 +202,7 @@ jobs:
# Preserve query regression's original resource and janitor budgets.
system-disk-gib: '80'
ttl-hours: '4'
enable-docker: ${{ inputs.base_image != '' || inputs.candidate_image != '' }}
enable-docker: ${{ inputs.base_image != '' || inputs.candidate_image != '' || inputs.helpers_image != '' }}
resource-group-id: ${{ vars.ALIYUN_ECS_RESOURCE_GROUP_ID }}
image-id: ${{ vars.QUERY_REGRESSION_ECS_IMAGE_ID }}
runner-uid: ${{ vars.QUERY_REGRESSION_RUNNER_UID || '1001' }}
@@ -235,6 +246,7 @@ jobs:
PR_NUMBER: ${{ inputs.pr_number }}
HEAD_REPO: ${{ inputs.head_repo }}
BASE_REPO: ${{ inputs.base_repo }}
HELPERS_IMAGE: ${{ inputs.helpers_image }}
BASE_IMAGE: ${{ inputs.base_image }}
CANDIDATE_IMAGE: ${{ inputs.candidate_image }}
BASE_REF: ${{ inputs.base_ref }}
@@ -249,11 +261,11 @@ jobs:
steps:
- name: Validate image target admission
run: |
if [[ "${PR_ADMISSION}" == "true" && ( -n "${BASE_IMAGE}" || -n "${CANDIDATE_IMAGE}" ) ]]; then
if [[ "${PR_ADMISSION}" == "true" && ( -n "${BASE_IMAGE}" || -n "${CANDIDATE_IMAGE}" || -n "${HELPERS_IMAGE}" ) ]]; then
echo "PR admission requires source targets for verified commit attribution." >&2
exit 1
fi
if [[ -n "${BASE_IMAGE}" || -n "${CANDIDATE_IMAGE}" ]]; then
if [[ -n "${BASE_IMAGE}" || -n "${CANDIDATE_IMAGE}" || -n "${HELPERS_IMAGE}" ]]; then
docker info >/dev/null
fi
@@ -451,6 +463,7 @@ jobs:
> "${GITHUB_WORKSPACE}/query-regression-trusted-scripts/query-regression-summary.py"
- name: Verify runner image tools
if: ${{ inputs.base_image == '' || inputs.candidate_image == '' || inputs.helpers_image == '' }}
shell: bash
run: |
set -euo pipefail
@@ -567,6 +580,7 @@ jobs:
fi
- name: Prepare query regression cache
if: ${{ inputs.base_image == '' || inputs.candidate_image == '' || inputs.helpers_image == '' }}
shell: bash
working-directory: src
run: |
@@ -762,7 +776,16 @@ jobs:
git reset --hard "${VERIFIED_CANDIDATE_SHA}"
git clean -ffdx
- name: Extract precompiled query regression helpers
if: ${{ inputs.helpers_image != '' }}
working-directory: src
run: |
python3 .github/scripts/query-regression-helpers.py "$HELPERS_IMAGE" \
"$GITHUB_WORKSPACE/query-regression-bins/candidate"
cat "$GITHUB_WORKSPACE/query-regression-bins/candidate/helpers-image.json" >> "$GITHUB_STEP_SUMMARY"
- name: Build candidate greptime and query regression helpers
if: ${{ inputs.candidate_image == '' || inputs.helpers_image == '' }}
working-directory: src
run: |
set -euo pipefail
@@ -770,8 +793,10 @@ jobs:
if [[ -z "${CANDIDATE_IMAGE}" ]]; then
cargo build --profile "${CARGO_PROFILE}" -p cmd --bin greptime
fi
cargo build --profile "${CARGO_PROFILE}" -p cmd --bin query_perf_fixture --features dev-tools
cargo build --profile "${CARGO_PROFILE}" -p cmd --bin query_regression_runner --features dev-tools
if [[ -z "${HELPERS_IMAGE}" ]]; then
cargo build --profile "${CARGO_PROFILE}" -p cmd --bin query_perf_fixture --features dev-tools
cargo build --profile "${CARGO_PROFILE}" -p cmd --bin query_regression_runner --features dev-tools
fi
candidate_build_elapsed="${SECONDS}"
printf 'Candidate greptime and query regression helper cargo builds elapsed: %s seconds\n' "${candidate_build_elapsed}"
printf -- '- Candidate greptime and query regression helper cargo builds: %s seconds\n' "${candidate_build_elapsed}" >> "${GITHUB_STEP_SUMMARY}"
@@ -785,10 +810,12 @@ jobs:
cp "${CARGO_TARGET_DIR}/${target_dir}/greptime" \
"${GITHUB_WORKSPACE}/query-regression-bins/candidate/greptime"
fi
cp "${CARGO_TARGET_DIR}/${target_dir}/query_perf_fixture" \
"${GITHUB_WORKSPACE}/query-regression-bins/candidate/query_perf_fixture"
cp "${CARGO_TARGET_DIR}/${target_dir}/query_regression_runner" \
"${GITHUB_WORKSPACE}/query-regression-bins/candidate/query_regression_runner"
if [[ -z "${HELPERS_IMAGE}" ]]; then
cp "${CARGO_TARGET_DIR}/${target_dir}/query_perf_fixture" \
"${GITHUB_WORKSPACE}/query-regression-bins/candidate/query_perf_fixture"
cp "${CARGO_TARGET_DIR}/${target_dir}/query_regression_runner" \
"${GITHUB_WORKSPACE}/query-regression-bins/candidate/query_regression_runner"
fi
- name: Run query regression
id: run
@@ -830,6 +857,7 @@ jobs:
query-regression-work/**/logs/**
query-regression-work/**/otelgen/**
query-regression-summary.md
query-regression-bins/candidate/helpers-image.json
machine-telemetry.log
if-no-files-found: warn
retention-days: 7
@@ -35,6 +35,11 @@ on:
description: Rebuild the query-regression ECS runner image (and update QUERY_REGRESSION_ECS_IMAGE_ID + RUNNER_IMAGE_EPOCH)
required: false
default: false
release_query_regression_helpers_image:
type: boolean
description: Publish precompiled query regression helpers and open a pin-update PR
required: false
default: false
update_dev_builder_image_tag:
type: boolean
description: Update the DEV_BUILDER_IMAGE_TAG in Makefile and create a PR
@@ -451,3 +456,8 @@ jobs:
echo "## Lockstep updates" >> "$GITHUB_STEP_SUMMARY"
echo "- QUERY_REGRESSION_ECS_IMAGE_ID → \`${image_id}\`" >> "$GITHUB_STEP_SUMMARY"
echo "- RUNNER_IMAGE_EPOCH → \`${new_epoch}\` (PR on \`${BRANCH}\`, pending review/merge)" >> "$GITHUB_STEP_SUMMARY"
release-query-regression-helpers:
if: ${{ github.repository == 'GreptimeTeam/greptimedb' && inputs.release_query_regression_helpers_image }}
uses: ./.github/workflows/publish-query-regression-helpers.yml
secrets: inherit