Merge pull request #2749 from pikasTech/fix/2748-gitea-git-timed
Pipelines as Code CI / hwlab-nc01-v03-ci-poll-24f1b94ec8dbd99465807ae64049f29d0778f320 Failed

修复 Gitea 流水线 git_timed 缺失
This commit is contained in:
Lyon
2026-07-22 04:07:42 +08:00
committed by GitHub
10 changed files with 54 additions and 32 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ metadata:
pipelinesascode.tekton.dev/on-cel-expression: "event == 'push' && target_branch == 'v0.3' && node == 'NC01'"
pipelinesascode.tekton.dev/max-keep-runs: "8"
unidesk.ai/owning-config-ref: "config/hwlab-node-lanes.yaml#lanes.v03.targets.NC01"
unidesk.ai/effective-config-sha256: sha256:f42181ba9c079806968bb8374967a2bc710c7a87b56030d512cc00c004be126b
unidesk.ai/effective-config-sha256: sha256:885e9277542653c730816208d4a0607dae143ce9b07fb68a108e9539428162b6
unidesk.ai/source-artifact-renderer: hwlab-runtime-lane
unidesk.ai/source-artifact-mode: remote-pipeline-annotation
pipelinesascode.tekton.dev/pipeline: ci/pipelines/hwlab-nc01-v03-ci-image-publish.yaml
File diff suppressed because one or more lines are too long
+10
View File
@@ -47,6 +47,14 @@ function taskByName(pipeline, name) {
return task;
}
function assertShellFunctionDefinedBeforeCall(script, functionName) {
const definitionIndex = script.indexOf(`${functionName}() {`);
assert.notEqual(definitionIndex, -1, `missing ${functionName} definition`);
const invocationIndex = script.search(new RegExp(`(?:^|\\n)[^\\n]*\\b${functionName}[ \\t]+`, "u"));
assert.notEqual(invocationIndex, -1, `missing ${functionName} invocation`);
assert.ok(definitionIndex < invocationIndex, `${functionName} must be defined before its first invocation`);
}
test("NC01 PaC artifact keeps the runtime GitOps file contract", async () => {
const pipelinePath = "ci/pipelines/hwlab-nc01-v03-ci-image-publish.yaml";
const pacSource = await readFile(".tekton/hwlab-nc01-v03-pac.yaml", "utf8");
@@ -275,6 +283,7 @@ test("v02 render follows TypeScript runtime checks and does not self-patch boots
assert.match(gitopsPromoteScript, /GIT_ASKPASS_REQUIRE=force/u);
assert.match(gitopsPromoteScript, /test -s \/workspace\/gitea-auth\/token/u);
assert.match(gitopsPromoteScript, /git_timed "source-head-\$phase" 45 git ls-remote/u);
assertShellFunctionDefinedBeforeCall(gitopsPromoteScript, "git_timed");
assert.doesNotMatch(gitopsPromoteScript, /git-ssh-setup/u);
assert.match(gitopsPromoteScript, /source_head_url="\$\(params\.git-read-url\)"/u);
assert.match(gitopsPromoteScript, /gitops_write_url="\$\(params\.git-write-url\)"/u);
@@ -292,6 +301,7 @@ test("v02 render follows TypeScript runtime checks and does not self-patch boots
assert.match(prepareSourceScript, /git_read_url="\$\(params\.git-read-url\)"/u);
assert.doesNotMatch(prepareSourceScript, /git-ssh-setup/u);
assert.match(prepareSourceScript, /git_timed source-clone 180 git clone --branch "\$\(params\.source-branch\)" "\$git_read_url"/u);
assertShellFunctionDefinedBeforeCall(prepareSourceScript, "git_timed");
assert.match(prepareSourceScript, /git_timed catalog-ls-remote 45 git ls-remote --exit-code --heads "\$gitops_read_url"/u);
assert.match(prepareSourceScript, /git remote set-url gitops-catalog "\$gitops_read_url"/u);
assert.match(prepareSourceScript, /"event":"prepare-source-dependencies","status":"skipped","reason":"renderer-dependency-install-disabled","dependency":"yaml"/u);
@@ -60,9 +60,14 @@ function gitSshShellFunction() {
});
}
function gitTimingShellFunction() {
return readTemplate("git-timing-functions.sh");
}
function prepareSourceScript() {
return renderTemplate("prepare-source.sh", {
"# __HWLAB_CI_TIMING_SHELL__\n": ciTimingShellFunction(),
"# __HWLAB_GIT_TIMING_SHELL__\n": gitTimingShellFunction(),
"__HWLAB_CI_TOOLS_IMAGE__": ciToolsRunnerImage,
"__HWLAB_V02_RUNTIME_ENDPOINT__": JSON.stringify(defaultV02RuntimeEndpoint).slice(1, -1),
"__HWLAB_VALIDATION_TASK_COUNT__": primitiveValidationTasks.length
@@ -139,6 +144,7 @@ function collectArtifactsScript() {
function gitopsPromoteScript() {
return renderTemplate("gitops-promote.sh", {
"# __HWLAB_CI_TIMING_SHELL__\n": ciTimingShellFunction(),
"# __HWLAB_GIT_TIMING_SHELL__\n": gitTimingShellFunction(),
"__HWLAB_CI_TOOLS_IMAGE__": ciToolsRunnerImage
});
}
@@ -149,6 +155,7 @@ function controlPlaneReconcileScript() {
"control-plane-proxy-preflight",
"http://deb.debian.org/debian/dists/bookworm/InRelease"
),
"# __HWLAB_GIT_TIMING_SHELL__\n": gitTimingShellFunction(),
"# __HWLAB_GIT_SSH_SHELL__\n": gitSshShellFunction(),
"__HWLAB_CI_TOOLS_IMAGE__": ciToolsRunnerImage
});
@@ -160,6 +167,7 @@ function pollerScript() {
"poller-proxy-preflight",
"http://deb.debian.org/debian/dists/bookworm/InRelease"
),
"# __HWLAB_GIT_TIMING_SHELL__\n": gitTimingShellFunction(),
"# __HWLAB_GIT_SSH_SHELL__\n": gitSshShellFunction(),
"__HWLAB_CI_TOOLS_IMAGE__": ciToolsRunnerImage
});
@@ -173,6 +181,7 @@ export {
dependencyProxyProbeScript,
gitopsPromoteScript,
gitSshShellFunction,
gitTimingShellFunction,
perServicePublishScript,
planArtifactsScript,
pollerScript,
@@ -1,6 +1,7 @@
#!/bin/sh
set -eu
# __HWLAB_DEPENDENCY_PROXY_PROBE__
# __HWLAB_GIT_TIMING_SHELL__
echo '{"event":"ci-base-image","phase":"control-plane-reconciler","image":"__HWLAB_CI_TOOLS_IMAGE__","policy":"no-runtime-apk"}'
for tool in node npm git python3 ssh curl timeout; do command -v "$tool" >/dev/null 2>&1 || { echo '{"event":"ci-base-image","phase":"control-plane-reconciler","ok":false,"reason":"missing-tool","tool":"'"$tool"'"}'; exit 31; }; done
# __HWLAB_GIT_SSH_SHELL__
@@ -16,31 +16,3 @@ write_github_proxy_command() {
NODE_PROXY
chmod 0700 /tmp/hwlab-github-proxy-connect.mjs
}
git_now_ms() {
node -e 'console.log(Date.now())' 2>/dev/null || date +%s000
}
git_timed() {
phase="$1"
timeout_seconds="$2"
shift 2
started_ms="$(git_now_ms)"
echo '{"event":"git-operation","phase":"'"$phase"'","status":"started","timeoutSeconds":'"$timeout_seconds"'}' >&2
set +e
timeout "$timeout_seconds" "$@"
status="$?"
set -e
finished_ms="$(git_now_ms)"
duration_ms="$((finished_ms - started_ms))"
if [ "$status" -eq 0 ]; then
echo '{"event":"git-operation","phase":"'"$phase"'","status":"succeeded","durationMs":'"$duration_ms"'}' >&2
return 0
fi
if [ "$status" -eq 124 ] || [ "$status" -eq 137 ]; then
echo '{"event":"git-operation","phase":"'"$phase"'","status":"failed","reason":"timeout","durationMs":'"$duration_ms"',"timeoutSeconds":'"$timeout_seconds"'}' >&2
else
echo '{"event":"git-operation","phase":"'"$phase"'","status":"failed","exitCode":'"$status"',"durationMs":'"$duration_ms"'}' >&2
fi
return "$status"
}
@@ -0,0 +1,27 @@
git_now_ms() {
node -e 'console.log(Date.now())' 2>/dev/null || date +%s000
}
git_timed() {
phase="$1"
timeout_seconds="$2"
shift 2
started_ms="$(git_now_ms)"
echo '{"event":"git-operation","phase":"'"$phase"'","status":"started","timeoutSeconds":'"$timeout_seconds"'}' >&2
set +e
timeout "$timeout_seconds" "$@"
status="$?"
set -e
finished_ms="$(git_now_ms)"
duration_ms="$((finished_ms - started_ms))"
if [ "$status" -eq 0 ]; then
echo '{"event":"git-operation","phase":"'"$phase"'","status":"succeeded","durationMs":'"$duration_ms"'}' >&2
return 0
fi
if [ "$status" -eq 124 ] || [ "$status" -eq 137 ]; then
echo '{"event":"git-operation","phase":"'"$phase"'","status":"failed","reason":"timeout","durationMs":'"$duration_ms"',"timeoutSeconds":'"$timeout_seconds"'}' >&2
else
echo '{"event":"git-operation","phase":"'"$phase"'","status":"failed","exitCode":'"$status"',"durationMs":'"$duration_ms"'}' >&2
fi
return "$status"
}
@@ -1,6 +1,7 @@
#!/bin/sh
set -eu
# __HWLAB_CI_TIMING_SHELL__
# __HWLAB_GIT_TIMING_SHELL__
export HWLAB_TEKTON_PIPELINERUN="$(context.pipelineRun.name)"
export HWLAB_TEKTON_TASKRUN="$(context.taskRun.name)"
@@ -1,6 +1,7 @@
#!/bin/sh
set -eu
# __HWLAB_DEPENDENCY_PROXY_PROBE__
# __HWLAB_GIT_TIMING_SHELL__
echo '{"event":"ci-base-image","phase":"poller","image":"__HWLAB_CI_TOOLS_IMAGE__","policy":"no-runtime-apk"}'
for tool in node git ssh curl timeout; do command -v "$tool" >/dev/null 2>&1 || { echo '{"event":"ci-base-image","phase":"poller","ok":false,"reason":"missing-tool","tool":"'"$tool"'"}'; exit 31; }; done
# __HWLAB_GIT_SSH_SHELL__
@@ -1,6 +1,7 @@
#!/bin/sh
set -eu
# __HWLAB_CI_TIMING_SHELL__
# __HWLAB_GIT_TIMING_SHELL__
export HWLAB_TEKTON_PIPELINERUN="$(context.pipelineRun.name)"
export HWLAB_TEKTON_TASKRUN="$(context.taskRun.name)"