Skip to content

Commit 0f2a1fd

Browse files
authored
Create check-script.yml
Signed-off-by: CanbiZ <[email protected]>
1 parent fab6cfc commit 0f2a1fd

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

.github/check-script.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Check Shell Scripts
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**/*.sh' # Führt den Check nur für Shell-Skripte aus
7+
8+
jobs:
9+
check-scripts:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout Code
14+
uses: actions/checkout@v3
15+
16+
- name: Check `source` Line in Scripts
17+
shell: bash
18+
run: |
19+
set -e
20+
ERROR_COUNT=0
21+
FILES=$(find . -name "*.sh")
22+
23+
for FILE in $FILES; do
24+
# Check for exact match of the source line in line 2
25+
if [[ $(sed -n '2p' "$FILE") =~ ^source[[:space:]]+<(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func) ]]; then
26+
echo "Check passed for: $FILE"
27+
else
28+
echo "Error in $FILE: Line 2 must be exactly 'source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func)' if a source line is used."
29+
ERROR_COUNT=$((ERROR_COUNT + 1))
30+
fi
31+
32+
# Check for shebang line at the top
33+
if [[ $(head -n 1 "$FILE") != "#!/usr/bin/env bash" ]]; then
34+
echo "Error in $FILE: The first line must be '#!/usr/bin/env bash'."
35+
ERROR_COUNT=$((ERROR_COUNT + 1))
36+
fi
37+
38+
# Check for executable permissions
39+
if [[ ! -x "$FILE" ]]; then
40+
echo "Warning in $FILE: This script is not executable. Consider running 'chmod +x $FILE'."
41+
fi
42+
43+
# Check for empty lines at the beginning of the script
44+
if [[ $(head -n 10 "$FILE" | grep -c '^$') -gt 0 ]]; then
45+
echo "Warning in $FILE: There are empty lines at the beginning of the script. Consider removing them."
46+
fi
47+
done
48+
49+
if [[ "$ERROR_COUNT" -gt 0 ]]; then
50+
echo "$ERROR_COUNT script(s) failed validation."
51+
exit 1
52+
else
53+
echo "All scripts passed."
54+
fi

0 commit comments

Comments
 (0)