v-wordpress-plugin-updater/.github/workflows/pr-auto-fix.yml
2025-08-14 01:32:03 -04:00

97 lines
3.1 KiB
YAML

name: PR Lint and Auto-Fix
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: write
pull-requests: write
jobs:
lint-fix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
- uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
tools: phpcs
# PHPCBF — uses phpcs.xml for standards and ignores vendor paths
- name: PHPCBF
shell: bash
run: |
TARGETS=""
[ -d mu-plugin ] && TARGETS="$TARGETS mu-plugin"
[ -d update-api ] && TARGETS="$TARGETS update-api"
if [ -z "$TARGETS" ]; then
echo "No target dirs found. Skipping PHPCBF."
exit 0
fi
if [ -f vendor/bin/phpcbf ]; then
php vendor/bin/phpcbf --standard=phpcs.xml $TARGETS || true
elif command -v phpcbf >/dev/null 2>&1; then
phpcbf --standard=phpcs.xml $TARGETS || true
else
echo "PHPCBF not available. Skipping."
fi
# ESLint Fix — recursive search, ignoring vendor directories
- name: ESLint Fix
shell: bash
run: |
if [ -f node_modules/eslint/bin/eslint.js ]; then
if find update-api -type f -name "*.js" ! -path "*/vendor/*" | grep -q .; then
node node_modules/eslint/bin/eslint.js \
"update-api/**/*.js" \
--ignore-pattern "vendor/**" \
--ignore-pattern "update-api/vendor/**" \
--fix || true
else
echo "No JS files under update-api/. Skipping ESLint."
fi
else
echo "ESLint not installed locally. Skipping."
fi
# Stylelint Fix — recursive search, ignoring vendor directories
- name: Stylelint Fix
shell: bash
run: |
if [ -f node_modules/stylelint/bin/stylelint.mjs ]; then
if find update-api -type f -name "*.css" ! -path "*/vendor/*" | grep -q .; then
node node_modules/stylelint/bin/stylelint.mjs \
"update-api/**/*.css" \
--ignore-pattern "vendor/**" \
--ignore-pattern "update-api/vendor/**" \
--fix || true
else
echo "No CSS files under update-api/. Skipping Stylelint."
fi
else
echo "Stylelint not installed locally. Skipping."
fi
# Commit changes directly to the PR branch
- name: Commit fixes to PR branch
id: commit_push
continue-on-error: true
run: |
git config core.filemode false
git add -A
if [ -n "$(git status --porcelain)" ]; then
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git commit -m "chore: auto-lint fixes"
git push origin HEAD:${{ github.head_ref }}
else
echo "No changes to commit."
fi