From 77b4e8afa2e104900a050a0a942efc363fbae362 Mon Sep 17 00:00:00 2001 From: Codex Date: Sat, 30 May 2026 09:22:37 +0800 Subject: [PATCH] fix: trim v02 cicd fast path checks --- scripts/g14-gitops-render.mjs | 35 ++++++++++++++++++++++--------- scripts/g14-gitops-render.test.ts | 12 ++++++++++- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/scripts/g14-gitops-render.mjs b/scripts/g14-gitops-render.mjs index 3c1b27d4..54767423 100644 --- a/scripts/g14-gitops-render.mjs +++ b/scripts/g14-gitops-render.mjs @@ -1115,13 +1115,18 @@ function prepareSourceScript() { "export HWLAB_TEKTON_TASKRUN=\"$(context.taskRun.name)\"", "export HWLAB_TEKTON_TASK=\"prepare-source\"", "export HWLAB_SOURCE_REVISION=\"$(params.revision)\"", - dependencyProxyProbeScript("prepare-source-proxy-preflight", "http://deb.debian.org/debian/dists/bookworm/InRelease"), `echo '{"event":"ci-base-image","phase":"prepare-source","image":"${ciToolsRunnerImage}","policy":"no-runtime-apk"}'`, - "for tool in node git ssh ssh-keyscan timeout; do command -v \"$tool\" >/dev/null 2>&1 || { echo '{\"event\":\"ci-base-image\",\"ok\":false,\"reason\":\"missing-tool\",\"tool\":\"'\"$tool\"'\"}'; exit 31; }; done", + "for tool in node git timeout; do command -v \"$tool\" >/dev/null 2>&1 || { echo '{\"event\":\"ci-base-image\",\"ok\":false,\"reason\":\"missing-tool\",\"tool\":\"'\"$tool\"'\"}'; exit 31; }; done", "node -e 'console.log(JSON.stringify({event:\"ci-base-image\",phase:\"prepare-source\",ok:true,node:process.version}))'", gitSshShellFunction(), - "git_ssh_setup", + "git_url_requires_ssh() { case \"$1\" in git@*|ssh://*) return 0 ;; *) return 1 ;; esac; }", "git_read_url=\"$(params.git-read-url)\"", + "if git_url_requires_ssh \"$git_read_url\"; then", + " for tool in ssh ssh-keyscan; do command -v \"$tool\" >/dev/null 2>&1 || { echo '{\"event\":\"ci-base-image\",\"ok\":false,\"reason\":\"missing-tool\",\"tool\":\"'\"$tool\"'\"}'; exit 31; }; done", + " git_ssh_setup", + "else", + " echo '{\"event\":\"git-ssh-setup\",\"phase\":\"prepare-source\",\"status\":\"skipped\",\"reason\":\"non-ssh-git-read-url\"}'", + "fi", "rm -rf /workspace/source/repo", "source_clone_started_ms=\"$(ci_now_ms)\"", "git_timed source-clone 180 git clone --branch \"$(params.source-branch)\" \"$git_read_url\" /workspace/source/repo", @@ -1228,7 +1233,6 @@ function primitiveValidationTask(task) { function planArtifactsScript() { return `#!/bin/sh set -eu -${dependencyProxyProbeScript("plan-artifacts-proxy-preflight", "http://deb.debian.org/debian/dists/bookworm/InRelease")} echo '{"event":"ci-base-image","phase":"plan-artifacts","image":"${ciToolsRunnerImage}","policy":"no-runtime-apk"}' for tool in node git; do command -v "$tool" >/dev/null 2>&1 || { echo '{"event":"ci-base-image","phase":"plan-artifacts","ok":false,"reason":"missing-tool","tool":"'"$tool"'"}'; exit 31; }; done cd /workspace/source/repo @@ -1378,7 +1382,6 @@ node scripts/g14-artifact-publish.mjs --publish --lane "$(params.lane)" --catalo function collectArtifactsScript() { return `#!/bin/sh set -eu -${dependencyProxyProbeScript("collect-artifacts-proxy-preflight", "http://deb.debian.org/debian/dists/bookworm/InRelease")} echo '{"event":"ci-base-image","phase":"collect-artifacts","image":"${ciToolsRunnerImage}","policy":"no-runtime-apk"}' for tool in node git; do command -v "$tool" >/dev/null 2>&1 || { echo '{"event":"ci-base-image","phase":"collect-artifacts","ok":false,"reason":"missing-tool","tool":"'"$tool"'"}'; exit 31; }; done cd /workspace/source/repo @@ -1405,11 +1408,24 @@ export HWLAB_TEKTON_PIPELINERUN="$(context.pipelineRun.name)" export HWLAB_TEKTON_TASKRUN="$(context.taskRun.name)" export HWLAB_TEKTON_TASK="gitops-promote" export HWLAB_SOURCE_REVISION="$(params.revision)" -${dependencyProxyProbeScript("gitops-promote-proxy-preflight", "http://deb.debian.org/debian/dists/bookworm/InRelease")} echo '{"event":"ci-base-image","phase":"gitops-promote","image":"${ciToolsRunnerImage}","policy":"no-runtime-apt"}' -for tool in node npm git ssh curl timeout; do command -v "$tool" >/dev/null 2>&1 || { echo '{"event":"ci-base-image","phase":"gitops-promote","ok":false,"reason":"missing-tool","tool":"'"$tool"'"}'; exit 31; }; done +for tool in node git timeout; do command -v "$tool" >/dev/null 2>&1 || { echo '{"event":"ci-base-image","phase":"gitops-promote","ok":false,"reason":"missing-tool","tool":"'"$tool"'"}'; exit 31; }; done ${gitSshShellFunction()} -git_ssh_setup +git_url_requires_ssh() { case "$1" in git@*|ssh://*) return 0 ;; *) return 1 ;; esac; } +lane="$(params.lane)" +source_head_url_for_setup="$(params.git-url)" +gitops_read_url_for_setup="$(params.git-url)" +if [ "$lane" = "v02" ]; then + source_head_url_for_setup="$(params.git-read-url)" + gitops_read_url_for_setup="$(params.git-read-url)" +fi +gitops_write_url_for_setup="$(params.git-write-url)" +if git_url_requires_ssh "$source_head_url_for_setup" || git_url_requires_ssh "$gitops_read_url_for_setup" || git_url_requires_ssh "$gitops_write_url_for_setup"; then + for tool in ssh ssh-keyscan; do command -v "$tool" >/dev/null 2>&1 || { echo '{"event":"ci-base-image","phase":"gitops-promote","ok":false,"reason":"missing-tool","tool":"'"$tool"'"}'; exit 31; }; done + git_ssh_setup +else + echo '{"event":"git-ssh-setup","phase":"gitops-promote","status":"skipped","reason":"non-ssh-git-url"}' +fi cd /workspace/source/repo test "$(git rev-parse HEAD)" = "$(params.revision)" @@ -1441,7 +1457,6 @@ git config --global user.name "HWLAB G14 GitOps Bot" git config --global user.email "hwlab-g14-gitops-bot@users.noreply.github.com" catalog_path="$(params.catalog-path)" runtime_path="$(params.runtime-path)" -lane="$(params.lane)" argo_hard_refresh_v02() { if [ "$lane" != "v02" ]; then return 0; fi @@ -2254,7 +2269,7 @@ const pipelineRun = process.env.HWLAB_TEKTON_PIPELINERUN || null; const taskRun = process.env.HWLAB_TEKTON_TASKRUN || null; const task = process.env.HWLAB_TEKTON_TASK || null; const timeoutMs = 240000; -const pollMs = 5000; +const pollMs = 1000; function emit(payload) { console.log(JSON.stringify({ diff --git a/scripts/g14-gitops-render.test.ts b/scripts/g14-gitops-render.test.ts index c0c65c16..f04332a3 100644 --- a/scripts/g14-gitops-render.test.ts +++ b/scripts/g14-gitops-render.test.ts @@ -50,6 +50,7 @@ test("v02 render follows TypeScript runtime checks and does not self-patch boots const runtimeReady = taskByName(pipelineJson, "runtime-ready"); const runtimeReadyScript = runtimeReady.taskSpec.steps[0].script; + assert.match(runtimeReadyScript, /const pollMs = 1000;/u); assert.match(runtimeReadyScript, /status: "timeout", reason: "source-commit-refresh-timeout"/u); assert.match(runtimeReadyScript, /const refresh = await waitForArgoRefresh\(\);\n if \(!refresh\.observed\) return;/u); @@ -61,24 +62,34 @@ test("v02 render follows TypeScript runtime checks and does not self-patch boots assert.match(gitopsPromoteScript, /BatchMode=yes/u); assert.match(gitopsPromoteScript, /ConnectTimeout=10/u); assert.match(gitopsPromoteScript, /git_timed "source-head-\$phase" 45 git ls-remote/u); + assert.match(gitopsPromoteScript, /"event":"git-ssh-setup","phase":"gitops-promote","status":"skipped"/u); assert.match(gitopsPromoteScript, /source_head_url="\$\(params\.git-read-url\)"/u); assert.match(gitopsPromoteScript, /gitops_write_url="\$\(params\.git-write-url\)"/u); assert.match(gitopsPromoteScript, /git clone --no-checkout "\$gitops_read_url"/u); assert.match(gitopsPromoteScript, /git_timed gitops-push 120 git push origin/u); + assert.doesNotMatch(gitopsPromoteScript, /gitops-promote-proxy-preflight/u); + assert.doesNotMatch(gitopsPromoteScript, /for tool in node npm git ssh curl timeout/u); const prepareSource = taskByName(pipelineJson, "prepare-source"); assert.ok(prepareSource.taskSpec.params.some((param) => param.name === "git-read-url")); assert.ok(prepareSource.params.some((param) => param.name === "git-read-url" && param.value === "$(params.git-read-url)")); const prepareSourceScript = prepareSource.taskSpec.steps[0].script; assert.match(prepareSourceScript, /git_read_url="\$\(params\.git-read-url\)"/u); + assert.match(prepareSourceScript, /"event":"git-ssh-setup","phase":"prepare-source","status":"skipped"/u); assert.match(prepareSourceScript, /git_timed source-clone 180 git clone --branch "\$\(params\.source-branch\)" "\$git_read_url"/u); assert.match(prepareSourceScript, /git_timed catalog-ls-remote 45 git ls-remote --exit-code --heads "\$git_read_url"/u); assert.match(prepareSourceScript, /git remote set-url gitops-catalog "\$git_read_url"/u); assert.match(prepareSourceScript, /prepare-source-dependencies/u); assert.doesNotMatch(prepareSourceScript, /npm ci --ignore-scripts/u); assert.doesNotMatch(prepareSourceScript, /prepare-source-pre-npm/u); + assert.doesNotMatch(prepareSourceScript, /prepare-source-proxy-preflight/u); assert.doesNotMatch(prepareSourceScript, /dependency-curl-probe-start/u); + const planArtifacts = taskByName(pipelineJson, "plan-artifacts"); + assert.doesNotMatch(planArtifacts.taskSpec.steps[0].script, /plan-artifacts-proxy-preflight/u); + const collectArtifacts = taskByName(pipelineJson, "collect-artifacts"); + assert.doesNotMatch(collectArtifacts.taskSpec.steps[0].script, /collect-artifacts-proxy-preflight/u); + const pipelineGitReadParam = pipelineJson.spec.params.find((param) => param.name === "git-read-url"); assert.equal(pipelineGitReadParam?.default, "http://git-mirror-http.devops-infra.svc.cluster.local/pikasTech/HWLAB.git"); const pipelineGitWriteParam = pipelineJson.spec.params.find((param) => param.name === "git-write-url"); @@ -160,7 +171,6 @@ test("v02 render follows TypeScript runtime checks and does not self-patch boots assert.deepEqual(task.when, [{ input: `$(tasks.plan-artifacts.results.affected-${serviceId})`, operator: "in", values: ["true"] }]); } - const collectArtifacts = taskByName(pipelineJson, "collect-artifacts"); const collectScript = collectArtifacts.taskSpec.steps[0].script; assert.match(collectScript, /--external-service-report-dir \/workspace\/source\/service-results/u); assert.doesNotMatch(JSON.stringify(collectArtifacts), /tasks\.build-hwlab-device-pod\.results/u);