Skip to content

Commit 6dcddae

Browse files
committed
Switch to scripting
1 parent c0719f5 commit 6dcddae

File tree

4 files changed

+174
-50
lines changed

4 files changed

+174
-50
lines changed

Dockerfile

Lines changed: 0 additions & 17 deletions
This file was deleted.

action.yml

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,19 @@ inputs:
55
github_token:
66
description: 'GITHUB_TOKEN'
77
default: '${{ github.token }}'
8-
workdir:
9-
description: 'Working directory relative to the root directory.'
10-
default: '.'
8+
### Flags for haml-lint
9+
haml_lint_flags:
10+
description: 'Additional haml-lint flags'
11+
default: ''
12+
tool_name:
13+
description: 'Tool name to use for reviewdog reporter'
14+
default: 'haml-lint'
15+
### Flags for rubocop ###
16+
rubocop_version:
17+
description: 'Rubocop version'
18+
rubocop_extensions:
19+
description: 'Rubocop extensions'
20+
default: 'rubocop-rails rubocop-performance rubocop-rspec rubocop-i18n rubocop-rake'
1121
### Flags for reviewdog ###
1222
level:
1323
description: 'Report level for reviewdog [info,warning,error]'
@@ -28,13 +38,41 @@ inputs:
2838
reviewdog_flags:
2939
description: 'Additional reviewdog flags'
3040
default: ''
31-
### Flags for haml-lint
32-
haml_lint_flags:
33-
description: 'Additional haml-lint flags'
34-
default: ''
41+
workdir:
42+
description: "The directory from which to look for and run Rubocop. Default '.'"
43+
default: '.'
44+
skip_install:
45+
description: "Do not install Rubocop or its extensions. Default: `false`"
46+
default: 'false'
47+
use_bundler:
48+
description: "Run Rubocop with bundle exec. Default: `false`"
49+
default: 'false'
50+
3551
runs:
36-
using: 'docker'
37-
image: 'Dockerfile'
52+
using: 'composite'
53+
steps:
54+
- run: $GITHUB_ACTION_PATH/script.sh
55+
shell: sh
56+
env:
57+
REVIEWDOG_VERSION: v0.14.1
58+
# INPUT_<VARIABLE_NAME> is not available in Composite run steps
59+
# https://github.community/t/input-variable-name-is-not-available-in-composite-run-steps/127611
60+
INPUT_GITHUB_TOKEN: ${{ inputs.github_token }}
61+
INPUT_RUBOCOP_VERSION: ${{ inputs.rubocop_version }}
62+
INPUT_RUBOCOP_EXTENSIONS: ${{ inputs.rubocop_extensions }}
63+
INPUT_TOOL_NAME: ${{ inputs.tool_name }}
64+
INPUT_LEVEL: ${{ inputs.level }}
65+
INPUT_REPORTER: ${{ inputs.reporter }}
66+
INPUT_FILTER_MODE: ${{ inputs.filter_mode }}
67+
INPUT_FAIL_ON_ERROR: ${{ inputs.fail_on_error }}
68+
INPUT_REVIEWDOG_FLAGS: ${{ inputs.reviewdog_flags }}
69+
INPUT_WORKDIR: ${{ inputs.workdir }}
70+
INPUT_SKIP_INSTALL: ${{ inputs.skip_install }}
71+
INPUT_USE_BUNDLER: ${{ inputs.use_bundler }}
72+
73+
# runs:
74+
# using: 'docker'
75+
# image: 'Dockerfile'
3876

3977
branding:
4078
icon: 'check-circle'

entrypoint.sh

Lines changed: 0 additions & 24 deletions
This file was deleted.

