voxpupuli / metadata-json-lint

Tool to check the validity of Puppet metadata.json files
Apache License 2.0
29 stars 27 forks source link

Rake task does not respect options #61

Closed ghost closed 7 years ago

ghost commented 7 years ago

Not sure if this is a puppetlabs_spec_helper problem or an issue with this gem. I'm using the boilerplate Rakefile from puppet module generate in version 4.7.1 Ruby env, gem versions and Rakefile below:

Rakefile

require 'puppetlabs_spec_helper'
require 'puppet-lint/tasks/puppet-lint'
require 'metadata-json-lint/rake_task'
...<truncated PuppetLint stuff>

desc '(override) Run metadata-json-lint'
task :lint_metadata do
  MetadataJsonLint.parse('metadata.json') do |options|
      options.strict_dependencies = false
  end
end

When I run rake validate, rake metadata_lint or the overriden task above rake lint_metadata, it runs and complains about an open-ended version requirement....which is by design as I don't want to pin my module to a specific puppetlabs/stdlib version (just the one I wrote it for).

metadata.json

{
  "name": "company/modulename",
  "version": "0.1.0",
  "author": "Thomas Cooper",
  "summary": "company modulename",
  "license": "Apache-2.0",
  "source": "https://internalgithub.com/modulename",
  "project_page": "https://internalgithub.com/modulename",
  "issues_url": "https://internalgithub.com/modulename/issues",
  "dependencies": [
    {"name":"puppetlabs/stdlib", "version_requirement": ">= 4.12.0"},   
    {"name":"puppetlabs/ciscopuppet", "version_requirement": "1.6.0"}
  ],
  "data_provider": null
}

Any idea what I might be doing wrong here? It seems like spec_helper includes standard tasks that are overwritting my desired configured one :(

ghoneycutt commented 7 years ago

This does seem like a bug. Have you tried with a compatible version of ruby such as 2.3.1?

For stdlib it should have an upper bound on the range, this is not the same as pinning to one specific version.

suggest

{"name":"puppetlabs/stdlib", "version_requirement": ">= 4.12.0 < 6.0.0"}, 

since stdlib 5 will also support Puppet 3 and 4

https://github.com/puppetlabs/puppetlabs-stdlib#version-compatibility

ghost commented 7 years ago

I had just come across that in the official Puppet docs...D'oh! Makes sense though. I've added the upper bound and it's no longer complaining.

I'm going to try this with 2.3.1 just for my own sanity, see if the behavior is any different.

ghost commented 7 years ago

Same issue with Ruby 2.3.1:

root@testhost:[~/modulename] # rake lint_metadata
Warning: Dependency puppetlabs/stdlib has an open ended dependency version requirement >= 4.12.0
root@testhost:[~/modulename] # rbenv version
2.3.1 (set by /app/.rbenv/version)
root@testhost:[~/modulename] # ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
root@testhost:[~/modulename] # gem list metadata-json-lint

*** LOCAL GEMS ***

metadata-json-lint (1.1.0)

I fully expect this to be an environment issue and not necessarily something wrong with metadata-json-lint, puppetlabs_spec_helper or even bundle/rake :disappointed:

ghoneycutt commented 7 years ago

+1

I was able to reproduce. Also does not work from the command line.

$ metadata-json-lint --no-strict-dependencies
Warning: Dependency puppetlabs/stdlib has an open ended dependency version requirement >= 4.6.0
rnelson0 commented 7 years ago

The strict-dependencies option elevates the Warning to an Error. Setting it to false still displays the warning, though. For example, in tests/rake_multiple_json_options/Rakefile, options.strict_license = false is set, and that generates the output:

$ be rake metadata_lint_multi
Warning: License identifier invalid_license is not in the SPDX list: http://spdx.org/licenses/

Changing that to true elevates it to an error:

$ be rake metadata_lint_multi
Warning: License identifier invalid_license is not in the SPDX list: http://spdx.org/licenses/
Errors found in metadata_license.json
ghost commented 7 years ago

I think there are some issues with the default Rake tasks that comes with puppetlabs_spec_helper and via puppet module generate. For some reason, when metadata linter was "failing", all subsequent tasks were not executing. I thought it had something to do with metadata's complaint.

I did not see the Errors found message in my outputs so I guess this issue can be closed as expected behavior of metadata-json-lint gem. Thanks!