-
Notifications
You must be signed in to change notification settings - Fork 681
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
throw an error during inspec check if the version is not correct #1832
Conversation
lib/inspec/metadata.rb
Outdated
|
||
# if version is set, ensure it is correct | ||
if !params[:version].nil? && !valid_version?(params[:version]) | ||
errors.push("Version need to be in SemVer format in #{ref}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two quick/small changes and then I'm good. :)
if !params[:version].nil? && !valid_version?(params[:version]) | ||
errors.push("Version need to be in SemVer format in #{ref}") | ||
end | ||
|
||
%w{ title summary maintainer copyright }.each do |field| | ||
next unless params[field.to_sym].nil? | ||
warnings.push("Missing profile #{field} in #{ref}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the inspec check
output will provide the filename that generated the warning:
✖ /Users/aleff/profiles/test1/inspec.yml:0:0: Version need to be in SemVer format in inspec.yml
... I propose can just change this to "Version needs to be in SemVer format" to avoid the duplicate "inspec.yml" output
lib/inspec/metadata.rb
Outdated
def valid_version?(value) | ||
Semverse::Version.new(value) | ||
true | ||
rescue Semverse::InvalidVersionFormat => _ex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're not using the exception object, we can remove the => _ex
from here.
Signed-off-by: Christoph Hartmann <chris@lollyrock.com>
6b0e2b5
to
b0ab35d
Compare
This ensures that inspec check fails if a non-semver version is used in inspec.yml