Skip to content

Commit f8edf03

Browse files
committed
ci: Add check-executable-permissions workflow to catch misconfigured file modes
Adds a GitHub Actions workflow to validate that only explicitly intended files (like run.sh or executable binaries) have executable permissions. This helps prevent accidental commits of files with incorrect modes (e.g., *.md, *.txt marked as executable). The check runs on each PR and fails the job if any suspicious file permission is detected, improving repo hygiene and review quality. Exemptions (e.g., run.sh) can be controlled by editing the allowlist. Signed-off-by: Srikanth Muppandam <[email protected]>
1 parent 0c2e49a commit f8edf03

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Enforce Script Executable Permissions
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**/run.sh'
7+
- '**/*.sh'
8+
9+
jobs:
10+
permissions:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Detect missing executable permissions on shell scripts
17+
run: |
18+
# Find all .sh and run.sh scripts without +x
19+
BAD=$(find . -type f -name 'run.sh' -o -name '*.sh' ! -perm -u=x)
20+
if [ -n "$BAD" ]; then
21+
echo "::error file=run.sh,line=1::❌ Some shell scripts are missing executable permissions. This can break CI and LAVA. Please fix before merging."
22+
echo "::error file=run.sh,line=2::To fix, run: find . -name '*.sh' -o -name 'run.sh' | xargs chmod +x && git add . && git commit -m 'Fix: restore executable bits on scripts' && git push"
23+
echo ""
24+
echo "The following scripts need 'chmod +x':"
25+
echo "$BAD"
26+
# Output a PR annotation for each file
27+
echo "$BAD" | while read -r file; do
28+
echo "::error file=$file,line=1::$file is not executable. Please run: chmod +x $file && git add $file"
29+
done
30+
exit 1
31+
else
32+
echo "✅ All shell scripts have correct executable permissions."
33+
fi
34+
35+
- name: Detect accidental executables on non-shell files (optional, warning only)
36+
run: |
37+
# (Advanced/optional) Warn if any non-.sh file has +x (customize as needed)
38+
OTHER_EXEC=$(find . -type f ! -name '*.sh' ! -name 'run.sh' -perm -u=x)
39+
if [ -n "$OTHER_EXEC" ]; then
40+
echo "::warning file=run.sh,line=1::Warning: Non-shell files with executable permissions detected. Review if needed."
41+
echo "$OTHER_EXEC"
42+
fi

0 commit comments

Comments
 (0)