mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-12-04 00:15:29 +00:00
refactor(ci): update helper image through repository variable
Signed-off-by: WenyXu <wenymedia@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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" <<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 ECS build smoke-tested both packaged binaries and compared fixture plans. The publishing job extracted both binaries from the published digest and verified their SHA-256 checksums against those 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"
|
||||
[[ "$HELPERS_IMAGE" == "$repository@sha256:"* ]]
|
||||
[[ "${HELPERS_IMAGE#"$repository@"}" =~ ^sha256:[0-9a-f]{64}$ ]]
|
||||
# Like QUERY_REGRESSION_ECS_IMAGE_ID, this is CI configuration, not a source
|
||||
# change. Create on first publication, then update only after image verification.
|
||||
gh variable set QUERY_REGRESSION_HELPERS_IMAGE \
|
||||
--repo "$GITHUB_REPOSITORY" --body "$HELPERS_IMAGE"
|
||||
gh api "repos/$GITHUB_REPOSITORY/actions/variables/QUERY_REGRESSION_HELPERS_IMAGE" \
|
||||
| jq -e --arg expected "$HELPERS_IMAGE" '.value == $expected' >/dev/null
|
||||
printf 'QUERY_REGRESSION_HELPERS_IMAGE updated to `%s`\n' "$HELPERS_IMAGE"
|
||||
|
||||
@@ -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 }}
|
||||
|
||||
@@ -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 }}
|
||||
|
||||
@@ -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:
|
||||
|
||||
+10
-5
@@ -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.
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user