Skip to content

test api diff

test api diff #596

Workflow file for this run

name: Formatter
on:
pull_request_target:
types: [opened, synchronize, reopened]
# Cancel previous runs if a new one is triggered
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
JAVA_VERSION: '21'
permissions:
contents: read
pull-requests: write
issues: write
jobs:
check-permissions:
uses: ./.github/workflows/check-permissions.yml
formatter:
needs: check-permissions
name: Verify Java code format
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: "${{ env.JAVA_VERSION }}"
distribution: 'temurin'
cache: 'maven'
- name: Run formatter
id: formatter
run: |
echo "Running formatter..."
mvn -B -q spotless:apply -P benchmark 2>&1 | grep -v null || true
# Check for modified files
files=$(git status --porcelain | awk '{print $2}')
modified=$(echo "$files" | wc -w | xargs)
echo "modified=$modified" >> $GITHUB_OUTPUT
if [ "$modified" -gt 0 ]; then
echo "Modified files:"
echo "$files"
git diff > formatter-diff.txt
echo "files<<EOF" >> $GITHUB_OUTPUT
echo "$files" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi
- name: Upload formatter diff
if: steps.formatter.outputs.modified != '0'
uses: actions/upload-artifact@v4
with:
name: formatter-diff
path: formatter-diff.txt
retention-days: 30
- name: Find existing comment
if: steps.formatter.outputs.modified != '0'
uses: peter-evans/find-comment@v3
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: '<!-- tc-formatter -->'
- name: Create or update comment
if: steps.formatter.outputs.modified != '0'
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
edit-mode: replace
body: |
<!-- tc-formatter -->
### Format Checker Report
![BLOCKER][BLOCKER] There are **${{ steps.formatter.outputs.modified }} files** with format errors
[BLOCKER]: https://sonarsource.github.io/sonar-github/severity-blocker.png 'Severity: BLOCKER'
- To see a complete report of formatting issues, download the [differences artifact](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
- To fix the build, please run `mvn spotless:apply` in your branch and commit the changes.
- Optionally you might add the following line in your `.git/hooks/pre-commit` file:
mvn spotless:apply
Here is the list of files with format issues in your PR:
```
${{ steps.formatter.outputs.files }}
```
- name: Delete comment if formatting is correct
if: steps.formatter.outputs.modified == '0' && steps.find-comment.outputs.comment-id != ''
uses: actions/github-script@v7
with:
script: |
github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ steps.find-comment.outputs.comment-id }}
})
- name: Fail if formatting issues exist
if: steps.formatter.outputs.modified != '0'
run: |
echo "::error::There are ${{ steps.formatter.outputs.modified }} files with format errors"
exit 1