Skip to content

Commit

Permalink
test only_changed
Browse files Browse the repository at this point in the history
  • Loading branch information
toy committed Jul 12, 2024
1 parent e50a873 commit 4e840d4
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,43 @@ 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 "workflow@github.com"
git config user.name "I am an automated workflow"
- name: Check when there are relevant files
run: |
git checkout ${{ github.sha }}
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
- name: Check when there are no relevant files
run: |
git checkout ${{ github.sha }}
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
- name: Check when there are too many relevant files
run: |
git checkout ${{ github.sha }}
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
1 change: 1 addition & 0 deletions test/only_changed/few_relevant/files/a.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
puts "Hello, " + "world!"

Check warning on line 1 in test/only_changed/few_relevant/files/a.rb

View workflow job for this annotation

GitHub Actions / test-skip-install-and-use-bundler

[rubocop] reported by reviewdog 🐶 Missing frozen string literal comment. Raw Output: test/only_changed/few_relevant/files/a.rb:1:1: C: Style/FrozenStringLiteralComment: Missing frozen string literal comment.

Check warning on line 1 in test/only_changed/few_relevant/files/a.rb

View workflow job for this annotation

GitHub Actions / test-skip-install-and-use-bundler

[rubocop] reported by reviewdog 🐶 Prefer string interpolation to string concatenation. Raw Output: test/only_changed/few_relevant/files/a.rb:1:6: C: Style/StringConcatenation: Prefer string interpolation to string concatenation.

Check warning on line 1 in test/only_changed/few_relevant/files/a.rb

View workflow job for this annotation

GitHub Actions / test-skip-install-and-use-bundler

[rubocop] reported by reviewdog 🐶 Prefer single-quoted strings when you don't need string interpolation or special symbols. Raw Output: test/only_changed/few_relevant/files/a.rb:1:6: C: Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

Check warning on line 1 in test/only_changed/few_relevant/files/a.rb

View workflow job for this annotation

GitHub Actions / test-skip-install-and-use-bundler

[rubocop] reported by reviewdog 🐶 Prefer single-quoted strings when you don't need string interpolation or special symbols. Raw Output: test/only_changed/few_relevant/files/a.rb:1:18: C: Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
1 change: 1 addition & 0 deletions test/only_changed/few_relevant/files/a.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
puts "Hello, " + "world!"
8 changes: 8 additions & 0 deletions test/only_changed/few_relevant/mock_bins/reviewdog
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

read -r input

if ! [ "$input" == "Mock message for reviewdog" ]; then
echo "reviewdog mock got unexpected input: $input"
exit 1
fi
14 changes: 14 additions & 0 deletions test/only_changed/few_relevant/mock_bins/rubocop
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

case "$*" in
"--list-target-files")
find . -name "*.rb"
;;
"--require $GITHUB_ACTION_PATH/rdjson_formatter/rdjson_formatter.rb --format RdjsonFormatter --fail-level error a.rb")
echo 'Mock message for reviewdog'
;;
*)
echo "rubocop mock called with unexpected arguments: $*"
exit 1
;;
esac
1 change: 1 addition & 0 deletions test/only_changed/nothing_relevant/files/a.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
puts "Hello, " + "world!"
4 changes: 4 additions & 0 deletions test/only_changed/nothing_relevant/mock_bins/reviewdog
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

echo "reviewdog mock got called unexpectedly"
exit 1
11 changes: 11 additions & 0 deletions test/only_changed/nothing_relevant/mock_bins/rubocop
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

case "$*" in
"--list-target-files")
find . -name "*.rb"
;;
*)
echo "rubocop mock called with unexpected arguments: $*"
exit 1
;;
esac
9 changes: 9 additions & 0 deletions test/only_changed/shared_mock_bins/bundle
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
8 changes: 8 additions & 0 deletions test/only_changed/shared_mock_bins/curl
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
8 changes: 8 additions & 0 deletions test/only_changed/too_many_relevant/mock_bins/reviewdog
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

read -r input

if [ "$input" != "Mock message for reviewdog" ]; then
echo "reviewdog mock got unexpected input: $input"
exit 1
fi
14 changes: 14 additions & 0 deletions test/only_changed/too_many_relevant/mock_bins/rubocop
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

case "$*" in
"--list-target-files")
find . -name "*.rb"
;;
"--require $GITHUB_ACTION_PATH/rdjson_formatter/rdjson_formatter.rb --format RdjsonFormatter --fail-level error a.rb")
echo 'Mock message for reviewdog'
;;
*)
echo "rubocop mock called with unexpected arguments: $*"
exit 1
;;
esac

0 comments on commit 4e840d4

Please sign in to comment.