-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add GitHub Actions annotations #34
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
class PuppetLint | ||
module Report | ||
# This formatter formats report data as GitHub Workflow commands resulting | ||
# in GitHub check annotations when run within GitHub Actions. | ||
class GitHubActionsReporter | ||
ESCAPE_MAP = { '%' => '%25', "\n" => '%0A', "\r" => '%0D' }.freeze | ||
|
||
def self.format_problem(file, problem) | ||
format( | ||
"\n::%<severity>s file=%<file>s,line=%<line>d,col=%<column>d::%<message>s (check: %<check>s)\n", | ||
:severity => problem[:kind], | ||
:file => file, | ||
:line => problem[:line], | ||
:column => problem[:column], | ||
:message => github_escape(problem[:message]), | ||
:check => problem[:check] | ||
) | ||
end | ||
|
||
def self.github_escape(string) | ||
string.gsub(Regexp.union(ESCAPE_MAP.keys), ESCAPE_MAP) | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,10 @@ | |
end | ||
|
||
it 'should be able to set sane defaults' do | ||
subject.defaults | ||
override_env do | ||
ENV.delete('GITHUB_ACTION') | ||
subject.defaults | ||
end | ||
|
||
expect(subject.settings).to eq( | ||
'with_filename' => false, | ||
|
@@ -58,9 +61,27 @@ | |
'log_format' => '', | ||
'with_context' => false, | ||
'fix' => false, | ||
'github_actions' => false, | ||
'show_ignored' => false, | ||
'json' => false, | ||
'ignore_paths' => ['vendor/**/*.pp'] | ||
) | ||
end | ||
|
||
it 'detects github actions' do | ||
override_env do | ||
ENV['GITHUB_ACTION'] = 'action' | ||
subject.defaults | ||
end | ||
|
||
expect(subject.settings['github_actions']).to be(true) | ||
end | ||
|
||
def override_env | ||
old_env = ENV.clone | ||
yield | ||
ensure | ||
ENV.clear | ||
ENV.update(old_env) | ||
end | ||
Comment on lines
+80
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't quite sure about this, but I wrote it on the train without internet access. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this comment resolvable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, it works. I just don't know if this is the desired solution in this repo. |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# Disable GitHub Actions reporting since it breaks the test suite | ||
ENV.delete('GITHUB_ACTION') | ||
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't the cleanest, but I couldn't find a good way to consistently set the setting. Right now I don't think it would break anything. |
||
|
||
if ENV['COVERAGE'] == 'yes' && RUBY_VERSION.start_with?('2.6.') | ||
require 'simplecov' | ||
SimpleCov.start do | ||
|
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.
Annotating my own code: technically this is redundant now that there's
ENV.delete()
inspec_helper.rb
, but it doesn't hurt to be explicit.