Skip to content

Commit c75b4e1

Browse files
authored
Merge pull request #2 from patch-technology/pc/script
Switch to a script instead of docker
2 parents c0719f5 + 3cb64c4 commit c75b4e1

File tree

7 files changed

+197
-106
lines changed

7 files changed

+197
-106
lines changed

.github/workflows/dockerimage.yml

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

.github/workflows/reviewdog.yml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,6 @@ jobs:
2222
reporter: ${{ steps.reporter.outputs.value }}
2323
level: warning
2424

25-
hadolint:
26-
name: runner / hadolint
27-
runs-on: ubuntu-latest
28-
steps:
29-
- uses: actions/checkout@v3
30-
- uses: haya14busa/action-cond@v1
31-
id: reporter
32-
with:
33-
cond: ${{ github.event_name == 'pull_request' }}
34-
if_true: "github-pr-review"
35-
if_false: "github-check"
36-
- uses: reviewdog/action-hadolint@v1
37-
with:
38-
github_token: ${{ secrets.github_token }}
39-
reporter: ${{ steps.reporter.outputs.value }}
40-
level: warning
41-
4225
misspell:
4326
name: runner / misspell
4427
runs-on: ubuntu-latest

.github/workflows/test.yml

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,41 @@
11
name: Test
2-
on:
3-
push:
4-
branches:
5-
- master
6-
pull_request:
2+
on: [pull_request]
73
jobs:
8-
test-check:
9-
name: runner / haml-lint (github-check)
4+
haml-lint:
5+
name: runner / haml-lint
106
runs-on: ubuntu-latest
117
steps:
128
- uses: actions/checkout@v3
13-
- uses: ./
9+
- uses: ruby/setup-ruby@v1
10+
with:
11+
ruby-version: 3.1
12+
bundler-cache: true
13+
- name: github-check
14+
uses: ./
1415
with:
1516
github_token: ${{ secrets.github_token }}
1617
reporter: github-check
1718
level: info
18-
19-
test-pr-check:
20-
if: github.event_name == 'pull_request'
21-
name: runner / haml-lint (github-pr-check)
22-
runs-on: ubuntu-latest
23-
steps:
24-
- uses: actions/checkout@v3
25-
- uses: ./
19+
- name: github-pr-check with workdir
20+
uses: ./
2621
with:
2722
github_token: ${{ secrets.github_token }}
2823
reporter: github-pr-check
2924
level: warning
3025
workdir: ./testdata/subdir/
31-
32-
test-pr-review:
33-
if: github.event_name == 'pull_request'
34-
name: runner / haml-lint (github-pr-review)
35-
runs-on: ubuntu-latest
36-
steps:
37-
- uses: actions/checkout@v3
38-
- uses: ./
26+
- name: github-pr-review with extra flags
27+
uses: ./
3928
with:
4029
github_token: ${{ secrets.github_token }}
4130
reporter: github-pr-review
4231
level: error
43-
haml_lint_config: -c ./testdata/.haml-lint.yml
32+
haml_lint_flags: -c ./testdata/.haml-lint.yml
4433
reviewdog_flags: -filter-mode=file -fail-on-error
34+
- name: github-pr-review with rubocop version
35+
uses: ./
36+
with:
37+
github_token: ${{ secrets.github_token }}
38+
reporter: github-pr-review
39+
level: error
40+
haml_lint_flags: -c ./testdata/.haml-lint.yml
41+
rubocop_version: 1.31.2

Dockerfile

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

action.yml

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
name: 'Run haml-lint via reviewdog'
22
description: '🐶 Run haml-lint with reviewdog on pull requests to improve code review experience.'
3-
author: 'Anton Dalgren'
3+
author: 'pcothenet'
44
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)