Skip to content

ci: fail spider formatters and skip deleted prettier files #5956

ci: fail spider formatters and skip deleted prettier files

ci: fail spider formatters and skip deleted prettier files #5956

Workflow file for this run

name: prettier
on:
pull_request_target:
types: [opened, edited, reopened, synchronize]
concurrency:
group: ${{github.workflow}} - ${{github.ref}}
cancel-in-progress: true
jobs:
format:
# ---------------------------------------------------------
# SAFETY CHECK:
# Only run for PRs from the SAME repository.
# Fork PRs are skipped entirely to prevent RCE via pnpm install.
# ---------------------------------------------------------
if: ${{ github.event.pull_request.head.repo.fork == false && github.event.pull_request.base.ref == 'main' }}
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v7
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}
fetch-depth: 0
- name: Install pnpm
uses: pnpm/action-setup@v6
- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version: 22
- name: Install Dependencies
run: pnpm install --frozen-lockfile --ignore-scripts
- name: Run prettier
run: |
set -euo pipefail
git config --global core.quotepath off
git fetch --depth=1 origin "${{ github.event.pull_request.base.sha }}"
mapfile -t files < <(git diff --name-only --diff-filter=ACMR "${{ github.event.pull_request.base.sha }}" -- '*.js' '*.ts' '*.php' '*.sql' '*.md' || true)
if [ ${#files[@]} -eq 0 ]; then
echo "No matching files to run prettier on."
exit 0
fi
echo "Running prettier on the changed files"
pnpm exec prettier --write "${files[@]}"
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v7
with:
commit_message: "style: format code and docs with prettier"
commit_user_name: idoocs
commit_user_email: doocs-bot@outlook.com