diff --git a/scripts/src/hwlab-node/cleanup.test.ts b/scripts/src/hwlab-node/cleanup.test.ts new file mode 100644 index 00000000..17f2f4e5 --- /dev/null +++ b/scripts/src/hwlab-node/cleanup.test.ts @@ -0,0 +1,25 @@ +import assert from "node:assert/strict"; +import { test } from "bun:test"; + +import { runtimeLaneCicdRepoEnsureScript } from "./cleanup"; + +test("CI/CD repo cache is materialized for local shared render clones", () => { + const script = runtimeLaneCicdRepoEnsureScript({ + cicdRepo: "/tmp/hwlab-v03-cicd.git", + cicdRepoLock: "/tmp/hwlab-v03-cicd-repo.lock", + gitUrl: "https://github.com/pikasTech/HWLAB.git", + sourceBranch: "v0.3", + downloadProfile: { + git: { + retries: 2, + timeoutSeconds: 60, + }, + }, + } as never); + + assert.doesNotMatch(script, /--filter=blob:none/u); + assert.match(script, /reason=partial-clone-cache/u); + assert.match(script, /remote\.origin\.promisor/u); + assert.match(script, /remote\.origin\.partialclonefilter/u); + assert.match(script, /clone --bare --depth=1 --single-branch/u); +}); diff --git a/scripts/src/hwlab-node/cleanup.ts b/scripts/src/hwlab-node/cleanup.ts index b6981251..7e6c73f5 100644 --- a/scripts/src/hwlab-node/cleanup.ts +++ b/scripts/src/hwlab-node/cleanup.ts @@ -200,20 +200,32 @@ export function runtimeLaneCicdRepoEnsureScript(spec: HwlabRuntimeLaneSpec): str "}", "mkdir -p \"$(dirname \"$cicd_repo\")\"", "if [ -d \"$cicd_repo/objects\" ] && [ -f \"$cicd_repo/HEAD\" ]; then", + " cicd_promisor=$(git --git-dir=\"$cicd_repo\" config --bool remote.origin.promisor 2>/dev/null || true)", + " cicd_promisor_pack=$(find \"$cicd_repo/objects/pack\" -maxdepth 1 -name '*.promisor' -print -quit 2>/dev/null || true)", + " if [ \"$cicd_promisor\" = \"true\" ] || [ -n \"$cicd_promisor_pack\" ]; then", + " echo \"phase=git-ci-cache-rebuild reason=partial-clone-cache\" >&2", + " rm -rf \"$cicd_repo\"", + " fi", + "fi", + "if [ -d \"$cicd_repo/objects\" ] && [ -f \"$cicd_repo/HEAD\" ]; then", " :", "elif [ -e \"$cicd_repo\" ]; then", " echo \"CI/CD repo path exists but is not a bare git repo: $cicd_repo\" >&2", " exit 41", "else", - " retry_git clone-ci-cache clone --bare --filter=blob:none --single-branch --branch \"$cicd_branch\" \"$cicd_url\" \"$cicd_repo\"", + " retry_git clone-ci-cache clone --bare --depth=1 --single-branch --branch \"$cicd_branch\" \"$cicd_url\" \"$cicd_repo\"", "fi", "git --git-dir=\"$cicd_repo\" remote set-url origin \"$cicd_url\" 2>/dev/null || git --git-dir=\"$cicd_repo\" remote add origin \"$cicd_url\"", "git --git-dir=\"$cicd_repo\" config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'", - "if ! retry_git fetch-ci-cache --git-dir=\"$cicd_repo\" fetch --filter=blob:none --depth=1 origin \"+refs/heads/$cicd_branch:refs/remotes/origin/$cicd_branch\" --prune; then", + "git --git-dir=\"$cicd_repo\" config --unset-all remote.origin.promisor 2>/dev/null || true", + "git --git-dir=\"$cicd_repo\" config --unset-all remote.origin.partialclonefilter 2>/dev/null || true", + "if ! retry_git fetch-ci-cache --git-dir=\"$cicd_repo\" fetch --depth=1 origin \"+refs/heads/$cicd_branch:refs/remotes/origin/$cicd_branch\" --prune; then", " rm -rf \"$cicd_repo\"", - " retry_git clone-ci-cache-retry clone --bare --filter=blob:none --single-branch --branch \"$cicd_branch\" \"$cicd_url\" \"$cicd_repo\"", + " retry_git clone-ci-cache-retry clone --bare --depth=1 --single-branch --branch \"$cicd_branch\" \"$cicd_url\" \"$cicd_repo\"", " git --git-dir=\"$cicd_repo\" config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'", - " retry_git fetch-ci-cache-retry --git-dir=\"$cicd_repo\" fetch --filter=blob:none --depth=1 origin \"+refs/heads/$cicd_branch:refs/remotes/origin/$cicd_branch\" --prune", + " git --git-dir=\"$cicd_repo\" config --unset-all remote.origin.promisor 2>/dev/null || true", + " git --git-dir=\"$cicd_repo\" config --unset-all remote.origin.partialclonefilter 2>/dev/null || true", + " retry_git fetch-ci-cache-retry --git-dir=\"$cicd_repo\" fetch --depth=1 origin \"+refs/heads/$cicd_branch:refs/remotes/origin/$cicd_branch\" --prune", "fi", ].join("\n"); }