Publish only a whitelist of files in the gem - #226
Merged
Merged
Conversation
`git ls-files` with no filter shipped the whole test suite: 29 of the gem's 61 packaged files lived under spec/, including 20 CSV/TSV fixtures and the 25 KB spec/import_spec.rb. Consumers download all of it and use none of it. Also switches to -z/\x0 splitting. `$OUTPUT_RECORD_SEPARATOR` only worked by accident — `English` is never required, so the global is nil and `split(nil)` falls back to whitespace splitting, which breaks on any tracked path containing a space. Packaged files: 61 -> 31.
The reject list only removes directories someone remembered to name. That is how spec/, .github/, screen/ and img/ got published in the first place — each needed a new pattern, and none was added until an audit went looking. A whitelist inverts the default: a new directory in the repo does not reach consumers until it is listed. Same shape the sibling gems activeadmin-oidc and credit_card_validations already use. Drops the remaining dev-only files the reject form kept: .gitignore .rubocop.yml active_admin_import.gemspec Gemfile Rakefile tasks/test.rake Packaged: 31 -> 25 files. The runtime payload — everything under lib/, app/, vendor/, config/ and exe/ — is byte-identical to before, verified by diffing the built .gem both ways.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The new glob can unintentionally package untracked or generated local files.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Limits packaged gem contents to runtime files, excluding specs and CI configuration.
Changes:
- Whitelists runtime directories, README, and license.
- Removes tests and repository metadata from gem packaging.
| File | Description |
|---|---|
active_admin_import.gemspec |
Defines the package file whitelist. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
`Dir[...]` globs the working tree, so any untracked or generated file under lib/, app/ or vendor/ would be published in a release — the build artifact depended on the releaser's local checkout. The reject form it replaced was tracked-only; this restores that property while keeping the whitelist. `git ls-files -- <paths>` also returns files only, where `Dir["**/*"]` returns directory entries too, so `files` no longer carries entries RubyGems just ignores. Built .gem is byte-for-byte the same file list as the Dir[] version.
`executables` greps `files` for `^bin/`, but `bin` was not in the whitelist, so that grep could never match. Adding a `bin/foo` later would have published a gem with no executables and no build error to say so — exactly the failure the whitelist exists to prevent, inverted. No repo file changes today: none of these gems tracks a bin/, and the built .gem is identical.
A whitelist fails quietly: `git ls-files -- config` against a tree with no config/ exits 0 and prints nothing, so the day someone adds `config/initializers/foo.rb` the gem installs, boots, and the initializer never runs. Nothing in `gem build` warns. That is not hypothetical for this family of gems — active_admin_datetimepicker's Ransack predicates live in exactly such an initializer, and its filters return no results without them. So list every root Rails::Engine loads from (lib app vendor config exe bin) in all of them, present or not, instead of only the ones that happen to exist today. No package changes: the built .gem is identical in every gem.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What
filesis now an explicit whitelist, instead of publishing everything tracked minus whatever someone remembered to exclude.A reject list only removes what someone named. That is how the test suite, CI config ended up in the published gem — each needed its own pattern, and none was added until an audit went looking. A whitelist inverts the default: a new directory does not reach consumers until it is listed.
Every root
Rails::Engineloads from is listed, present in this repo or not. A whitelist fails quietly —git ls-files -- configagainst a tree with noconfig/exits 0 and prints nothing — so the day someone addsconfig/initializers/foo.rbthe gem would install, boot, and never run it. Naming the roots up front costs nothing (git ls-fileson a missing path is a no-op) and removes that trapdoor.Selected through
git ls-filesrather thanDir[...]so the artifact stays tracked-only — an untracked or generated file underlib/cannot leak into a release — and sofilescarries no directory entries.Verified
All 40 files that leave the package:
Nothing is added. The 23 files under
app/,config/,lib/— the entire runtime payload — are unchanged: