Repository navigation
V4 china #2
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: Formatting Check | |
| on: | |
| pull_request: | |
| types: | |
| - opened | |
| - synchronize | |
| - reopened | |
| - ready_for_review | |
| workflow_dispatch: | |
| concurrency: | |
| group: formatting-check-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| checks: write | |
| issues: write | |
| pull-requests: write | |
| jobs: | |
| check-formatting: | |
| name: Check formatting | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v7 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v7 | |
| with: | |
| node-version: 24 | |
| cache: npm | |
| - name: Install dependencies | |
| run: npm ci --ignore-scripts | |
| - name: Apply formatting and collect changes | |
| id: formatting | |
| shell: bash | |
| run: | | |
| npm run format | |
| if git diff --quiet; then | |
| echo "changed=false" >> "$GITHUB_OUTPUT" | |
| echo "Formatting is correct." >> "$GITHUB_STEP_SUMMARY" | |
| exit 0 | |
| fi | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| git diff --no-color > /tmp/formatting.diff | |
| diff_lines=$(wc -l < /tmp/formatting.diff) | |
| { | |
| echo "## Formatting changes required" | |
| echo | |
| echo "Run the following command locally, then commit the changes:" | |
| echo | |
| echo '```bash' | |
| echo 'npm run format' | |
| echo '```' | |
| echo | |
| echo "### Suggested diff" | |
| echo | |
| echo '```diff' | |
| sed -n '1,400p' /tmp/formatting.diff | |
| echo '```' | |
| if [ "$diff_lines" -gt 400 ]; then | |
| echo | |
| echo "Diff truncated to the first 400 of $diff_lines lines." | |
| fi | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| - name: Add inline formatting suggestions | |
| if: > | |
| steps.formatting.outputs.changed == 'true' && | |
| github.event_name == 'pull_request' && | |
| github.event.pull_request.head.repo.full_name == github.repository | |
| uses: reviewdog/action-suggester@v1.24.3 | |
| with: | |
| tool_name: formatter | |
| level: error | |
| filter_mode: diff_context | |
| - name: Explain fork pull request limitation | |
| if: > | |
| steps.formatting.outputs.changed == 'true' && | |
| github.event_name == 'pull_request' && | |
| github.event.pull_request.head.repo.full_name != github.repository | |
| shell: bash | |
| run: | | |
| { | |
| echo | |
| echo "> Inline suggestions were skipped because workflows from fork pull requests receive a read-only token." | |
| echo "> The complete formatting diff is still shown above." | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| - name: Fail formatting check | |
| if: steps.formatting.outputs.changed == 'true' | |
| shell: bash | |
| run: | | |
| echo "Formatting changes are required. Run 'npm run format' locally." | |
| exit 1 |