test: 测试自动format #1
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Auto Format | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| - develop | |
| - v2 | |
| types: [opened, synchronize, ready_for_review] | |
| jobs: | |
| auto-format: | |
| runs-on: ubuntu-latest | |
| if: github.event.pull_request.draft == false && github.event.pull_request.head.repo.full_name == github.repository | |
| steps: | |
| - name: Check out Git repository | |
| uses: actions/checkout@v5 | |
| with: | |
| ref: ${{ github.head_ref }} | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| fetch-depth: 0 | |
| - name: Install Node.js | |
| uses: actions/setup-node@v5 | |
| with: | |
| node-version: 20 | |
| - name: Install corepack | |
| run: corepack enable && corepack prepare [email protected] --activate | |
| - name: Get yarn cache directory path | |
| id: yarn-cache-dir-path | |
| run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT | |
| - name: Cache yarn dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ${{ steps.yarn-cache-dir-path.outputs.dir }} | |
| node_modules | |
| key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-yarn- | |
| - name: Install Dependencies | |
| run: yarn install | |
| - name: Check if formatting is needed | |
| id: format-check | |
| continue-on-error: true | |
| run: yarn format:check | |
| - name: Run auto-format if needed | |
| if: steps.format-check.outcome == 'failure' | |
| run: yarn format | |
| - name: Check for changes | |
| if: steps.format-check.outcome == 'failure' | |
| id: git-check | |
| run: | | |
| git diff --exit-code || echo "has_changes=true" >> $GITHUB_OUTPUT | |
| - name: Commit and push changes | |
| if: steps.format-check.outcome == 'failure' && steps.git-check.outputs.has_changes == 'true' | |
| run: | | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| git add -A | |
| git commit -m "style: auto-format code with biome | |
| 🤖 Automatically formatted code using \`yarn format\` | |
| Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>" | |
| git push | |
| - name: Comment on PR | |
| if: steps.format-check.outcome == 'failure' && steps.git-check.outputs.has_changes == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: '🤖 Auto-formatted code using `yarn format`. Please pull the latest changes.' | |
| }) |