fix: keep G14 generated state on gitops branch

This commit is contained in:
Codex
2026-05-27 10:14:24 +08:00
parent 278bbe1c6a
commit 336a9b2c2c
10 changed files with 188 additions and 154 deletions
+16 -24
View File
@@ -239,20 +239,6 @@ async function resolveSourceRevision(value) {
return { full, short: full.slice(0, 7) };
}
async function defaultCheckSourceRevision(args) {
if (!args.check || args.sourceRevision) return args;
try {
const raw = await readFile(generatedPath(path.join(args.outDir, "source.json")), "utf8");
const parsed = JSON.parse(raw);
if (typeof parsed.sourceCommit === "string" && sourceCommitPattern.test(parsed.sourceCommit)) {
return { ...args, sourceRevision: parsed.sourceCommit };
}
} catch (error) {
if (error?.code !== "ENOENT") throw error;
}
return args;
}
function jsonManifest(value) {
return `${JSON.stringify(value, null, 2)}\n`;
}
@@ -729,6 +715,17 @@ function prepareSourceScript() {
"git config --global --add safe.directory /workspace/source/repo",
"git checkout \"$(params.revision)\"",
"test \"$(git rev-parse HEAD)\" = \"$(params.revision)\"",
"if git ls-remote --exit-code --heads origin \"$(params.gitops-branch)\" >/dev/null 2>&1; then",
" git fetch --depth 1 origin \"$(params.gitops-branch)\" >/dev/null 2>&1 || true",
" if git cat-file -e FETCH_HEAD:deploy/artifact-catalog.dev.json 2>/dev/null; then",
" git show FETCH_HEAD:deploy/artifact-catalog.dev.json > deploy/artifact-catalog.dev.json",
" echo '{\"event\":\"gitops-artifact-catalog\",\"phase\":\"prepare-source\",\"status\":\"loaded\",\"branch\":\"'\"$(params.gitops-branch)\"'\"}'",
" else",
" echo '{\"event\":\"gitops-artifact-catalog\",\"phase\":\"prepare-source\",\"status\":\"seed\",\"reason\":\"missing-on-gitops-branch\"}'",
" fi",
"else",
" echo '{\"event\":\"gitops-artifact-catalog\",\"phase\":\"prepare-source\",\"status\":\"seed\",\"reason\":\"gitops-branch-missing\"}'",
"fi",
"npm ci --ignore-scripts",
`echo ${shellSingleQuote(`G14 prepare-source complete; validation task count=${primitiveValidationTasks.length}`)}`
];
@@ -918,17 +915,10 @@ git config --global user.name "HWLAB G14 GitOps Bot"
git config --global user.email "hwlab-g14-gitops-bot@users.noreply.github.com"
if [ -s /workspace/source/dev-artifacts.json ]; then
node scripts/refresh-artifact-catalog.mjs --target-ref "$(params.revision)" --publish-report /workspace/source/dev-artifacts.json
if ! git diff --quiet -- deploy/artifact-catalog.dev.json; then
short="$(printf '%.7s' "$(params.revision)")"
git add deploy/artifact-catalog.dev.json
git commit -m "chore: promote G14 GitOps source $short"
git push origin "HEAD:$(params.source-branch)"
fi
fi
source_state_revision="$(git rev-parse HEAD)"
node scripts/g14-gitops-render.mjs --source-revision "$(params.revision)" --source-repo "$(params.git-url)" --source-branch "$(params.source-branch)" --gitops-branch "$(params.gitops-branch)" --registry-prefix "$(params.registry-prefix)" --use-deploy-images
node scripts/g14-gitops-render.mjs --source-revision "$(params.revision)" --source-repo "$(params.git-url)" --source-branch "$(params.source-branch)" --gitops-branch "$(params.gitops-branch)" --registry-prefix "$(params.registry-prefix)" --use-deploy-images --check
check_source_head before-push "$source_state_revision"
check_source_head before-push
workdir="$(mktemp -d)"
git clone --no-checkout "$(params.git-url)" "$workdir/gitops"
cd "$workdir/gitops"
@@ -942,7 +932,8 @@ else
fi
mkdir -p deploy/gitops
cp -a /workspace/source/repo/deploy/gitops/g14 deploy/gitops/g14
git add deploy/gitops/g14
cp /workspace/source/repo/deploy/artifact-catalog.dev.json deploy/artifact-catalog.dev.json
git add deploy/artifact-catalog.dev.json deploy/gitops/g14
if git diff --cached --quiet; then
echo '{"status":"unchanged","gitopsBranch":"'"$(params.gitops-branch)"'","sourceRevision":"'"$(params.revision)"'"}'
exit 0
@@ -1492,6 +1483,7 @@ function tektonPipeline() {
params: [
{ name: "git-url" },
{ name: "source-branch" },
{ name: "gitops-branch" },
{ name: "revision" }
],
workspaces: [{ name: "source" }, { name: "git-ssh" }],
@@ -1500,6 +1492,7 @@ function tektonPipeline() {
params: [
{ name: "git-url", value: "$(params.git-url)" },
{ name: "source-branch", value: "$(params.source-branch)" },
{ name: "gitops-branch", value: "$(params.gitops-branch)" },
{ name: "revision", value: "$(params.revision)" }
]
},
@@ -2373,7 +2366,6 @@ async function main() {
console.log(usage());
return;
}
args = await defaultCheckSourceRevision(args);
ensureObject(args, "args");
const { files, source } = await plannedFiles(args);
if (args.check) {