-
Notifications
You must be signed in to change notification settings - Fork 0
59 lines (51 loc) · 1.62 KB
/
shellcheck.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
name: ShellCheck Modified Files
on:
pull_request:
branches:
- master
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: |
CHANGED_FILES=$(git diff --name-only origin/master | grep '\.sh$' || true)
echo "Found changed files:"
echo "$CHANGED_FILES"
{
echo "files<<EOF"
echo "$CHANGED_FILES"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- 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 -x "$file"; then
# If shellcheck fails, output error in GitHub Actions format
echo "::error file=$file::ShellCheck found issues in $file"
exit 1
fi
echo "shellcheck for $file success..."
fi
done <<< "$FILES"
fi