diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 83a5fd2..3b62943 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/test/only_changed/few_relevant/files/a.rb b/test/only_changed/few_relevant/files/a.rb new file mode 100644 index 0000000..5460224 --- /dev/null +++ b/test/only_changed/few_relevant/files/a.rb @@ -0,0 +1 @@ +puts "Hello, " + "world!" diff --git a/test/only_changed/few_relevant/files/a.txt b/test/only_changed/few_relevant/files/a.txt new file mode 100644 index 0000000..5460224 --- /dev/null +++ b/test/only_changed/few_relevant/files/a.txt @@ -0,0 +1 @@ +puts "Hello, " + "world!" diff --git a/test/only_changed/few_relevant/mock_bins/reviewdog b/test/only_changed/few_relevant/mock_bins/reviewdog new file mode 100755 index 0000000..50bc77f --- /dev/null +++ b/test/only_changed/few_relevant/mock_bins/reviewdog @@ -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 diff --git a/test/only_changed/few_relevant/mock_bins/rubocop b/test/only_changed/few_relevant/mock_bins/rubocop new file mode 100755 index 0000000..dda163a --- /dev/null +++ b/test/only_changed/few_relevant/mock_bins/rubocop @@ -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 diff --git a/test/only_changed/nothing_relevant/files/a.txt b/test/only_changed/nothing_relevant/files/a.txt new file mode 100644 index 0000000..5460224 --- /dev/null +++ b/test/only_changed/nothing_relevant/files/a.txt @@ -0,0 +1 @@ +puts "Hello, " + "world!" diff --git a/test/only_changed/nothing_relevant/mock_bins/reviewdog b/test/only_changed/nothing_relevant/mock_bins/reviewdog new file mode 100755 index 0000000..7de4581 --- /dev/null +++ b/test/only_changed/nothing_relevant/mock_bins/reviewdog @@ -0,0 +1,4 @@ +#!/bin/bash + +echo "reviewdog mock got called unexpectedly" +exit 1 diff --git a/test/only_changed/nothing_relevant/mock_bins/rubocop b/test/only_changed/nothing_relevant/mock_bins/rubocop new file mode 100755 index 0000000..95363db --- /dev/null +++ b/test/only_changed/nothing_relevant/mock_bins/rubocop @@ -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 diff --git a/test/only_changed/shared_mock_bins/bundle b/test/only_changed/shared_mock_bins/bundle new file mode 100755 index 0000000..0a28632 --- /dev/null +++ b/test/only_changed/shared_mock_bins/bundle @@ -0,0 +1,9 @@ +#!/bin/bash + +if [ "$1" = "exec" ]; then + shift + eval "$@" +else + echo "Only 'exec' command is supported" + exit 1 +fi diff --git a/test/only_changed/shared_mock_bins/curl b/test/only_changed/shared_mock_bins/curl new file mode 100755 index 0000000..3c5bc23 --- /dev/null +++ b/test/only_changed/shared_mock_bins/curl @@ -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 diff --git a/test/only_changed/too_many_relevant/mock_bins/reviewdog b/test/only_changed/too_many_relevant/mock_bins/reviewdog new file mode 100755 index 0000000..830edbc --- /dev/null +++ b/test/only_changed/too_many_relevant/mock_bins/reviewdog @@ -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 diff --git a/test/only_changed/too_many_relevant/mock_bins/rubocop b/test/only_changed/too_many_relevant/mock_bins/rubocop new file mode 100755 index 0000000..dda163a --- /dev/null +++ b/test/only_changed/too_many_relevant/mock_bins/rubocop @@ -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