Skip to content

Workflow file for this run

name: ShellCheck Modified Files
on:
push:
branches:
- shellcheck-workflow
paths:
- "**/*.sh"
jobs:
shellcheck:
name: ShellCheck
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install ShellCheck
run: |
sudo apt-get update
sudo apt-get install -y shellcheck
- name: Get changed files
id: changed-files
run: |
echo "files<<EOF" >> $GITHUB_OUTPUT
git diff --name-only HEAD^ HEAD | grep '\.sh$' || echo "" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "Debug: files=$files"
# $GITHUB_OUTPUT is used to set the "files" output for this step.
- name: Debug Output
run: |
echo "Debug: Changed files output = '${{ steps.changed-files.outputs.files }}'"
- name: Run ShellCheck on changed files
if: steps.changed-files.outputs.files != ''
run: |
# Print files being checked
echo "Checking files: ${{ steps.changed-files.outputs.files }}"
FILES="${{ steps.changed-files.outputs.files }}"
# Check if FILES is not empty
if [ -n "$FILES" ]; then
while IFS= read -r file; do
if [ -n "$file" ]; then
echo "Checking $file..."
if ! shellcheck "$file"; then
# If shellcheck fails, output error in GitHub Actions format
echo "::error file=$file::ShellCheck found issues in $file"
exit 1
fi
fi
done <<< "$FILES"
fi