Skip to content

Add CI workflow to check for unintended executable permissions in scripts #67

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
42 changes: 42 additions & 0 deletions .github/workflows/check-executable-permissions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Enforce Script Executable Permissions

on:
pull_request:
paths:
- '**/run.sh'
- '**/*.sh'

jobs:
permissions:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Detect missing executable permissions on shell scripts
run: |
# Find all .sh and run.sh scripts without +x
BAD=$(find . -type f -name 'run.sh' -o -name '*.sh' ! -perm -u=x)
if [ -n "$BAD" ]; then
echo "::error file=run.sh,line=1::❌ Some shell scripts are missing executable permissions. This can break CI and LAVA. Please fix before merging."
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"
echo ""
echo "The following scripts need 'chmod +x':"
echo "$BAD"
# Output a PR annotation for each file
echo "$BAD" | while read -r file; do
echo "::error file=$file,line=1::$file is not executable. Please run: chmod +x $file && git add $file"
done
exit 1
else
echo "βœ… All shell scripts have correct executable permissions."
fi

- name: Detect accidental executables on non-shell files (optional, warning only)
run: |
# (Advanced/optional) Warn if any non-.sh file has +x (customize as needed)
OTHER_EXEC=$(find . -type f ! -name '*.sh' ! -name 'run.sh' -perm -u=x)
if [ -n "$OTHER_EXEC" ]; then
echo "::warning file=run.sh,line=1::Warning: Non-shell files with executable permissions detected. Review if needed."
echo "$OTHER_EXEC"
fi
Loading