@@ -18,39 +18,31 @@ jobs:
1818 with :
1919 php-version : ' 8.1'
2020
21- - name : Check for new PHP files
22- id : check
21+ - name : Add strict types to new PHP files
22+ id : add_strict_types
2323 run : |
24- git fetch origin +refs/heads/trunk:refs/remotes/origin/trunk
24+ git fetch origin +refs/heads/trunk:refs/remotes/origin/trunk --quiet
2525 NEW_PHP_FILES=$(git diff --name-only refs/remotes/origin/trunk HEAD -- '*.php' | xargs -r grep -LE 'declare\( strict_types=1 \)')
2626 if [ -n "$NEW_PHP_FILES" ]; then
27+ echo "$NEW_PHP_FILES" | xargs -I {} sed -i '1s|^|<?php declare( strict_types=1 );\n|' {}
28+ git add $NEW_PHP_FILES
29+ git commit -m "Add strict types to new PHP files"
30+ git push -u origin HEAD:refs/heads/add-strict-types-${{ github.sha }}
2731 echo "::set-output name=strict_types_needed::true"
28- echo "New PHP files without strict types: $NEW_PHP_FILES"
2932 else
33+ echo "No PHP files need strict types."
3034 echo "::set-output name=strict_types_needed::false"
3135 fi
32-
33-
34- - name : Add strict types to new PHP files
35- if : steps.check.outputs.strict_types_needed == 'true'
36- run : |
37- git fetch origin trunk:trunk
38- for file in $(git diff --name-only origin/trunk...HEAD -- '*.php' | xargs grep -LE 'declare\( strict_types=1 \)'); do
39- sed -i '1s/^/<?php declare( strict_types=1 );\n/' "$file"
40- git add "$file"
41- done
42- git commit -m "Add strict types to new PHP files"
43- git push -u origin HEAD:refs/heads/add-strict-types-${{ github.sha }}
4436
4537 - name : Comment on PR
46- if : steps.check .outputs.strict_types_needed == 'true'
38+ if : steps.add_strict_types .outputs.strict_types_needed == 'true'
4739 uses : thollander/actions-comment-pull-request@v1
4840 with :
4941 message : " We've found some PHP files that don't have strict types. This commit adds them. Branch: add-strict-types-${{ github.sha }}"
5042 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
5143
5244 # - name: Create PR
53- # if: steps.check .outputs.strict_types_needed == 'true'
45+ # if: steps.add_strict_types .outputs.strict_types_needed == 'true'
5446 # uses: peter-evans/create-pull-request@v3
5547 # with:
5648 # token: ${{ secrets.GITHUB_TOKEN }}
0 commit comments