Skip to content

Commit 93924be

Browse files
LTSCommerceclaude
andcommitted
feat: Auto-manage QA runtime cache excludes in project root .gitignore
Defence-in-depth for the QA runtime cache tracking class of bug: misconfigured tools (e.g. PHPUnit with the default `cacheDirectory`) write cache dirs into folders that happen to be tracked, and those caches silently end up in git. prepareDirectories.inc.bash now appends a marked, idempotent block to the consuming project's root .gitignore with anywhere-in-tree patterns for every QA tool cache we know about: **/.phpunit.cache/ **/.qa-lock/ **/.php-cs-fixer.cache **/.php_cs.cache **/.rector.cache/ **/phpstan-result.json The block is guarded by BEGIN/END markers so re-runs are no-ops and manual edits to the rest of the file are preserved. The lib itself picks this up through its own self-QA runs, so the same patterns are already committed to this repo's top-level .gitignore. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d211348 commit 93924be

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,15 @@
1616
/.phive-home/
1717
/tools/rector/vendor/
1818
/tools/rector/composer.lock
19+
20+
# BEGIN php-qa-ci managed QA runtime excludes — do not edit
21+
# These patterns ensure QA tool runtime caches are never committed,
22+
# regardless of where they happen to appear in the project tree.
23+
# Managed by vendor/lts/php-qa-ci/includes/generic/prepareDirectories.inc.bash
24+
**/.phpunit.cache/
25+
**/.qa-lock/
26+
**/.php-cs-fixer.cache
27+
**/.php_cs.cache
28+
**/.rector.cache/
29+
**/phpstan-result.json
30+
# END php-qa-ci managed QA runtime excludes

includes/generic/prepareDirectories.inc.bash

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,45 @@ echo '
99
*
1010
!.gitignore
1111
' > "$cacheDir/.gitignore"
12+
13+
# Ensure the consuming project's root .gitignore excludes QA runtime caches
14+
# wherever they might appear in the tree. We manage a marked block so the
15+
# edit is idempotent — if the markers exist we leave the block alone, if not
16+
# we append it. This protects projects against misconfigured tools writing
17+
# cache dirs into tracked folders (e.g. PHPUnit's default .phpunit.cache
18+
# ending up next to phpunit.xml in qaConfig/).
19+
ensureProjectGitignoreGuards() {
20+
local rootGitignore="$projectRoot/.gitignore"
21+
local markerStart="# BEGIN php-qa-ci managed QA runtime excludes"
22+
23+
if [[ -f "$rootGitignore" ]] && grep -qF "$markerStart" "$rootGitignore"; then
24+
return 0
25+
fi
26+
27+
if [[ ! -f "$rootGitignore" ]]; then
28+
touch "$rootGitignore"
29+
fi
30+
31+
# Ensure there's a blank line before the managed block for readability,
32+
# but only if the file is non-empty and doesn't already end with one.
33+
if [[ -s "$rootGitignore" ]] && [[ -n "$(tail -c1 "$rootGitignore")" ]]; then
34+
printf '\n' >> "$rootGitignore"
35+
fi
36+
37+
cat >> "$rootGitignore" << 'GITIGNORE_EOF'
38+
39+
# BEGIN php-qa-ci managed QA runtime excludes — do not edit
40+
# These patterns ensure QA tool runtime caches are never committed,
41+
# regardless of where they happen to appear in the project tree.
42+
# Managed by vendor/lts/php-qa-ci/includes/generic/prepareDirectories.inc.bash
43+
**/.phpunit.cache/
44+
**/.qa-lock/
45+
**/.php-cs-fixer.cache
46+
**/.php_cs.cache
47+
**/.rector.cache/
48+
**/phpstan-result.json
49+
# END php-qa-ci managed QA runtime excludes
50+
GITIGNORE_EOF
51+
}
52+
53+
ensureProjectGitignoreGuards

0 commit comments

Comments
 (0)