Skip to content

Filter gitignored files when building the publish archive#10066

Open
plemarquand wants to merge 1 commit into
swiftlang:mainfrom
plemarquand:respect-gitignored-when-packaging-files
Open

Filter gitignored files when building the publish archive#10066
plemarquand wants to merge 1 commit into
swiftlang:mainfrom
plemarquand:respect-gitignored-when-packaging-files

Conversation

@plemarquand
Copy link
Copy Markdown
Contributor

@plemarquand plemarquand commented May 15, 2026

Motivation:

When building a package archive to publish the archiver strips omits .build, .git, .gitignore and .swiftpm using a hardcoded list. Any files the user has explicitly .gitignored are still included in the package archive.

Modifications:

Rewrites PackageArchiver.archive so publishing no longer leaks sensitive files that happen to live in the package directory. For git-tracked packages the tarball is now built from git archive HEAD, so only tracked content ships and .gitattributes export-ignore is honored.

For non-git packages a recursive copy with a denylist (.env*, .netrc, id_rsa/id_ed25519/id_ecdsa keypairs, credentials*.json, secrets.json, *.pem, *.key, *.p12, *.pfx, etc.) replaces the previous four-entry top-level filter, and a warning log entry points the user at git or .gitattributes for deterministic filtering.

Result:

Archives created using swift package-registry publish and swift package archive-source now respect the user's ignored files.

Rewrites `PackageArchiver.archive` so publishing no longer leaks
sensitive files that happen to live in the package directory. For
git-tracked packages the archive is now built from `git archive HEAD`,
so only tracked content ships. Files referenced by  `.gitignore` and
`.gitattributes export-ignore` are excluded from the archive.

For non-git packages a recursive copy with a denylist (.env*, .netrc,
id_rsa/id_ed25519/id_ecdsa keypairs, credentials*.json, secrets.json,
*.pem, *.key, *.p12, *.pfx, etc.) replaces the previous four-entry
top-level filter, and a warning log entry points the towards using
git based .gitignore or .gitattributes for deterministic filtering.

This patch updates both the `swift package-registry publish` and
`swift package archive-source` commands.
@plemarquand
Copy link
Copy Markdown
Contributor Author

@swift-ci test

@plemarquand
Copy link
Copy Markdown
Contributor Author

@swift-ci test windows platform

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