-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add only_changed input to run rubocop only against changed files (#103)
* add only_changed input to run rubocop only against changed files Switch to bash for process substitution and working with arrays. Ignore if there are more than 100. Protecting from possibly hitting the command line length limit, it can be much higher and can be calculated or also extracted as one more input if needed. The effect from limiting number of files processed by rubocop is also smaller. Fix ci workflow to fetch all commits for pr branch plus head commit of base branch to be able to find changed files. Co-authored-by: Oliver Günther <[email protected]> * automatically fetch the tip of the base branch if it is not available * don't hide the name of the CI job * test only_changed --------- Co-authored-by: Oliver Günther <[email protected]>
- Loading branch information
1 parent
4e3af4b
commit e44fb2c
Showing
13 changed files
with
187 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ name: CI | |
on: [pull_request] | ||
jobs: | ||
test-skip-install-and-use-bundler: | ||
name: runner / rubocop | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
|
@@ -22,3 +21,55 @@ jobs: | |
skip_install: 'true' | ||
use_bundler: 'true' | ||
- run: test "$(bundle exec rubocop --version)" == "1.18.1" | ||
test-only_changed: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
shell: bash | ||
env: | ||
INPUT_ONLY_CHANGED: 'true' | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: setup | ||
run: | | ||
git config user.email "[email protected]" | ||
git config user.name "I am an automated workflow" | ||
- name: Check when there are relevant files | ||
run: | | ||
git checkout ${{ github.sha }} | ||
rm -f test/only_changed/reviewdog-was-called | ||
cp test/only_changed/few_relevant/files/* . | ||
git add * | ||
git commit -m auto | ||
export PATH=test/only_changed/few_relevant/mock_bins:test/only_changed/shared_mock_bins:$PATH | ||
BASE_REF=$(git rev-parse HEAD~) HEAD_REF=$(git rev-parse HEAD) ./script.sh | ||
[ -f test/only_changed/reviewdog-was-called ] | ||
- name: Check when there are no relevant files | ||
run: | | ||
git checkout ${{ github.sha }} | ||
rm -f test/only_changed/reviewdog-was-called | ||
cp test/only_changed/nothing_relevant/files/* . | ||
git add * | ||
git commit -m auto | ||
export PATH=test/only_changed/nothing_relevant/mock_bins:test/only_changed/shared_mock_bins:$PATH | ||
BASE_REF=$(git rev-parse HEAD~) HEAD_REF=$(git rev-parse HEAD) ./script.sh | ||
[ ! -f test/only_changed/reviewdog-was-called ] | ||
- name: Check when there are too many relevant files | ||
run: | | ||
git checkout ${{ github.sha }} | ||
rm -f test/only_changed/reviewdog-was-called | ||
touch a{00..100}.rb | ||
git add * | ||
git commit -m auto | ||
export PATH=test/only_changed/too_many_relevant/mock_bins:test/only_changed/shared_mock_bins:$PATH | ||
BASE_REF=$(git rev-parse HEAD~) HEAD_REF=$(git rev-parse HEAD) ./script.sh | ||
[ -f test/only_changed/reviewdog-was-called ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
puts "Hello, " + "world!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
puts "Hello, " + "world!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
case ARGV | ||
when %w[ | ||
--list-target-files | ||
] | ||
puts Dir['**/*.rb'] | ||
when %W[ | ||
--require #{ENV['GITHUB_ACTION_PATH']}/rdjson_formatter/rdjson_formatter.rb | ||
--format RdjsonFormatter | ||
--fail-level error | ||
a.rb | ||
] | ||
puts 'Mock message for reviewdog' | ||
else | ||
abort "rubocop mock called with unexpected arguments:\n#{ARGV.join("\n")}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
puts "Hello, " + "world!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
case ARGV | ||
when %w[ | ||
--list-target-files | ||
] | ||
puts Dir['**/*.rb'] | ||
else | ||
abort "rubocop mock called with unexpected arguments:\n#{ARGV.join("\n")}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
if [ "$1" = "exec" ]; then | ||
shift | ||
eval "$@" | ||
else | ||
echo "Only 'exec' command is supported" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
arguments="$*" | ||
|
||
if [ "$arguments" != "-sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh" ]; then | ||
echo "curl mock got unexpected arguments: $arguments" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
touch test/only_changed/reviewdog-was-called | ||
|
||
read -r input | ||
|
||
if [ "$input" != "Mock message for reviewdog" ]; then | ||
echo "reviewdog mock got unexpected input: $input" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
case ARGV | ||
when %w[ | ||
--list-target-files | ||
] | ||
puts Dir['**/*.rb'] | ||
when %W[ | ||
--require #{ENV['GITHUB_ACTION_PATH']}/rdjson_formatter/rdjson_formatter.rb | ||
--format RdjsonFormatter | ||
--fail-level error | ||
] | ||
puts 'Mock message for reviewdog' | ||
else | ||
abort "rubocop mock called with unexpected arguments:\n#{ARGV.join("\n")}" | ||
end |