From 8ea6c72300dd89b10ec21a02a22d5e60c8f7be23 Mon Sep 17 00:00:00 2001 From: jijihohococo Date: Sat, 27 Dec 2025 12:02:17 +0900 Subject: [PATCH] Update PHP Quality workflow: refine PHPCBF steps and restrict triggers to master branch --- .github/workflows/php-quality.yaml | 50 ++++++++++++++++++------------ 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/.github/workflows/php-quality.yaml b/.github/workflows/php-quality.yaml index 5c67198..8f688b7 100644 --- a/.github/workflows/php-quality.yaml +++ b/.github/workflows/php-quality.yaml @@ -1,11 +1,12 @@ -name: PHP Auto-Fix & Quality Check +name: PHP Quality on: + pull_request: + branches: + - master push: branches: - - '**' - pull_request: - types: [opened, synchronize, reopened] + - master jobs: # 🔧 Auto-fix coding standards (only once, PHP 8.1) @@ -34,30 +35,41 @@ jobs: # 4️⃣ Run PHPCBF (auto-fix issues) - name: Run PHPCBF - run: phpcbf --standard=PSR12 src/ || true + run: | + # Run PHPCBF but ignore exit code so workflow continues + phpcbf --standard=PSR12 src/ || true + + # Check if PHPCBF changed any files + if ! git diff --quiet; then + echo "PHPCBF_CHANGED=true" >> $GITHUB_ENV + else + echo "PHPCBF_CHANGED=false" >> $GITHUB_ENV + fi # 5️⃣ Commit & push fixes back to branch - name: Commit and push PHPCBF fixes - if: github.ref != 'refs/heads/main' # optional: skip main + if: env.PHPCBF_CHANGED == 'true' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" + + # Add all PHPCBF-modified files git add . - # commit only if there are changes - if ! git diff-index --quiet HEAD; then - git commit -m "PHPCBF: auto-fix coding standards" - # determine branch for PRs or direct pushes - BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" - # pull remote changes to avoid rejection - git fetch origin $BRANCH - git rebase origin/$BRANCH - # push fixes - git push https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git HEAD:$BRANCH - else - echo "No changes to commit, skipping push." - fi + + # Commit with message + git commit -m "PHPCBF: auto-fix coding standards" + + # Determine branch to push + BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" + + # Pull latest to avoid push rejection + git fetch origin $BRANCH + git rebase origin/$BRANCH + + # Push PHPCBF fixes + git push https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git HEAD:$BRANCH # 🧪 Run PHPCS + PHPStan on multiple PHP versions php-quality: