diff --git a/.github/query-regression-helpers-image.txt b/.github/query-regression-helpers-image.txt deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/.github/scripts/query-regression-helpers.py b/.github/scripts/query-regression-helpers.py index 8e25c9f840c..7f1e22a5c83 100644 --- a/.github/scripts/query-regression-helpers.py +++ b/.github/scripts/query-regression-helpers.py @@ -18,19 +18,19 @@ import argparse import hashlib import json +import os 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): +def resolve_image(value): if value == "pinned": - value = pin.read_text().strip() + value = os.environ.get("QUERY_REGRESSION_HELPERS_IMAGE", "") 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'") + raise ValueError("helpers_image requires an image@sha256 digest; set QUERY_REGRESSION_HELPERS_IMAGE by publishing a verified image before using 'pinned'") return value diff --git a/.github/scripts/update-query-regression-helpers-image.sh b/.github/scripts/update-query-regression-helpers-image.sh index 230c0d0b8c4..9ef9122da74 100644 --- a/.github/scripts/update-query-regression-helpers-image.sh +++ b/.github/scripts/update-query-regression-helpers-image.sh @@ -1,45 +1,14 @@ #!/usr/bin/env bash set -euo pipefail -: "${HELPERS_IMAGE:?Published image digest is required}" +: "${HELPERS_IMAGE:?Verified image digest is required}" +: "${GITHUB_REPOSITORY:?Repository 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" </dev/null +printf 'QUERY_REGRESSION_HELPERS_IMAGE updated to `%s`\n' "$HELPERS_IMAGE" diff --git a/.github/workflows/publish-query-regression-helpers.yml b/.github/workflows/publish-query-regression-helpers.yml index e899fcb8ae3..eca58cff96d 100644 --- a/.github/workflows/publish-query-regression-helpers.yml +++ b/.github/workflows/publish-query-regression-helpers.yml @@ -14,12 +14,13 @@ on: - .github/workflows/publish-query-regression-helpers.yml - .github/scripts/publish-query-regression-helpers.sh - .github/scripts/build-query-regression-helpers.sh + - .github/scripts/update-query-regression-helpers-image.sh - Cargo.lock permissions: contents: read -# Serialize publication so pin-update PRs follow source order. +# Serialize publication and updates of the repository image variable. concurrency: group: publish-query-regression-helpers cancel-in-progress: false @@ -128,14 +129,14 @@ jobs: helpers-validation/extracted/helpers-image.json if-no-files-found: warn - update-pin: + update-variable: needs: publish runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: - token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} - - name: Open image pin update PR + persist-credentials: false + - name: Update helpers image repository variable env: GH_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} HELPERS_IMAGE: ${{ needs.publish.outputs.image }} diff --git a/.github/workflows/query-regression.yml b/.github/workflows/query-regression.yml index cee15637fb3..d65d6666658 100644 --- a/.github/workflows/query-regression.yml +++ b/.github/workflows/query-regression.yml @@ -37,7 +37,7 @@ on: type: string default: "" helpers_image: - description: Helpers image@sha256 or pinned (empty builds helpers from source) + description: Helpers image@sha256 or pinned from repository variable (empty builds from source) required: false type: string default: "" @@ -106,7 +106,7 @@ on: type: string default: "" helpers_image: - description: Helpers image@sha256 or pinned (empty builds helpers from source) + description: Helpers image@sha256 or pinned from repository variable (empty builds from source) required: false type: string default: "" @@ -247,6 +247,7 @@ jobs: HEAD_REPO: ${{ inputs.head_repo }} BASE_REPO: ${{ inputs.base_repo }} HELPERS_IMAGE: ${{ inputs.helpers_image }} + QUERY_REGRESSION_HELPERS_IMAGE: ${{ vars.QUERY_REGRESSION_HELPERS_IMAGE }} BASE_IMAGE: ${{ inputs.base_image }} CANDIDATE_IMAGE: ${{ inputs.candidate_image }} BASE_REF: ${{ inputs.base_ref }} diff --git a/.github/workflows/release-dev-builder-images.yaml b/.github/workflows/release-dev-builder-images.yaml index 6d1eaf2ea6b..9f74035f8c9 100644 --- a/.github/workflows/release-dev-builder-images.yaml +++ b/.github/workflows/release-dev-builder-images.yaml @@ -37,7 +37,7 @@ on: default: false release_query_regression_helpers_image: type: boolean - description: Publish precompiled query regression helpers and open a pin-update PR + description: Publish precompiled query regression helpers and update the image repository variable required: false default: false update_dev_builder_image_tag: diff --git a/tests/perf/README.md b/tests/perf/README.md index fc4e326d7e9..a7e698fe047 100644 --- a/tests/perf/README.md +++ b/tests/perf/README.md @@ -620,7 +620,7 @@ Additional SQL optimizer cases: `helpers_image` is optional in Query Regression (dispatch and reusable calls). The empty default still builds both helpers from the candidate source. Set it to -`pinned` to use `.github/query-regression-helpers-image.txt`, or provide an explicit +`pinned` to use the `QUERY_REGRESSION_HELPERS_IMAGE` repository variable, or provide an explicit `image@sha256:...` reference. With both database image inputs and a helper image, the run skips all Cargo builds and build-cache preparation. PR comment admission continues to require source builds. @@ -638,10 +638,15 @@ the case DSL. The **Publish query regression helpers** workflow builds and pushes to `greptime-registry.cn-hangzhou.cr.aliyuncs.com/tools/query-regression-helpers`. It runs manually or on main when helper sources, packaging, or Cargo.lock change. -After verifying the published digest, it opens a draft PR updating the pin, like -the runner-image update workflow. Review and merge that PR before using `pinned` -for the first time (the initial pin is deliberately empty). No mutable `latest` -tag is consumed and publication alone does not change the version used by runs. +After verifying the published digest, it creates or updates the +`QUERY_REGRESSION_HELPERS_IMAGE` Actions repository variable, using +`GH_PERSONAL_ACCESS_TOKEN` with Actions-variable write permission (the same +credential used to update the ECS runner image variable). No version-update PR +is needed. Subsequent runs with `helpers_image: pinned` use that digest; runs +with an explicit digest keep their chosen version, and empty inputs still build +from source. To roll back, set the variable to a previously verified digest. +No mutable `latest` tag is consumed. Local extraction with `pinned` reads the +same name from the environment. The existing **Release builder images** workflow can also invoke publication via `release_query_regression_helpers_image`, including for initial branch testing. diff --git a/tests/perf/test_query_regression_helpers.py b/tests/perf/test_query_regression_helpers.py index 06a6acb2750..329f34e0759 100644 --- a/tests/perf/test_query_regression_helpers.py +++ b/tests/perf/test_query_regression_helpers.py @@ -18,6 +18,7 @@ import hashlib import importlib.util import json +import os import subprocess import tempfile import unittest @@ -33,17 +34,17 @@ REVISION = "b" * 40 class HelpersTest(unittest.TestCase): - def test_pin_and_digest_validation(self): - with tempfile.TemporaryDirectory() as tmp: - pin = Path(tmp) / "pin" - pin.write_text(IMAGE + "\n") - self.assertEqual(helpers.resolve_image("pinned", pin), IMAGE) - for value in ("", "registry/helpers:latest", IMAGE + "\nmalicious", "--help"): - with self.subTest(value=value), self.assertRaises(ValueError): - helpers.resolve_image(value) - pin.write_text("") - with self.assertRaises(ValueError): - helpers.resolve_image("pinned", pin) + def test_repository_variable_and_explicit_digest(self): + with patch.dict(os.environ, {"QUERY_REGRESSION_HELPERS_IMAGE": IMAGE}): + self.assertEqual(helpers.resolve_image("pinned"), IMAGE) + explicit = IMAGE.replace("a" * 64, "b" * 64) + self.assertEqual(helpers.resolve_image(explicit), explicit) + for value in ("", "registry/helpers:latest", IMAGE + "\nmalicious", "--help"): + with self.subTest(value=value), self.assertRaises(ValueError): + helpers.resolve_image(value) + for variables in ({}, {"QUERY_REGRESSION_HELPERS_IMAGE": "registry/helpers:latest"}): + with patch.dict(os.environ, variables, clear=True), self.assertRaises(ValueError): + helpers.resolve_image("pinned") def test_extraction_provenance_and_cleanup_on_failure(self): for fail in (False, True):