Skip to content

chore: harden repository and package distribution - #25

Merged
gachakra merged 3 commits into
developfrom
chore/harden-gitignore
Dec 4, 2026
Merged

gachakra merged 3 commits into
developfrom
chore/harden-gitignore

Conversation

@gachakra

@gachakra gachakra commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Simplify local Git ignore rules for credentials, environment files, private documentation, IDE and test artifacts, and PHP error logs.
  • Use a default-exclude root policy for Git Archive and Composer Archive, allowing src/, composer.json, LICENSE, README.md, and README-ClassBased.md only. Explicitly cover dot-prefixed root paths in Composer's filters and exclude known local artifacts within allowed directories.
  • Keep composer.lock tracked for development reproducibility while excluding it from distributions.
  • Provide a commit-based Composer archive helper that stages a Git export, validates both archive file lists and contents, and avoids packaging local working-tree files.
  • Retain independent raw Composer Archive checks and exercise synthetic hidden paths, forced-tracked artifacts, and ignored, untracked, and staged files under src/.

Creating a Composer archive

From a repository checkout, with Composer installed and an existing output directory outside the checkout:

bash .github/scripts/create-composer-archive.sh <commit-or-tag> <output-directory>

The helper packages the selected commit rather than the index or working tree. Raw composer archive is not a tracked-only operation.

Validation

  • The independent review of the preceding head confirmed the Git distribution and identified two Composer distribution issues.
  • Tested the helper's Bash syntax, committed-tree isolation, and overwrite protection in a temporary Git repository. The orchestration test used a mock Composer command; it is not an actual Composer Archive test.
  • Composer is unavailable in the implementation environment. The new CI run must verify real Composer archives, including the hidden-path and dirty-tree regression cases. Full PHP and Docker checks are also left to CI.

Scope

Only repository infrastructure and distribution checks are changed. Existing PHP and Docker check names, library code, public API, dependency versions, lockfile contents, documentation, and published releases/tags are unchanged.

@gachakra gachakra changed the title chore: harden and simplify gitignore rules chore: harden repository and package distribution Dec 4, 2026

@gachakra gachakra left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review

Please address the two inline findings before merging. The Git distribution has the expected contents. The Composer distribution includes repository infrastructure on a clean checkout and admits local files on a dirty checkout.

  • [P1] The Composer root exclusion misses dot-prefixed paths (composer.json:38). The clean archive contained 25 files, including .gitattributes, .gitignore, and .github/workflows/ci.yml. Synthetic, previously unknown root dotfiles and dot-directories were also included.
  • [P2] Composer collects untracked and ignored files inside src/ (.github/workflows/ci.yml:186). The current regression only adds fresh untracked files at the root, so it does not exercise this case.

Verification

  • Reviewed head 943fb2582313c98826c14b667dcf3755dd5fd570 against base 881c8383c09aa16c8736c43f5764b19bcf2347bc. The diff is limited to the four infrastructure files. Library source, documentation, Docker configuration, dependency constraints, and the composer.lock blob are unchanged. The lockfile remains tracked and unignored.
  • Generated the Git TAR and downloaded the GitHub source ZIP for the reviewed SHA. Both contained the same 22 allowed files with identical contents. The clean Composer 2.11.3 TAR excluded composer.lock and matched the contents of all 22 allowed files, with the three additional paths listed above.
  • Ran the exact synthetic step in an isolated directory. The forced-tracked Git fixtures were excluded, while the Composer comparison failed on the three infrastructure paths. The temporary fixture directory was removed by the exit trap. Separate synthetic probes confirmed that recognized nested exclusions, including .env, auth.json, IDE data, and *.log, exclude those paths from Composer archives.
  • composer validate --strict, git diff --check, and docker compose config --quiet passed independently. The existing check names are preserved. On the reviewed SHA, the two PHP jobs passed PHPUnit, examples, and Git Archive, then failed at Verify Composer archive after tests. The Docker check passed. These job results were read from GitHub.

Comment thread composer.json
"/vendor",
"/.phpunit.result.cache",
"/.phpunit.cache"
"/*",

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Exclude dot-prefixed paths in the Composer allowlist

Composer 2.11.3 translates the * in /* to a glob that skips leading dots. A clean composer archive includes .gitattributes, .gitignore, and .github/workflows/ci.yml even though the Git archive excludes them. A synthetic .local-metadata file and .review-config/notes.txt also entered the archive. Cover hidden root files and directory trees with Composer-compatible exclusions and add previously unknown hidden paths to the regression fixture.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 49b3bad: Composer now explicitly excludes dot-prefixed root paths with /.*, and the independent raw Composer archive fixture includes previously unknown hidden root files and directories. Real Composer verification is required in the new CI run; I could not run Composer in the implementation environment.

Comment thread .github/workflows/ci.yml
diff -u "$RUNNER_TEMP/expected-files.txt" "$RUNNER_TEMP/fixture-git-files.txt"

# Composer Archive also sees untracked and ignored working-tree files.
printf '{}\n' > "$fixture/untracked-local.txt"

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Exercise untracked and ignored source files

The fixture adds its fresh untracked files at the root. Composer traverses the working tree below the allowed src/ directory as well. In an isolated checkout, src/local-tool.php entered the archive while untracked, and src/local-ignored.txt entered it even after git check-ignore confirmed the path was ignored. Add both cases to the distribution test and generate the supported Composer release artifact from a tracked-only staging tree, or reject a dirty source tree before it can be packaged.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 49b3bad: added a commit-based Composer archive helper that validates the Git export and resulting Composer archive against the tracked public file list, and compares their extracted contents before moving the final artifact to its destination. The regression now includes arbitrary ignored, untracked, and staged source files plus a modified tracked file. Raw Composer filtering is still tested separately. The local Git isolation and mock-Composer orchestration checks passed; actual Composer execution remains to be verified by CI and re-review.

@gachakra gachakra left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent follow-up review

Both findings from the previous review are resolved on 49b3bad6623abcbf4e2782b3bc182b1ced796941. I found no remaining actionable issues and recommend merging.

  • P1 — Composer root exclusions. Composer 2.11.3 excluded the previously reported infrastructure files as well as synthetic root dotfiles and a hidden directory. The Git TAR, GitHub source ZIP, and clean Composer TAR contained the same 22 files with identical contents. The lockfile remained tracked and unignored.
  • P2 — Dirty source trees. The commit-based helper produced the same 22 files with identical contents when the checkout contained untracked, ignored, and staged files under src/ and a staged edit to README.md. Direct composer archive still included those working-tree files, so the commit-based helper is the release entry point. The CI fixture now exercises that boundary.
  • Independently passed composer validate --strict, git diff --check, bash -n, and docker compose config --quiet. The helper cleaned its temporary directory and rejected an existing output file. The library source, dependency constraints, composer.lock, documentation, and Docker configuration are unchanged.
  • Verified that PHP 8.4, PHP 8.5, and Docker development environment succeeded on the reviewed SHA. Both PHP jobs also passed the synthetic exclusions and commit-based packaging checks.

@gachakra
gachakra merged commit 739c451 into develop Dec 4, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant