Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MarounMaroun committed May 29, 2020
0 parents commit 2cc43d4
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 0 deletions.
Binary file added .meta/shellchecker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions Dockerfile
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"]
37 changes: 37 additions & 0 deletions README.md
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.
24 changes: 24 additions & 0 deletions action.yml
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'
26 changes: 26 additions & 0 deletions entrypoint.sh
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

0 comments on commit 2cc43d4

Please sign in to comment.