script.sh

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#!/bin/sh -e
2+
version() {
3+
if [ -n "$1" ]; then
4+
echo "-v $1"
5+
fi
6+
}
7+
8+
cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit
9+
export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"
10+
11+
TEMP_PATH="$(mktemp -d)"
12+
PATH="${TEMP_PATH}:$PATH"
13+
14+
echo '::group::🐶 Installing reviewdog ... https://github.com/reviewdog/reviewdog'
15+
curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b "${TEMP_PATH}" "${REVIEWDOG_VERSION}" 2>&1
16+
echo '::endgroup::'
17+
18+
# Install rubocop
19+
# This is inspired (read: copied) by https://github.com/reviewdog/action-rubocop/blob/master/script.sh
20+
if [ "${INPUT_SKIP_INSTALL}" = "false" ]; then
21+
echo '::group:: Installing rubocop with extensions ... https://github.com/rubocop/rubocop'
22+
# if 'gemfile' rubocop version selected
23+
if [ "${INPUT_RUBOCOP_VERSION}" = "gemfile" ]; then
24+
# if Gemfile.lock is here
25+
if [ -f 'Gemfile.lock' ]; then
26+
# grep for rubocop version
27+
RUBOCOP_GEMFILE_VERSION=$(ruby -ne 'print $& if /^\s{4}rubocop\s\(\K.*(?=\))/' Gemfile.lock)
28+
29+
# if rubocop version found, then pass it to the gem install
30+
# left it empty otherwise, so no version will be passed
31+
if [ -n "$RUBOCOP_GEMFILE_VERSION" ]; then
32+
RUBOCOP_VERSION=$RUBOCOP_GEMFILE_VERSION
33+
else
34+
printf "Cannot get the rubocop's version from Gemfile.lock. The latest version will be installed."
35+
fi
36+
else
37+
printf 'Gemfile.lock not found. The latest version will be installed.'
38+
fi
39+
else
40+
# set desired rubocop version
41+
RUBOCOP_VERSION=$INPUT_RUBOCOP_VERSION
42+
fi
43+
44+
gem install -N rubocop --version "${RUBOCOP_VERSION}"
45+
46+
# Traverse over list of rubocop extensions
47+
for extension in $INPUT_RUBOCOP_EXTENSIONS; do
48+
# grep for name and version
49+
INPUT_RUBOCOP_EXTENSION_NAME=$(echo "$extension" |awk 'BEGIN { FS = ":" } ; { print $1 }')
50+
INPUT_RUBOCOP_EXTENSION_VERSION=$(echo "$extension" |awk 'BEGIN { FS = ":" } ; { print $2 }')
51+
52+
# if version is 'gemfile'
53+
if [ "${INPUT_RUBOCOP_EXTENSION_VERSION}" = "gemfile" ]; then
54+
# if Gemfile.lock is here
55+
if [ -f 'Gemfile.lock' ]; then
56+
# grep for rubocop extension version
57+
RUBOCOP_EXTENSION_GEMFILE_VERSION=$(ruby -ne "print $& if /^\s{4}$INPUT_RUBOCOP_EXTENSION_NAME\s\(\K.*(?=\))/" Gemfile.lock)
58+
59+
# if rubocop extension version found, then pass it to the gem install
60+
# left it empty otherwise, so no version will be passed
61+
if [ -n "$RUBOCOP_EXTENSION_GEMFILE_VERSION" ]; then
62+
RUBOCOP_EXTENSION_VERSION=$RUBOCOP_EXTENSION_GEMFILE_VERSION
63+
else
64+
printf "Cannot get the rubocop extension version from Gemfile.lock. The latest version will be installed."
65+
fi
66+
else
67+
printf 'Gemfile.lock not found. The latest version will be installed.'
68+
fi
69+
else
70+
# set desired rubocop extension version
71+
RUBOCOP_EXTENSION_VERSION=$INPUT_RUBOCOP_EXTENSION_VERSION
72+
fi
73+
74+
# Handle extensions with no version qualifier
75+
if [ -z "${RUBOCOP_EXTENSION_VERSION}" ]; then
76+
unset RUBOCOP_EXTENSION_VERSION_FLAG
77+
else
78+
RUBOCOP_EXTENSION_VERSION_FLAG="--version ${RUBOCOP_EXTENSION_VERSION}"
79+
fi
80+
81+
# shellcheck disable=SC2086
82+
gem install -N "${INPUT_RUBOCOP_EXTENSION_NAME}" ${RUBOCOP_EXTENSION_VERSION_FLAG}
83+
done
84+
85+
# Installing haml-lint
86+
# TODO: make the version configurable
87+
echo '::group:: Installing haml-lint'
88+
gem install haml_lint
89+
90+
echo '::endgroup::'
91+
fi
92+
93+
export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"
94+
95+
if [ "${INPUT_USE_BUNDLER}" = "false" ]; then
96+
BUNDLE_EXEC=""
97+
else
98+
BUNDLE_EXEC="bundle exec "
99+
fi
100+
101+
echo '::group:: Running haml-lint with reviewdog 🐶 ...'
102+
# shellcheck disable=SC2086
103+
# ${BUNDLE_EXEC}rubocop ${INPUT_RUBOCOP_FLAGS} --require ${GITHUB_ACTION_PATH}/rdjson_formatter/rdjson_formatter.rb --format RdjsonFormatter \
104+
# | reviewdog -f=rdjson \
105+
# -name="${INPUT_TOOL_NAME}" \
106+
# -reporter="${INPUT_REPORTER}" \
107+
# -filter-mode="${INPUT_FILTER_MODE}" \
108+
# -fail-on-error="${INPUT_FAIL_ON_ERROR}" \
109+
# -level="${INPUT_LEVEL}" \
110+
# ${INPUT_REVIEWDOG_FLAGS}
111+
112+
# shellcheck disable=SC2046
113+
# shellcheck disable=SC2086
114+
${BUNDLE_EXEC} haml-lint ${INPUT_HAML_LINT_FLAGS} . \
115+
| reviewdog -efm="%f:%l [%t] %m" \
116+
-name="${INPUT_TOOL_NAME}" \
117+
-reporter="${INPUT_REPORTER}" \
118+
-filter-mode="${INPUT_FILTER_MODE}" \
119+
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \
120+
-level="${INPUT_LEVEL}" \
121+
${INPUT_REVIEWDOG_FLAGS}
122+
123+
reviewdog_rc=$?
124+
echo '::endgroup::'
125+
exit $reviewdog_rc
126+
127+

0 commit comments

Comments
 (0)