Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow use of bundler #47

Merged
merged 2 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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"
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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'
110 changes: 59 additions & 51 deletions script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}" \
Expand Down
5 changes: 5 additions & 0 deletions test/using_bundler/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'rubocop'
32 changes: 32 additions & 0 deletions test/using_bundler/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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