-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2cc43d4
Showing
5 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM koalaman/shellcheck-alpine | ||
|
||
RUN apk --no-cache add jq bash curl git git-lfs | ||
|
||
COPY entrypoint.sh /entrypoint.sh | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<p align="center"> | ||
<img src=".meta/shellchecker.png" width="30%" height="30%"> | ||
</p> | ||
|
||
<h1 align="center"> | ||
✅ PR Shell Checker | ||
</h1> | ||
|
||
## Usage | ||
|
||
Create a file `checker.yml` inside `.github/workflows`: | ||
|
||
```yaml | ||
on: [pull_request] | ||
|
||
jobs: | ||
shell-check: | ||
runs-on: ubuntu-latest | ||
name: Shell Checker | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: marounmaroun/shell-checker@v1 | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
severity: 'info' | ||
exclude: '' | ||
``` | ||
You can set the severity to one of: "error, warning, info, style". Default is "info". | ||
You can also include type of warnings to exclude. For example: | ||
```yaml | ||
exclude: 'SC2006,SC2148' | ||
``` | ||
Default value is not set, meaning that there will be no exclusions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: 'PR ShellCheck' | ||
description: 'Run ShellCheck on PR files' | ||
inputs: | ||
GITHUB_TOKEN: | ||
description: 'GitHub token' | ||
required: true | ||
severity: | ||
description: 'Minimum severity of errors to consider' | ||
required: false | ||
default: 'style' | ||
exclude: | ||
description: 'Exclude types of warnings' | ||
required: false | ||
default: '' | ||
runs: | ||
using: 'docker' | ||
image: 'Dockerfile' | ||
args: | ||
- ${{ inputs.GITHUB_TOKEN }} | ||
- ${{ inputs.severity }} | ||
- ${{ inputs.exclude }} | ||
branding: | ||
icon: 'tag' | ||
color: 'green' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
GITHUB_API_URI="https://api.github.com" | ||
GITHUB_API_HEADER="Accept: application/vnd.github.v3+json" | ||
|
||
token="$1" | ||
severity="$2" | ||
exclude="$3" | ||
|
||
echo "---= Excluded params: [$exclude] =---" | ||
echo "---= Severity: $severity =---" | ||
|
||
pr_num=$(jq -r .pull_request.number "$GITHUB_EVENT_PATH") | ||
echo "---= Running on PR #$pr_num =---" | ||
body=$(curl -sSL -H "Authorization: token $token" -H "$GITHUB_API_HEADER" "$GITHUB_API_URI/repos/$GITHUB_REPOSITORY/pulls/$pr_num/files") | ||
|
||
err=0 | ||
for file in $(echo "$body" | jq -r '.[].filename'); do | ||
extension=$(echo "$file" | awk -F . '{print $NF}') | ||
if [[ "$extension" =~ (sh|bash|zsh|ksh) ]]; then | ||
echo "---= checking file $file =---" | ||
shellcheck -e "$exclude" -S "$severity" "$GITHUB_WORKSPACE/$file" || err=$? | ||
fi | ||
done | ||
|
||
exit $err |