Skip to content

Commit

Permalink
Merge pull request #2 from blooper05/set-rails_best_practices-version
Browse files Browse the repository at this point in the history
✨ feat: Add ability to set `rails_best_practices` version
  • Loading branch information
blooper05 committed Jun 3, 2022
2 parents 6f9b099 + c252b19 commit 8adcbbc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
8 changes: 5 additions & 3 deletions README.md
Expand Up @@ -23,13 +23,13 @@ inputs:
github_token:
description: 'GITHUB_TOKEN'
default: '${{ github.token }}'
tool_name:
description: 'Tool name to use for reviewdog reporter'
default: 'rails_best_practices'
workdir:
description: 'Working directory relative to the root directory.'
default: '.'
### Flags for reviewdog ###
tool_name:
description: 'Tool name to use for reviewdog reporter'
default: 'rails_best_practices'
level:
description: 'Report level for reviewdog [info,warning,error]'
default: 'error'
Expand All @@ -50,6 +50,8 @@ inputs:
description: 'Additional reviewdog flags'
default: ''
### Flags for rails_best_practices ###
rails_best_practices_version:
description: 'rails_best_practices version'
rails_best_practices_flags:
description: 'rails_best_practices flags (rails_best_practices --without-color --silent . <rails_best_practices_flags>)'
default: ''
Expand Down
11 changes: 7 additions & 4 deletions action.yml
Expand Up @@ -5,13 +5,13 @@ inputs:
github_token:
description: 'GITHUB_TOKEN'
default: '${{ github.token }}'
tool_name:
description: 'Tool name to use for reviewdog reporter'
default: 'rails_best_practices'
workdir:
description: 'Working directory relative to the root directory.'
default: '.'
### Flags for reviewdog ###
tool_name:
description: 'Tool name to use for reviewdog reporter'
default: 'rails_best_practices'
level:
description: 'Report level for reviewdog [info,warning,error]'
default: 'error'
Expand All @@ -32,6 +32,8 @@ inputs:
description: 'Additional reviewdog flags'
default: ''
### Flags for rails_best_practices ###
rails_best_practices_version:
description: 'rails_best_practices version'
rails_best_practices_flags:
description: 'rails_best_practices flags (rails_best_practices --without-color --silent . <rails_best_practices_flags>)'
default: ''
Expand All @@ -50,13 +52,14 @@ runs:
# INPUT_<VARIABLE_NAME> is not available in Composite run steps
# https://github.community/t/input-variable-name-is-not-available-in-composite-run-steps/127611
INPUT_GITHUB_TOKEN: ${{ inputs.github_token }}
INPUT_TOOL_NAME: ${{ inputs.tool_name }}
INPUT_WORKDIR: ${{ inputs.workdir }}
INPUT_TOOL_NAME: ${{ inputs.tool_name }}
INPUT_LEVEL: ${{ inputs.level }}
INPUT_REPORTER: ${{ inputs.reporter }}
INPUT_FILTER_MODE: ${{ inputs.filter_mode }}
INPUT_FAIL_ON_ERROR: ${{ inputs.fail_on_error }}
INPUT_REVIEWDOG_FLAGS: ${{ inputs.reviewdog_flags }}
INPUT_RAILS_BEST_PRACTICES_VERSION: ${{ inputs.rails_best_practices_version }}
INPUT_RAILS_BEST_PRACTICES_FLAGS: ${{ inputs.rails_best_practices_flags }}

# Ref: https://haya14busa.github.io/github-action-brandings/
Expand Down
24 changes: 23 additions & 1 deletion script.sh
Expand Up @@ -8,7 +8,29 @@ fi
export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"

echo '::group::🐶 Installing rails_best_practices ... https://github.com/flyerhzm/rails_best_practices'
gem install --no-document rails_best_practices
# if 'gemfile' rails_best_practices version selected
if [ "${INPUT_RAILS_BEST_PRACTICES_VERSION}" = "gemfile" ]; then
# if Gemfile.lock is here
if [ -f 'Gemfile.lock' ]; then
# grep for rails_best_practices version
RAILS_BEST_PRACTICES_GEMFILE_VERSION=$(ruby -ne 'print $& if /^\s{4}rails_best_practices\s\(\K.*(?=\))/' Gemfile.lock)

# if rails_best_practices version found, then pass it to the gem install
# left it empty otherwise, so no version will be passed
if [ -n "$RAILS_BEST_PRACTICES_GEMFILE_VERSION" ]; then
RAILS_BEST_PRACTICES_VERSION=$RAILS_BEST_PRACTICES_GEMFILE_VERSION
else
printf "Cannot get the rails_best_practices's version from Gemfile.lock. The latest version will be installed."
fi
else
printf 'Gemfile.lock not found. The latest version will be installed.'
fi
else
# set desired rails_best_practices version
RAILS_BEST_PRACTICES_VERSION=$INPUT_RAILS_BEST_PRACTICES_VERSION
fi

gem install --no-document rails_best_practices --version "${RAILS_BEST_PRACTICES_VERSION}"
echo '::endgroup::'

echo '::group:: Running rails_best_practices with reviewdog 🐶 ...'
Expand Down

0 comments on commit 8adcbbc

Please sign in to comment.