diff --git a/README.md b/README.md index c071fca..e8ffade 100644 --- a/README.md +++ b/README.md @@ -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' @@ -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 . )' default: '' diff --git a/action.yml b/action.yml index c440939..c658e17 100644 --- a/action.yml +++ b/action.yml @@ -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' @@ -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 . )' default: '' @@ -50,13 +52,14 @@ runs: # INPUT_ 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/ diff --git a/script.sh b/script.sh index fa06b11..67982cc 100755 --- a/script.sh +++ b/script.sh @@ -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 🐶 ...'