Skip to content

Commit

Permalink
Add check-file-permissions script
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed Aug 3, 2024
1 parent b40f895 commit a063a2e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/static-code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ jobs:
- name: Install dependencies
run: composer update --ansi

- name: Check - file permissions
run: bin/check-file-permissions

- name: Check - PHP-CS-Fixer
run: composer cs:check

Expand Down
39 changes: 39 additions & 0 deletions bin/check-file-permissions
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env sh
set -eu

FILES_WITH_WRONG_PERMISSIONS=$(
git ls-files --stage . ':!bin/*' \
| grep --extended-regexp "^100755 " \
| sort -fh
)
BIN_FILES_WITH_WRONG_PERMISSIONS=$(
git ls-files --stage bin \
| grep --invert-match --extended-regexp "^100755 " \
| sort -fh
)

if [ -n "$FILES_WITH_WRONG_PERMISSIONS" ]; then
printf '\033[31mFAIL\033[0m Non-executable files with +x permissions were detected!\n'
[ -z "${GITHUB_ACTIONS+x}" ] || echo '::group::Non-executable files'
echo "$FILES_WITH_WRONG_PERMISSIONS"
echo ''
echo "$FILES_WITH_WRONG_PERMISSIONS" | awk '{print $4}' | xargs -n1 printf 'Please run "\033[32msudo chmod\033[0m -x %s".\n'
[ -z "${GITHUB_ACTIONS+x}" ] || echo '::endgroup::'
fi

if [ -n "$BIN_FILES_WITH_WRONG_PERMISSIONS" ]; then
printf '\033[31mFAIL\033[0m Executable files with -x permissions were detected!\n'
[ -z "${GITHUB_ACTIONS+x}" ] || echo '::group::Executable files'
echo "$BIN_FILES_WITH_WRONG_PERMISSIONS"
echo -e ''
echo $BIN_FILES_WITH_WRONG_PERMISSIONS | awk '{print $4}' | xargs -n1 printf 'Please run "\033[32msudo chmod\033[0m +x %s".\n'
[ -z "${GITHUB_ACTIONS+x}" ] || echo '::endgroup::'
fi

if [ -n "$FILES_WITH_WRONG_PERMISSIONS" ]; then
exit 3
elif [ -n "$BIN_FILES_WITH_WRONG_PERMISSIONS" ]; then
exit 4
fi

printf '\033[32mOK\033[0m No wrong permissions were detected.\n'

0 comments on commit a063a2e

Please sign in to comment.