优化并且修复一些问题 #63
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: Format Code | |
| on: | |
| workflow_dispatch: # 手动触发 | |
| pull_request: | |
| types: [closed] # PR合并后触发 | |
| branches: [ "**" ] | |
| jobs: | |
| format: | |
| # 只在PR被合并时运行 | |
| if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch' | |
| runs-on: ubuntu-latest | |
| permissions: # 添加写入权限 | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| ref: ${{ github.head_ref || github.ref_name }} | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| cache: maven | |
| - name: Format code with Spotless | |
| run: mvn spotless:apply | |
| - name: Check for changes | |
| id: git-check | |
| run: | | |
| git diff --exit-code || echo "changes=true" >> $GITHUB_OUTPUT | |
| - name: Commit changes | |
| if: steps.git-check.outputs.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 . | |
| git commit -m "style: format code with spotless" | |
| git push |