Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Dir.glob instead of git ls-files in gemspec #565

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rbclark
Copy link

@rbclark rbclark commented Oct 7, 2021

Summary

Using git ls-files causes strange errors with the inspec plugin system. This is due to the inspec plugin system reading the gemspec and attempting to execute the files command which throws an error with the installed version of the gem. This updated gemspec will execute successfully even if git isn't installed or a .git directory is not present.

Other Information

Without this change the following error happens if a user attempts to use an inspec plugin that requires 'roo':

sh-4.4# inspec plugin list
Invalid gemspec in [/root/.inspec/gems/2.7.0/gems/roo-2.8.3/roo.gemspec]: No such file or directory - git
[2021-10-07T14:28:56+00:00] ERROR: Could not load plugin inspec-reporter-json-hdf: unable to find /root/.inspec/gems/2.7.0/gems/roo-2.8.3/roo.gemspec for gem roo
[2021-10-07T14:28:57+00:00] ERROR: Errors were encountered while loading plugins...
[2021-10-07T14:28:57+00:00] ERROR: Plugin name: inspec-reporter-json-hdf
[2021-10-07T14:28:57+00:00] ERROR: Error: unable to find /root/.inspec/gems/2.7.0/gems/roo-2.8.3/roo.gemspec for gem roo
[2021-10-07T14:28:57+00:00] ERROR: Run again with --debug for a stacktrace.

This should also have the added bonus of slimming what is actually published with the gem, since it seems likely that the test and spec files are not required for end users of roo.

Using git ls-files causes strange errors with the inspec plugin system. This is due to the inspec plugin system reading the gemspec and attempting to execute the `files` command which throws an error with the installed version of the gem. This updated gemspec will execute successfully even if git isn't installed or a .git directory is not present.
@Unit193
Copy link

Unit193 commented Dec 18, 2021

Another way to do this would be

-  spec.files                  = `git ls-files -z`.split("\x0")
-  spec.files.reject! { |fn| fn.include?('test/files') }
+  spec.files                  = Dir['CHANGELOG.md', '{examples,lib}/**/*', 'LICENSE', README.md']

@@ -13,8 +13,8 @@ Gem::Specification.new do |spec|
spec.homepage = 'https://github.com/roo-rb/roo'
spec.license = 'MIT'

spec.files = `git ls-files -z`.split("\x0")
spec.files.reject! { |fn| fn.include?('test/files') }
spec.files = Dir.glob('lib/**/*').reject { |f| File.directory?(f) } + %w{CHANGELOG.md LICENSE README.md Gemfile roo.gemspec}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why exclude directory?
iI it is not necessary action, i would like to accept his suggestion

For reference, rails also uses this style

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.

3 participants