Skip to content

Commit a872a79

Browse files
committed
fix(ci): bound clone cache mirror refresh refs
1 parent 87ede21 commit a872a79

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

packages/app/src/lib/core/templates-entrypoint/tasks.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ const renderCloneAuthRepoUrl = (): string =>
117117
AUTH_REPO_URL="$(printf "%s" "$REPO_URL" | sed "s#^https://#https://\${RESOLVED_GIT_AUTH_USER}:\${RESOLVED_GIT_AUTH_TOKEN}@#")"
118118
fi`
119119

120+
// CHANGE: restrict clone-cache mirror refresh to branch and tag refs
121+
// WHY: broad refs include hosted forge PR refs and make cache reuse proportional to every remote ref
122+
// QUOTE(ТЗ): "Для тестов можно реализовать CI/CD workflow для Linux, MAC, Windows"
123+
// REF: issue-278-ci-check-clone-cache
124+
// SOURCE: n/a
125+
// FORMAT THEOREM: forall r in refreshedRefs: r in refs/heads/* union refs/tags/*
126+
// PURITY: CORE
127+
// INVARIANT: clone-cache refresh never requests refs/pull/* or refs/merge-requests/*
128+
// COMPLEXITY: O(|heads| + |tags|)
129+
const cloneCacheRefreshRefspecs = "'+refs/heads/*:refs/heads/*' '+refs/tags/*:refs/tags/*'"
130+
120131
const renderCloneCacheInit = (config: TemplateConfig): string =>
121132
` CLONE_CACHE_ARGS=""
122133
CACHE_REPO_DIR=""
@@ -135,7 +146,7 @@ const renderCloneCacheInit = (config: TemplateConfig): string =>
135146
chown 1000:1000 "$CACHE_ROOT" || true
136147
if [[ -d "$CACHE_REPO_DIR" ]]; then
137148
if su - ${config.sshUser} -c "git --git-dir '$CACHE_REPO_DIR' rev-parse --is-bare-repository >/dev/null 2>&1"; then
138-
if ! su - ${config.sshUser} -c "GIT_TERMINAL_PROMPT=0 git --git-dir '$CACHE_REPO_DIR' fetch --progress --prune '$AUTH_REPO_URL' '+refs/*:refs/*'"; then
149+
if ! su - ${config.sshUser} -c "GIT_TERMINAL_PROMPT=0 git --git-dir '$CACHE_REPO_DIR' fetch --progress --prune '$AUTH_REPO_URL' ${cloneCacheRefreshRefspecs}"; then
139150
echo "[clone-cache] mirror refresh failed for $REPO_URL"
140151
fi
141152
CLONE_CACHE_ARGS="--reference-if-able '$CACHE_REPO_DIR' --dissociate"

packages/lib/src/core/templates-entrypoint/tasks.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ const renderCloneAuthRepoUrl = (): string =>
117117
AUTH_REPO_URL="$(printf "%s" "$REPO_URL" | sed "s#^https://#https://\${RESOLVED_GIT_AUTH_USER}:\${RESOLVED_GIT_AUTH_TOKEN}@#")"
118118
fi`
119119

120+
// CHANGE: restrict clone-cache mirror refresh to branch and tag refs
121+
// WHY: broad refs include hosted forge PR refs and make cache reuse proportional to every remote ref
122+
// QUOTE(ТЗ): "Для тестов можно реализовать CI/CD workflow для Linux, MAC, Windows"
123+
// REF: issue-278-ci-check-clone-cache
124+
// SOURCE: n/a
125+
// FORMAT THEOREM: forall r in refreshedRefs: r in refs/heads/* union refs/tags/*
126+
// PURITY: CORE
127+
// INVARIANT: clone-cache refresh never requests refs/pull/* or refs/merge-requests/*
128+
// COMPLEXITY: O(|heads| + |tags|)
129+
const cloneCacheRefreshRefspecs = "'+refs/heads/*:refs/heads/*' '+refs/tags/*:refs/tags/*'"
130+
120131
const renderCloneCacheInit = (config: TemplateConfig): string =>
121132
` CLONE_CACHE_ARGS=""
122133
CACHE_REPO_DIR=""
@@ -135,7 +146,7 @@ const renderCloneCacheInit = (config: TemplateConfig): string =>
135146
chown 1000:1000 "$CACHE_ROOT" || true
136147
if [[ -d "$CACHE_REPO_DIR" ]]; then
137148
if su - ${config.sshUser} -c "git --git-dir '$CACHE_REPO_DIR' rev-parse --is-bare-repository >/dev/null 2>&1"; then
138-
if ! su - ${config.sshUser} -c "GIT_TERMINAL_PROMPT=0 git --git-dir '$CACHE_REPO_DIR' fetch --progress --prune '$AUTH_REPO_URL' '+refs/*:refs/*'"; then
149+
if ! su - ${config.sshUser} -c "GIT_TERMINAL_PROMPT=0 git --git-dir '$CACHE_REPO_DIR' fetch --progress --prune '$AUTH_REPO_URL' ${cloneCacheRefreshRefspecs}"; then
139150
echo "[clone-cache] mirror refresh failed for $REPO_URL"
140151
fi
141152
CLONE_CACHE_ARGS="--reference-if-able '$CACHE_REPO_DIR' --dissociate"

packages/lib/tests/core/templates.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ describe("renderDockerfile", () => {
7474
})
7575
})
7676

77+
describe("renderEntrypoint clone cache", () => {
78+
it("refreshes mirrors without broad remote refs", () => {
79+
const entrypoint = renderEntrypoint(makeTemplateConfig())
80+
81+
expect(entrypoint).toContain("git --git-dir '$CACHE_REPO_DIR' fetch")
82+
expect(entrypoint).toContain("'+refs/heads/*:refs/heads/*'")
83+
expect(entrypoint).toContain("'+refs/tags/*:refs/tags/*'")
84+
expect(entrypoint).not.toContain("'+refs/*:refs/*'")
85+
})
86+
})
87+
7788
describe("renderEntrypointGitHooks", () => {
7889
it("installs pre-push protection checks and a global git post-push runtime", () => {
7990
const hooks = renderEntrypointGitHooks()

0 commit comments

Comments
 (0)