Skip to content

Allow to set the version of haml_lint #5

New issue

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

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

Already on GitHub? # to your account

Merged
merged 2 commits into from
Jun 22, 2023
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
61 changes: 30 additions & 31 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,57 @@
name: 'Run haml-lint via reviewdog'
description: '🐶 Run haml-lint with reviewdog on pull requests to improve code review experience.'
author: 'pcothenet'
name: "Run haml-lint via reviewdog"
description: "🐶 Run haml-lint with reviewdog on pull requests to improve code review experience."
author: "pcothenet"
inputs:
github_token:
description: 'GITHUB_TOKEN'
default: '${{ github.token }}'
description: "GITHUB_TOKEN"
default: "${{ github.token }}"
### Flags for haml-lint
haml_lint_flags:
description: 'Additional haml-lint flags'
default: ''
description: "Additional haml-lint flags"
default: ""
haml_lint_version:
description: "The version of haml_lint to use. Use 'gemfile' to use the version from Gemfile.lock"
tool_name:
description: 'Tool name to use for reviewdog reporter'
default: 'haml-lint'
### Flags for rubocop ###
description: "Tool name to use for reviewdog reporter"
default: "haml-lint"
### Flags for rubocop ###
rubocop_version:
description: 'Rubocop version'
description: "The version of rubocop to use. Use 'gemfile' to use the version from Gemfile.lock"
rubocop_extensions:
description: 'Rubocop extensions'
default: 'rubocop-rails rubocop-performance rubocop-rspec rubocop-i18n rubocop-rake'
description: "Rubocop extensions"
default: "rubocop-rails rubocop-performance rubocop-rspec rubocop-i18n rubocop-rake"
### Flags for reviewdog ###
level:
description: 'Report level for reviewdog [info,warning,error]'
default: 'error'
description: "Report level for reviewdog [info,warning,error]"
default: "error"
reporter:
description: 'Reporter of reviewdog command [github-pr-check,github-pr-review].'
default: 'github-pr-check'
description: "Reporter of reviewdog command [github-pr-check,github-pr-review]."
default: "github-pr-check"
filter_mode:
description: |
Filtering for the reviewdog command [added,diff_context,file,nofilter].
Default is added.
default: 'added'
default: "added"
fail_on_error:
description: |
Exit code for reviewdog when errors are found [true,false]
Default is `false`.
default: 'false'
default: "false"
reviewdog_flags:
description: 'Additional reviewdog flags'
default: ''
description: "Additional reviewdog flags"
default: ""
workdir:
description: "The directory from which to look for and run Rubocop. Default '.'"
default: '.'
default: "."
skip_install:
description: "Do not install Rubocop or its extensions. Default: `false`"
default: 'false'
default: "false"
use_bundler:
description: "Run Rubocop with bundle exec. Default: `false`"
default: 'false'
default: "false"

runs:
using: 'composite'
using: "composite"
steps:
- run: $GITHUB_ACTION_PATH/script.sh
shell: sh
Expand All @@ -59,6 +61,7 @@ runs:
# https://github.heygears.community/t/input-variable-name-is-not-available-in-composite-run-steps/127611
INPUT_GITHUB_TOKEN: ${{ inputs.github_token }}
INPUT_HAML_LINT_FLAGS: ${{ inputs.haml_lint_flags }}
INPUT_HAML_LINT_VERSION: ${{ inputs.haml_lint_version }}
INPUT_RUBOCOP_VERSION: ${{ inputs.rubocop_version }}
INPUT_RUBOCOP_EXTENSIONS: ${{ inputs.rubocop_extensions }}
INPUT_TOOL_NAME: ${{ inputs.tool_name }}
Expand All @@ -71,10 +74,6 @@ runs:
INPUT_SKIP_INSTALL: ${{ inputs.skip_install }}
INPUT_USE_BUNDLER: ${{ inputs.use_bundler }}

# runs:
# using: 'docker'
# image: 'Dockerfile'

branding:
icon: 'check-circle'
color: 'blue'
icon: "check-circle"
color: "blue"
26 changes: 24 additions & 2 deletions script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,31 @@ if [ "${INPUT_SKIP_INSTALL}" = "false" ]; then
done

# Installing haml-lint
# TODO: make the version configurable
# The logic for this is inspired by Rubocop above
# if 'gemfile' haml_lint version selected
if [ "${INPUT_HAML_LINT_VERSION}" = "gemfile" ]; then
# if Gemfile.lock is here
if [ -f 'Gemfile.lock' ]; then
# grep for rubocop version
HAML_LINT_GEMFILE_VERSION=$(ruby -ne 'print $& if /^\s{4}haml_lint\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 "$HAML_LINT_GEMFILE_VERSION" ]; then
HAML_LINT_VERSION=$HAML_LINT_GEMFILE_VERSION
else
printf "Cannot get the haml_lint'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 rubocop version
HAML_LINT_VERSION=$INPUT_HAML_LINT_VERSION
fi

echo '::group:: Installing haml-lint'
gem install haml_lint
gem install -N haml_lint --version "${HAML_LINT_VERSION}"

echo '::endgroup::'
fi
Expand Down