Skip to content

Commit cf5d262

Browse files
committed
Use haml_lint from gemfile
1 parent a5a9420 commit cf5d262

File tree

2 files changed

+54
-33
lines changed

2 files changed

+54
-33
lines changed

action.yml

+30-31
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,57 @@
1-
name: 'Run haml-lint via reviewdog'
2-
description: '🐶 Run haml-lint with reviewdog on pull requests to improve code review experience.'
3-
author: 'pcothenet'
1+
name: "Run haml-lint via reviewdog"
2+
description: "🐶 Run haml-lint with reviewdog on pull requests to improve code review experience."
3+
author: "pcothenet"
44
inputs:
55
github_token:
6-
description: 'GITHUB_TOKEN'
7-
default: '${{ github.token }}'
6+
description: "GITHUB_TOKEN"
7+
default: "${{ github.token }}"
88
### Flags for haml-lint
99
haml_lint_flags:
10-
description: 'Additional haml-lint flags'
11-
default: ''
10+
description: "Additional haml-lint flags"
11+
default: ""
12+
haml_lint_version:
13+
description: "The version of haml_lint to use. Use "gemfile" to use the version from Gemfile.lock"
1214
tool_name:
13-
description: 'Tool name to use for reviewdog reporter'
14-
default: 'haml-lint'
15-
### Flags for rubocop ###
15+
description: "Tool name to use for reviewdog reporter"
16+
default: "haml-lint"
17+
### Flags for rubocop ###
1618
rubocop_version:
17-
description: 'Rubocop version'
19+
description: "The version of rubocop to use. Use "gemfile" to use the version from Gemfile.lock"
1820
rubocop_extensions:
19-
description: 'Rubocop extensions'
20-
default: 'rubocop-rails rubocop-performance rubocop-rspec rubocop-i18n rubocop-rake'
21+
description: "Rubocop extensions"
22+
default: "rubocop-rails rubocop-performance rubocop-rspec rubocop-i18n rubocop-rake"
2123
### Flags for reviewdog ###
2224
level:
23-
description: 'Report level for reviewdog [info,warning,error]'
24-
default: 'error'
25+
description: "Report level for reviewdog [info,warning,error]"
26+
default: "error"
2527
reporter:
26-
description: 'Reporter of reviewdog command [github-pr-check,github-pr-review].'
27-
default: 'github-pr-check'
28+
description: "Reporter of reviewdog command [github-pr-check,github-pr-review]."
29+
default: "github-pr-check"
2830
filter_mode:
2931
description: |
3032
Filtering for the reviewdog command [added,diff_context,file,nofilter].
3133
Default is added.
32-
default: 'added'
34+
default: "added"
3335
fail_on_error:
3436
description: |
3537
Exit code for reviewdog when errors are found [true,false]
3638
Default is `false`.
37-
default: 'false'
39+
default: "false"
3840
reviewdog_flags:
39-
description: 'Additional reviewdog flags'
40-
default: ''
41+
description: "Additional reviewdog flags"
42+
default: ""
4143
workdir:
4244
description: "The directory from which to look for and run Rubocop. Default '.'"
43-
default: '.'
45+
default: "."
4446
skip_install:
4547
description: "Do not install Rubocop or its extensions. Default: `false`"
46-
default: 'false'
48+
default: "false"
4749
use_bundler:
4850
description: "Run Rubocop with bundle exec. Default: `false`"
49-
default: 'false'
51+
default: "false"
5052

5153
runs:
52-
using: 'composite'
54+
using: "composite"
5355
steps:
5456
- run: $GITHUB_ACTION_PATH/script.sh
5557
shell: sh
@@ -59,6 +61,7 @@ runs:
5961
# https://github.community/t/input-variable-name-is-not-available-in-composite-run-steps/127611
6062
INPUT_GITHUB_TOKEN: ${{ inputs.github_token }}
6163
INPUT_HAML_LINT_FLAGS: ${{ inputs.haml_lint_flags }}
64+
INPUT_HAML_LINT_VERSION: ${{ inputs.haml_lint_version }}
6265
INPUT_RUBOCOP_VERSION: ${{ inputs.rubocop_version }}
6366
INPUT_RUBOCOP_EXTENSIONS: ${{ inputs.rubocop_extensions }}
6467
INPUT_TOOL_NAME: ${{ inputs.tool_name }}
@@ -71,10 +74,6 @@ runs:
7174
INPUT_SKIP_INSTALL: ${{ inputs.skip_install }}
7275
INPUT_USE_BUNDLER: ${{ inputs.use_bundler }}
7376

74-
# runs:
75-
# using: 'docker'
76-
# image: 'Dockerfile'
77-
7877
branding:
79-
icon: 'check-circle'
80-
color: 'blue'
78+
icon: "check-circle"
79+
color: "blue"

script.sh

+24-2
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,31 @@ if [ "${INPUT_SKIP_INSTALL}" = "false" ]; then
8383
done
8484

8585
# Installing haml-lint
86-
# TODO: make the version configurable
86+
# The logic for this is inspired by Rubocop above
87+
# if 'gemfile' haml_lint version selected
88+
if [ "${INPUT_HAML_LINT_VERSION}" = "gemfile" ]; then
89+
# if Gemfile.lock is here
90+
if [ -f 'Gemfile.lock' ]; then
91+
# grep for rubocop version
92+
HAML_LINT_GEMFILE_VERSION=$(ruby -ne 'print $& if /^\s{4}haml_lint\s\(\K.*(?=\))/' Gemfile.lock)
93+
94+
# if rubocop version found, then pass it to the gem install
95+
# left it empty otherwise, so no version will be passed
96+
if [ -n "$HAML_LINT_GEMFILE_VERSION" ]; then
97+
HAML_LINT_VERSION=$HAML_LINT_GEMFILE_VERSION
98+
else
99+
printf "Cannot get the haml_lint's version from Gemfile.lock. The latest version will be installed."
100+
fi
101+
else
102+
printf 'Gemfile.lock not found. The latest version will be installed.'
103+
fi
104+
else
105+
# set desired rubocop version
106+
HAML_LINT_VERSION=$INPUT_HAML_LINT_VERSION
107+
fi
108+
87109
echo '::group:: Installing haml-lint'
88-
gem install haml_lint
110+
gem install -N haml_lint --version "${HAML_LINT_VERSION}"
89111

90112
echo '::endgroup::'
91113
fi

0 commit comments

Comments
 (0)