Skip to content

Commit c853e9f

Browse files
committed
chore: add utils/check-file-permissions script
1 parent db79418 commit c853e9f

File tree

3 files changed

+51
-96
lines changed

3 files changed

+51
-96
lines changed

.github/workflows/test-file-permissions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ jobs:
2121
uses: actions/checkout@v4
2222

2323
- name: Detect unnecessary execution permissions
24-
run: php utils/check_permission_x.php
24+
run: utils/check-file-permissions

utils/check-file-permissions

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
set -eu
3+
4+
INCLUDE_DIRS=(
5+
'.github/'
6+
'admin/'
7+
'app/'
8+
'changelogs/'
9+
'contributing/'
10+
'public/'
11+
'system/'
12+
'tests/'
13+
'user_guide_src/'
14+
'utils/'
15+
'writable/'
16+
)
17+
EXCLUDE_FILES=(
18+
':!.github/scripts/deploy-userguide'
19+
':!admin/release-userguide'
20+
':!admin/release-deploy'
21+
':!admin/apibot'
22+
':!admin/alldocs'
23+
':!admin/release'
24+
':!admin/docbot'
25+
':!admin/release-notes.bb'
26+
':!admin/release-revert'
27+
':!admin/starter/builds'
28+
':!admin/userguide/.github/scripts/deploy.sh'
29+
':!user_guide_src/add-edit-this-page'
30+
)
31+
FILES_WITH_WRONG_PERMISSIONS=$(
32+
git ls-files --stage "${INCLUDE_DIRS[@]}" "${EXCLUDE_FILES[@]}" \
33+
| grep --extended-regexp "^100755 " \
34+
| sort -fh
35+
)
36+
37+
if [[ -n "$FILES_WITH_WRONG_PERMISSIONS" ]]; then
38+
printf '\033[41m FAIL \033[0m Files with unnecessary execution permissions were detected:\n'
39+
[[ -z "${GITHUB_ACTIONS+x}" ]] || echo '::group::Non-executable files'
40+
echo "$FILES_WITH_WRONG_PERMISSIONS" | awk '{print " - " $4}'
41+
echo ''
42+
echo "$FILES_WITH_WRONG_PERMISSIONS" | awk '{print $4}' | xargs -n1 printf 'Please run "\033[32msudo chmod\033[0m -x %s".\n'
43+
[[ -z "${GITHUB_ACTIONS+x}" ]] || echo '::endgroup::'
44+
fi
45+
46+
if [[ -n "$FILES_WITH_WRONG_PERMISSIONS" ]]; then
47+
exit 1
48+
fi
49+
50+
printf '\033[42m OK \033[0m No files with unnecessary execution permissions were detected.\n'

utils/check_permission_x.php

Lines changed: 0 additions & 95 deletions
This file was deleted.

0 commit comments

Comments
 (0)