mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-03 06:42:27 +08:00
- Use head.sha instead of head_ref for checkout (works for forks) - For fork PRs: fail with helpful message if formatting needed - For same-repo PRs: auto-commit and push as before
58 lines
1.9 KiB
YAML
58 lines
1.9 KiB
YAML
name: Auto Format
|
|
|
|
on:
|
|
pull_request:
|
|
types: [opened, synchronize]
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
jobs:
|
|
format:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: ${{ github.event.pull_request.head.sha }}
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20'
|
|
|
|
- name: Install Biome
|
|
run: npm install --save-dev @biomejs/biome
|
|
|
|
- name: Run Biome format
|
|
run: npx @biomejs/biome check --write --no-errors-on-unmatched .
|
|
|
|
- name: Check for changes
|
|
id: changes
|
|
run: |
|
|
if git diff --quiet; then
|
|
echo "has_changes=false" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "has_changes=true" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
# For fork PRs, just fail if formatting is needed (can't push to forks)
|
|
- name: Fail if fork PR needs formatting
|
|
if: steps.changes.outputs.has_changes == 'true' && github.event.pull_request.head.repo.full_name != github.repository
|
|
run: |
|
|
echo "::error::This PR has formatting issues. Please run 'npx @biomejs/biome check --write .' locally and push the changes."
|
|
git diff --stat
|
|
exit 1
|
|
|
|
# For same-repo PRs, commit and push the changes
|
|
- name: Commit changes
|
|
if: steps.changes.outputs.has_changes == 'true' && github.event.pull_request.head.repo.full_name == github.repository
|
|
run: |
|
|
git config --global user.name "github-actions[bot]"
|
|
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
|
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
|
|
git add .
|
|
git commit -m "style: auto-format with Biome"
|
|
git push origin HEAD:${{ github.head_ref }}
|