Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 4a331e9

Browse files
author
Vicente Canales
committed
refactor
1 parent 51ac833 commit 4a331e9

1 file changed

Lines changed: 27 additions & 25 deletions

File tree

.github/workflows/add-strict-types.yml

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,44 @@ jobs:
1818
with:
1919
php-version: '8.1'
2020

21-
- name: Checking for new PHP files
21+
- name: Check for new PHP files
2222
id: check
2323
run: |
24-
if [[ $(git rev-parse --verify HEAD^) ]]; then
25-
if [[ $(git diff --name-only HEAD^ HEAD | grep -E "\.php$" | xargs grep -L "declare\(strict_types=1\)" | wc -l) -gt 0 ]]; then
26-
echo "::set-output name=strict_types::false"
27-
else
28-
echo "::set-output name=strict_types::true"
29-
fi
24+
git fetch origin trunk
25+
NEW_PHP_FILES=$(git diff --name-only origin/trunk...HEAD -- '*.php' | xargs grep -LE 'declare\( strict_types=1\ )')
26+
if [ -n "$NEW_PHP_FILES" ]; then
27+
echo "::set-output name=strict_types_needed::true"
28+
echo "New PHP files without strict types: $NEW_PHP_FILES"
3029
else
31-
echo "::set-output name=strict_types::true"
30+
echo "::set-output name=strict_types_needed::false"
3231
fi
33-
34-
- name: Add strict types
35-
if: steps.check.outputs.strict_types == 'false'
36-
run: |
37-
git diff --name-only HEAD^ HEAD | grep -E "\.php$" | xargs sed -i '1s/^/<?php declare(strict_types=1);\n\n/'
38-
git diff --name-only HEAD^ HEAD | grep -E "\.php$" | xargs git add
3932
40-
- name: Create a branch, add a comment to PR
41-
if: steps.check.outputs.strict_types == 'false'
33+
- name: Add strict types to new PHP files
34+
if: steps.check.outputs.strict_types_needed == 'true'
4235
run: |
43-
git checkout -b add-strict-types-${{ github.sha }}
44-
git commit -m "Automation: Add strict types to PHP files"
45-
git push origin add-strict-types-${{ github.sha }}
46-
gh pr comment ${{ github.event.pull_request.number }} -b "We've found some PHP files that don't have strict types. This PR adds them."
47-
36+
git fetch origin trunk
37+
for file in $(git diff --name-only origin/trunk...HEAD -- '*.php' | xargs grep -LE 'declare\( strict_types=1\ )'); do
38+
sed -i '1s/^/<?php declare( strict_types=1 );\n/' "$file"
39+
git add "$file"
40+
done
41+
git commit -m "Add strict types to new PHP files"
42+
git push -u origin HEAD:refs/heads/add-strict-types-${{ github.sha }}
43+
44+
- name: Comment on PR
45+
if: steps.check.outputs.strict_types_needed == 'true'
46+
uses: thollander/actions-comment-pull-request@v1
47+
with:
48+
message: "We've found some PHP files that don't have strict types. This commit adds them. Branch: add-strict-types-${{ github.sha }}"
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
4851
# - name: Create PR
49-
# if: steps.check.outputs.strict_types == 'false'
52+
# if: steps.check.outputs.strict_types_needed == 'true'
5053
# uses: peter-evans/create-pull-request@v3
5154
# with:
5255
# token: ${{ secrets.GITHUB_TOKEN }}
53-
# commit-message: "Automation: Add strict types to PHP files"
56+
# commit-message: "Add strict types to new PHP files"
5457
# title: "[Automation]: Add strict types"
55-
# body: |
56-
# We've found some PHP files that don't have strict types. This PR adds them.
58+
# body: "We've found some PHP files that don't have strict types. This PR adds them."
5759
# branch: add-strict-types-${{ github.sha }}
5860
# branch-suffix: timestamp
5961
# labels: Automation

0 commit comments

Comments
 (0)