fix: restore Gitea git timing helper
This commit is contained in:
@@ -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)"
|
||||
|
||||
Reference in New Issue
Block a user