diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index faa10f5..61280dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,8 +11,6 @@ jobs: BUNDLE_GEMFILE: ${{ github.workspace }}/test/using_bundler/Gemfile steps: - uses: actions/checkout@v4 - - name: Fetch head commit of base branch - run: git fetch --depth 1 origin ${{ github.event.pull_request.base.sha }} - uses: ruby/setup-ruby@v1 with: ruby-version: 2.6 diff --git a/README.md b/README.md index 7817571..f1e9fa9 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,9 @@ It's same as `-level` flag of reviewdog. Optional. Run Rubocop only on changed (and added) files, for speedup [`true`, `false`]. Default: `false`. +Will fetch the tip of the base branch with depth 1 from remote origin if it is not available. +If you use different remote name or customise the checkout otherwise, make the tip of the base branch available before this action + ### `reporter` Optional. Reporter of reviewdog command [`github-pr-check`, `github-check`, `github-pr-review`]. diff --git a/action.yml b/action.yml index 3bd5ef3..5d973d7 100644 --- a/action.yml +++ b/action.yml @@ -20,7 +20,10 @@ inputs: description: 'Report level for reviewdog [info,warning,error]' default: 'error' only_changed: - description: "Run Rubocop only on changed (and added) files, for speedup [`true`, `false`]" + description: | + Run Rubocop only on changed (and added) files, for speedup [`true`, `false`]. + Will fetch the tip of the base branch with depth 1 from remote origin if it is not available. + If you use different remote name or customise the checkout otherwise, make the tip of the base branch available before this action. default: 'false' reporter: description: | diff --git a/script.sh b/script.sh index 4dfda14..b34f6b6 100755 --- a/script.sh +++ b/script.sh @@ -91,6 +91,11 @@ fi if [ "${INPUT_ONLY_CHANGED}" = "true" ]; then echo '::group:: Getting changed files list' + # check if commit is present in repository, otherwise fetch it + if ! git cat-file -e "${BASE_REF}"; then + git fetch --depth 1 origin "${BASE_REF}" + fi + # get intersection of changed files (excluding deleted) with target files for # rubocop as an array # shellcheck disable=SC2086