Skip to content

Commit

Permalink
Fixup GitHub Actions formatter when run in non-default directory
Browse files Browse the repository at this point in the history
In some cases (specifically when running inside the container with
non-default `working-directory`) GitHub cannot link absolute paths
produced by formatter to the code, while relative paths works.

Output relative paths if they're inside current directory, so this
usecase is covered.
  • Loading branch information
ojab committed Jul 16, 2021
1 parent 3e1cc1a commit 903a4f9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_github_actions_in_non_default_directory.md
@@ -0,0 +1 @@
* [#9933](https://github.com/rubocop/rubocop/pull/9933): Fix GitHub Actions formatter when running in non-default directory. ([@ojab][])
2 changes: 1 addition & 1 deletion lib/rubocop/formatter/git_hub_actions_formatter.rb
Expand Up @@ -33,7 +33,7 @@ def report_offense(file, offense)
output.printf(
"\n::%<severity>s file=%<file>s,line=%<line>d,col=%<column>d::%<message>s\n",
severity: github_severity(offense),
file: file,
file: PathUtil.smart_path(file),
line: offense.line,
column: offense.real_column,
message: github_escape(offense.message)
Expand Down
9 changes: 9 additions & 0 deletions spec/rubocop/formatter/git_hub_actions_formatter_spec.rb
Expand Up @@ -30,6 +30,15 @@
end
end

context 'when file is relative to the current directory' do
let(:file) { "#{Dir.pwd}/path/to/file" }

it 'reports offenses as error with the relative path' do
expect(output.string)
.to include('::error file=path/to/file,line=1,col=1::This is a message.')
end
end

context 'when no offenses are detected' do
let(:offenses) { [] }

Expand Down

0 comments on commit 903a4f9

Please sign in to comment.