Skip to content

Commit

Permalink
feat: add support for running on windows and macos (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 authored Jan 21, 2023
1 parent fbfac85 commit f6b2d29
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Denote files that are shell scripts and should be normalized (convert crlf -> lf)
# and should be converted to unix line endings on checkout.
*.sh text eol=lf
5 changes: 4 additions & 1 deletion .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ on: [pull_request]
jobs:
shellcheck:
name: runner / shellcheck
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v3
- name: shellcheck-github-pr-check
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,16 @@ jobs:
exclude: "./.git/*" # Optional.
check_all_files_with_shebangs: "false" # Optional.
```

## Known issue

> Running `shellcheck.exe` on Windows might fail with the following error:
`SC1017: Literal carriage return. Run script through tr -d '\r'`
>
> This is due to the presence of a carriage return character (`\r`) in the script.
>
> To fix this, you can add a `.gitattributes` file to your repository with the following contents:
> ```
> *.sh text eol=lf
> ```
> This will ensure that the scripts are checked out with the correct line endings.
19 changes: 16 additions & 3 deletions script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,23 @@ set -u
echo '::group:: Installing shellcheck ... https://github.com/koalaman/shellcheck'
TEMP_PATH="$(mktemp -d)"
cd "${TEMP_PATH}" || exit
curl -sL "https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.linux.x86_64.tar.xz" | tar -xJf -
mkdir bin
cp "shellcheck-v$SHELLCHECK_VERSION/shellcheck" ./bin

WINDOWS_TARGET=zip
LINUX_TARGET=linux.x86_64.tar.xz
MACOS_TARGET=darwin.x86_64.tar.xz

if [[ $(uname -s) == "Linux" ]]; then
curl -sL "https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.${LINUX_TARGET}" | tar -xJf -
cp "shellcheck-v$SHELLCHECK_VERSION/shellcheck" ./bin
elif [[ $(uname -s) == "Darwin" ]]; then
curl -sL "https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.${MACOS_TARGET}" | tar -xJf -
cp "shellcheck-v$SHELLCHECK_VERSION/shellcheck" ./bin
else
curl -sL "https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.${WINDOWS_TARGET}" -o "shellcheck-v${SHELLCHECK_VERSION}.${WINDOWS_TARGET}" && unzip "shellcheck-v${SHELLCHECK_VERSION}.${WINDOWS_TARGET}" && rm "shellcheck-v${SHELLCHECK_VERSION}.${WINDOWS_TARGET}"
cp "shellcheck.exe" ./bin
fi

PATH="${TEMP_PATH}/bin:$PATH"
echo '::endgroup::'

Expand All @@ -33,7 +47,6 @@ while read -r pattern; do
[[ -n ${pattern} ]] && excludes+=(-not -path "${pattern}")
done <<< "${INPUT_EXCLUDE:-}"


# Match all files matching the pattern
files_with_pattern=$(find "${paths[@]}" "${excludes[@]}" -type f "${names[@]}")

Expand Down

0 comments on commit f6b2d29

Please sign in to comment.