@@ -20,31 +20,27 @@ jobs:
20
20
runs-on : ubuntu-24.04
21
21
steps :
22
22
- name : Checkout code
23
+ uses : actions/checkout@v4
24
+ with :
25
+ path : o
26
+
27
+ - name : Prepare code
23
28
env :
24
- PR_NUMBER : ${{ github.event.pull_request.number }}
25
- PR_HEAD_SHA : ${{ github.event.pull_request.head.sha }}
26
- REPO_OWNER : ${{ github.repository_owner }}
27
- REPO_NAME : ${{ github.event.repository.name }}
29
+ REPO : ${{ github.repository_owner }}/${{ github.event.repository.name }}
30
+ PR : ${{ github.event.pull_request.number }}
28
31
run : |
29
- # Checkout patched files using the REST API and install dependencies concurrently
32
+ # Install dependencies and select files to check
30
33
pip install codespell &
31
34
composer global require -q friendsofphp/php-cs-fixer seld/jsonlint symfony/yaml &
32
- mkdir a
33
35
34
- gh api -H "Accept: application/vnd.github.v3.raw" \
35
- "/repos/$REPO_OWNER/$REPO_NAME/contents/.php-cs-fixer.dist.php?ref=$PR_HEAD_SHA" \
36
- > a/.php-cs-fixer.dist.php || rm a/.php-cs-fixer.dist.php &
37
-
38
- gh api --paginate "/repos/$REPO_OWNER/$REPO_NAME/pulls/$PR_NUMBER/files" \
39
- | jq -c '.[] | select(.status != "removed") | {filename, sha}' \
40
- | while read -r FILE_OBJ; do
41
- FILENAME=$(echo "$FILE_OBJ" | jq -r '.filename')
42
- FILE_SHA=$(echo "$FILE_OBJ" | jq -r '.sha')
36
+ mkdir a
37
+ [ -e o/.php-cs-fixer.dist.php ] && cp -a {o,a}/.php-cs-fixer.dist.php
43
38
39
+ gh api --paginate "/repos/$REPO/pulls/$PR/files" \
40
+ | jq -c '.[] | select(.status != "removed") | filename' \
41
+ | while read -r FILENAME; do
44
42
mkdir -p "a/$(dirname "$FILENAME")"
45
- gh api -H "Accept: application/vnd.github.raw" \
46
- "/repos/$REPO_OWNER/$REPO_NAME/git/blobs/$FILE_SHA" \
47
- > "a/$FILENAME" &
43
+ cp -a {o,a}/"$FILENAME"
48
44
done
49
45
50
46
wait
@@ -86,13 +82,12 @@ jobs:
86
82
- name : Check for merge commits
87
83
if : always()
88
84
env :
89
- PR_NUMBER : ${{ github.event.pull_request.number }}
90
- REPO_OWNER : ${{ github.repository_owner }}
91
- REPO_NAME : ${{ github.event.repository.name }}
85
+ REPO : ${{ github.repository_owner }}/${{ github.event.repository.name }}
86
+ PR : ${{ github.event.pull_request.number }}
92
87
run : |
93
88
# If a PR contains merge commits, fail the job
94
89
gh api -H "Accept: application/vnd.github.v3+json" \
95
- "/repos/$REPO_OWNER/$REPO_NAME /pulls/$PR_NUMBER /commits" \
90
+ "/repos/$REPO_OWNER/$REPO /pulls/$PR /commits" \
96
91
| jq -r '.[].parents | length > 1' | grep true > /dev/null && {
97
92
echo "::error::Merge commits are not allowed in pull requests."
98
93
echo "Please rebase your branch."
@@ -245,6 +240,30 @@ jobs:
245
240
exit 1
246
241
fi
247
242
243
+ - name : Check file permissions
244
+ if : always()
245
+ run : |
246
+ # Check for executable files without a shebang or that are not recognized as executables
247
+ cd a
248
+ find -type f -perm /u+x,g+x,o+x | while read -r FILE_PATH; do
249
+ if head -n 1 "$FILE_PATH" 2>/dev/null | grep -q '^#!'; then
250
+ continue
251
+ fi
252
+ if file -b "$file_path" 2>/dev/null | grep -qi 'elf'; then
253
+ continue
254
+ fi
255
+ echo "$FILE_PATH" >> ../PROBLEM_FILES
256
+ done
257
+ cd ..
258
+
259
+ if [ -e PROBLEM_FILES ]; then
260
+ echo "::error::Found executable files without a shebang or that are not recognized as executables:"
261
+ echo -e "\n \n$(cat PROBLEM_FILES)\n \n"
262
+ echo "Remove executable permissions: 'chmod -x <file>' for each listed file."
263
+ rm PROBLEM_FILES
264
+ exit 1
265
+ fi
266
+
248
267
- name : 🧠 Fabbot can generate false-positives. Cherry-pick as fits 🍒. Reviewers will help.
249
268
if : always()
250
269
run : exit 0
0 commit comments