diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e0dde91 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,24 @@ +name: CI +on: [pull_request] +jobs: + test-skip-install-and-use-bundler: + name: runner / rubocop + runs-on: ubuntu-latest + defaults: + run: + working-directory: test/using_bundler + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/test/using_bundler/Gemfile + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + bundler-cache: true + - name: rubocop with skip install and using bundler + uses: ./ + with: + github_token: ${{ secrets.github_token }} + skip_install: 'true' + use_bundler: 'true' + - run: test "$(bundle exec rubocop --version)" == "1.18.1" diff --git a/action.yml b/action.yml index aa53b87..54f9a27 100644 --- a/action.yml +++ b/action.yml @@ -40,6 +40,12 @@ inputs: workdir: description: "The directory from which to look for and run Rubocop. Default '.'" default: '.' + skip_install: + description: "Do not install Rubocop or its extensions. Default: `false`" + default: 'false' + use_bundler: + description: "Run Rubocop with bundle exec. Default: `false`" + default: 'false' runs: using: 'composite' steps: @@ -60,6 +66,8 @@ runs: INPUT_FAIL_ON_ERROR: ${{ inputs.fail_on_error }} INPUT_REVIEWDOG_FLAGS: ${{ inputs.reviewdog_flags }} INPUT_WORKDIR: ${{ inputs.workdir }} + INPUT_SKIP_INSTALL: ${{ inputs.skip_install }} + INPUT_USE_BUNDLER: ${{ inputs.use_bundler }} branding: icon: 'check-circle' color: 'red' diff --git a/script.sh b/script.sh index 1493fc9..f906bf3 100755 --- a/script.sh +++ b/script.sh @@ -15,76 +15,84 @@ echo '::group::🐶 Installing reviewdog ... https://github.com/reviewdog/review curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b "${TEMP_PATH}" "${REVIEWDOG_VERSION}" 2>&1 echo '::endgroup::' -echo '::group:: Installing rubocop with extensions ... https://github.com/rubocop/rubocop' -# if 'gemfile' rubocop version selected -if [ "${INPUT_RUBOCOP_VERSION}" = "gemfile" ]; then - # if Gemfile.lock is here - if [ -f 'Gemfile.lock' ]; then - # grep for rubocop version - RUBOCOP_GEMFILE_VERSION=$(ruby -ne 'print $& if /^\s{4}rubocop\s\(\K.*(?=\))/' Gemfile.lock) +if [ "${INPUT_SKIP_INSTALL}" = "false" ]; then + echo '::group:: Installing rubocop with extensions ... https://github.com/rubocop/rubocop' + # if 'gemfile' rubocop version selected + if [ "${INPUT_RUBOCOP_VERSION}" = "gemfile" ]; then + # if Gemfile.lock is here + if [ -f 'Gemfile.lock' ]; then + # grep for rubocop version + RUBOCOP_GEMFILE_VERSION=$(ruby -ne 'print $& if /^\s{4}rubocop\s\(\K.*(?=\))/' Gemfile.lock) - # if rubocop version found, then pass it to the gem install - # left it empty otherwise, so no version will be passed - if [ -n "$RUBOCOP_GEMFILE_VERSION" ]; then - RUBOCOP_VERSION=$RUBOCOP_GEMFILE_VERSION + # if rubocop version found, then pass it to the gem install + # left it empty otherwise, so no version will be passed + if [ -n "$RUBOCOP_GEMFILE_VERSION" ]; then + RUBOCOP_VERSION=$RUBOCOP_GEMFILE_VERSION + else + printf "Cannot get the rubocop's version from Gemfile.lock. The latest version will be installed." + fi else - printf "Cannot get the rubocop's version from Gemfile.lock. The latest version will be installed." + printf 'Gemfile.lock not found. The latest version will be installed.' fi else - printf 'Gemfile.lock not found. The latest version will be installed.' + # set desired rubocop version + RUBOCOP_VERSION=$INPUT_RUBOCOP_VERSION fi - else - # set desired rubocop version - RUBOCOP_VERSION=$INPUT_RUBOCOP_VERSION -fi -gem install -N rubocop --version "${RUBOCOP_VERSION}" + gem install -N rubocop --version "${RUBOCOP_VERSION}" -# Traverse over list of rubocop extensions -for extension in $INPUT_RUBOCOP_EXTENSIONS; do - # grep for name and version - INPUT_RUBOCOP_EXTENSION_NAME=$(echo "$extension" |awk 'BEGIN { FS = ":" } ; { print $1 }') - INPUT_RUBOCOP_EXTENSION_VERSION=$(echo "$extension" |awk 'BEGIN { FS = ":" } ; { print $2 }') + # Traverse over list of rubocop extensions + for extension in $INPUT_RUBOCOP_EXTENSIONS; do + # grep for name and version + INPUT_RUBOCOP_EXTENSION_NAME=$(echo "$extension" |awk 'BEGIN { FS = ":" } ; { print $1 }') + INPUT_RUBOCOP_EXTENSION_VERSION=$(echo "$extension" |awk 'BEGIN { FS = ":" } ; { print $2 }') - # if version is 'gemfile' - if [ "${INPUT_RUBOCOP_EXTENSION_VERSION}" = "gemfile" ]; then - # if Gemfile.lock is here - if [ -f 'Gemfile.lock' ]; then - # grep for rubocop extension version - RUBOCOP_EXTENSION_GEMFILE_VERSION=$(ruby -ne "print $& if /^\s{4}$INPUT_RUBOCOP_EXTENSION_NAME\s\(\K.*(?=\))/" Gemfile.lock) + # if version is 'gemfile' + if [ "${INPUT_RUBOCOP_EXTENSION_VERSION}" = "gemfile" ]; then + # if Gemfile.lock is here + if [ -f 'Gemfile.lock' ]; then + # grep for rubocop extension version + RUBOCOP_EXTENSION_GEMFILE_VERSION=$(ruby -ne "print $& if /^\s{4}$INPUT_RUBOCOP_EXTENSION_NAME\s\(\K.*(?=\))/" Gemfile.lock) - # if rubocop extension version found, then pass it to the gem install - # left it empty otherwise, so no version will be passed - if [ -n "$RUBOCOP_EXTENSION_GEMFILE_VERSION" ]; then - RUBOCOP_EXTENSION_VERSION=$RUBOCOP_EXTENSION_GEMFILE_VERSION + # if rubocop extension version found, then pass it to the gem install + # left it empty otherwise, so no version will be passed + if [ -n "$RUBOCOP_EXTENSION_GEMFILE_VERSION" ]; then + RUBOCOP_EXTENSION_VERSION=$RUBOCOP_EXTENSION_GEMFILE_VERSION + else + printf "Cannot get the rubocop extension version from Gemfile.lock. The latest version will be installed." + fi else - printf "Cannot get the rubocop extension version from Gemfile.lock. The latest version will be installed." + printf 'Gemfile.lock not found. The latest version will be installed.' fi - else - printf 'Gemfile.lock not found. The latest version will be installed.' + else + # set desired rubocop extension version + RUBOCOP_EXTENSION_VERSION=$INPUT_RUBOCOP_EXTENSION_VERSION fi - else - # set desired rubocop extension version - RUBOCOP_EXTENSION_VERSION=$INPUT_RUBOCOP_EXTENSION_VERSION - fi - # Handle extensions with no version qualifier - if [ -z "${RUBOCOP_EXTENSION_VERSION}" ]; then - unset RUBOCOP_EXTENSION_VERSION_FLAG - else - RUBOCOP_EXTENSION_VERSION_FLAG="--version ${RUBOCOP_EXTENSION_VERSION}" - fi + # Handle extensions with no version qualifier + if [ -z "${RUBOCOP_EXTENSION_VERSION}" ]; then + unset RUBOCOP_EXTENSION_VERSION_FLAG + else + RUBOCOP_EXTENSION_VERSION_FLAG="--version ${RUBOCOP_EXTENSION_VERSION}" + fi - # shellcheck disable=SC2086 - gem install -N "${INPUT_RUBOCOP_EXTENSION_NAME}" ${RUBOCOP_EXTENSION_VERSION_FLAG} -done -echo '::endgroup::' + # shellcheck disable=SC2086 + gem install -N "${INPUT_RUBOCOP_EXTENSION_NAME}" ${RUBOCOP_EXTENSION_VERSION_FLAG} + done + echo '::endgroup::' +fi export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" +if [ "${INPUT_USE_BUNDLER}" = "false" ]; then + BUNDLE_EXEC="" +else + BUNDLE_EXEC="bundle exec " +fi + echo '::group:: Running rubocop with reviewdog 🐶 ...' # shellcheck disable=SC2086 -rubocop ${INPUT_RUBOCOP_FLAGS} \ +${BUNDLE_EXEC}rubocop ${INPUT_RUBOCOP_FLAGS} \ | reviewdog -f=rubocop \ -name="${INPUT_TOOL_NAME}" \ -reporter="${INPUT_REPORTER}" \ diff --git a/test/using_bundler/Gemfile b/test/using_bundler/Gemfile new file mode 100644 index 0000000..11d1436 --- /dev/null +++ b/test/using_bundler/Gemfile @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +source 'https://rubygems.org' + +gem 'rubocop' diff --git a/test/using_bundler/Gemfile.lock b/test/using_bundler/Gemfile.lock new file mode 100644 index 0000000..8b9e7fe --- /dev/null +++ b/test/using_bundler/Gemfile.lock @@ -0,0 +1,32 @@ +GEM + remote: https://rubygems.org/ + specs: + ast (2.4.2) + parallel (1.20.1) + parser (3.0.2.0) + ast (~> 2.4.1) + rainbow (3.0.0) + regexp_parser (2.1.1) + rexml (3.2.5) + rubocop (1.18.1) + parallel (~> 1.10) + parser (>= 3.0.0.0) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml + rubocop-ast (>= 1.7.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.9.0) + parser (>= 3.0.1.1) + ruby-progressbar (1.11.0) + unicode-display_width (2.0.0) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + rubocop + +BUNDLED WITH + 2.2.25