Skip to content

chore: add utils/check-file-permissions script #9558

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

Closed
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/test-file-permissions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
uses: actions/checkout@v4

- name: Detect unnecessary execution permissions
run: php utils/check_permission_x.php
run: utils/check-file-permissions
51 changes: 51 additions & 0 deletions utils/check-file-permissions
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash
set -eu

INCLUDE_DIRS=(
'.github/'
'admin/'
'app/'
'changelogs/'
'contributing/'
'public/'
'system/'
'tests/'
'user_guide_src/'
'utils/'
'writable/'
)
EXCLUDE_FILES=(
':!.github/scripts/deploy-userguide'
':!admin/release-userguide'
':!admin/release-deploy'
':!admin/apibot'
':!admin/alldocs'
':!admin/release'
':!admin/docbot'
':!admin/release-notes.bb'
':!admin/release-revert'
':!admin/starter/builds'
':!admin/userguide/.github/scripts/deploy.sh'
':!user_guide_src/add-edit-this-page'
':!utils/check-file-permissions'
)
FILES_WITH_WRONG_PERMISSIONS=$(
git ls-files --stage "${INCLUDE_DIRS[@]}" "${EXCLUDE_FILES[@]}" \
| grep --extended-regexp "^100755 " \
| sort -fh
)

if [[ -n "$FILES_WITH_WRONG_PERMISSIONS" ]]; then
printf '\033[41m FAIL \033[0m Files with unnecessary execution permissions were detected:\n'
[[ -z "${GITHUB_ACTIONS+x}" ]] || echo '::group::Non-executable files'
echo "$FILES_WITH_WRONG_PERMISSIONS" | awk '{print " - " $4}'
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 "$FILES_WITH_WRONG_PERMISSIONS" ]]; then
exit 1
fi

printf '\033[42m OK \033[0m No files with unnecessary execution permissions were detected.\n'
95 changes: 0 additions & 95 deletions utils/check_permission_x.php

This file was deleted.