diff --git a/scripts/src/hwlab-node/status.ts b/scripts/src/hwlab-node/status.ts index ec7cb962..4806a7d3 100644 --- a/scripts/src/hwlab-node/status.ts +++ b/scripts/src/hwlab-node/status.ts @@ -66,6 +66,9 @@ export function nodeRuntimeGitMirrorStatus(scoped: ReturnType/tmp/hwlab-node-gitmirror-status.err || true)", + "if ! printf '%s' \"$summary_json\" | node -e 'let s=\"\"; process.stdin.on(\"data\", c => s += c); process.stdin.on(\"end\", () => { try { const o = JSON.parse(s || \"{}\"); process.exit(o && o.localSource ? 0 : 1); } catch { process.exit(1); } });'; then", + " summary_json=$(kubectl -n \"$namespace\" exec deploy/\"$read_deploy\" -- sh -lc \"source_repository=\\$1 source_branch=\\$2 gitops_branch=\\$3 node <<'NODE'", + "const { execFileSync } = require('node:child_process');", + "const { readFileSync, existsSync } = require('node:fs');", + "const repository = process.env.source_repository;", + "const sourceBranch = process.env.source_branch;", + "const gitopsBranch = process.env.gitops_branch;", + "const repoPath = '/cache/' + repository + '.git';", + "function readJson(path) { try { return existsSync(path) ? JSON.parse(readFileSync(path, 'utf8')) : null; } catch { return null; } }", + "function rev(ref) { try { return execFileSync('git', ['--git-dir=' + repoPath, 'rev-parse', '--verify', ref + '^{commit}'], { encoding: 'utf8' }).trim(); } catch { return null; } }", + "const localSource = rev('refs/heads/' + sourceBranch);", + "const githubSource = rev('refs/mirror-stage/heads/' + sourceBranch);", + "const localGitops = rev('refs/heads/' + gitopsBranch);", + "const githubGitops = rev('refs/mirror-stage/heads/' + gitopsBranch);", + "const pendingFlush = Boolean(localGitops && (!githubGitops || localGitops !== githubGitops));", + "console.log(JSON.stringify({", + " localSource, githubSource, localGitops, githubGitops,", + " refSources: {", + " localSource: 'refs/heads/' + sourceBranch,", + " githubSource: 'refs/mirror-stage/heads/' + sourceBranch,", + " localGitops: 'refs/heads/' + gitopsBranch,", + " githubGitops: 'refs/mirror-stage/heads/' + gitopsBranch,", + " githubFieldsAreMirrorStageCache: true", + " },", + " pendingFlush,", + " flushNeeded: pendingFlush,", + " githubInSync: Boolean(localSource && githubSource && localSource === githubSource && localGitops && githubGitops && localGitops === githubGitops),", + " statusSource: 'cache-ref-fallback',", + " lastSync: readJson('/cache/HWLAB.last-sync.json'),", + " lastFlush: readJson('/cache/HWLAB.last-flush.json')", + "}));", + "NODE", + "\" sh \"$source_repository\" \"$source_branch\" \"$gitops_branch\" 2>>/tmp/hwlab-node-gitmirror-status.err || true)", + "fi", "if [ -z \"$summary_json\" ]; then summary_json='{}'; fi", "read_deployment_ready=$(deploy_ready \"$namespace\" \"$read_deploy\")", "write_deployment_ready=$(deploy_ready \"$namespace\" \"$write_deploy\")",