Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only run against modified shell files #407

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
on: [push]
jobs:
shellcheck:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install ShellCheck
run: sudo apt-get install -y shellcheck

- name: Run ShellCheck
run: shellcheck $(awk -F'=' '/^source=/{print $2}' .shellcheckrc)
2 changes: 2 additions & 0 deletions .shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source=dev-mode.sh
source=update_shellcheckrc.sh
8 changes: 8 additions & 0 deletions dev-mode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

touch ./.git/hooks/pre-commit

chmod +x ./.git/hooks/pre-commit

echo "#!/bin/bash" >./.git/hooks/pre-commit
echo "bash ./update_shellcheckrc.sh" >>./.git/hooks/pre-commit
18 changes: 18 additions & 0 deletions update_shellcheckrc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
# Get the list of modified shell files
MODIFIED_FILES=$(git diff --name-only master | grep -E '\.sh$' || true)

# Update the .shellcheckrc file
if [ -n "$MODIFIED_FILES" ]; then
# Remove previous entries
sed -i '/^source=.*$/d' .shellcheckrc
for file in $MODIFIED_FILES; do
echo "source=$file" >>.shellcheckrc
done

# Add .shellcheckrc to the staging
echo "Adding .shellcheck to the staging."
git add .shellcheckrc
else
echo "No modified shell files to check."
fi