Skip to content

[3.3] Fix code formatting issues on pull request #15391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 40 additions & 7 deletions .github/workflows/build-and-test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ jobs:
check-format:
name: "Check if code needs formatting"
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit the changed files back to the repository.
contents: write
Comment on lines +39 to +41
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All repos under apache organization cannot grant write permission to workflows running on PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the write permission is ganted for the PR branch of the forked repos such as https://github.com/zrlw/dubbo, it should not be trigged on apache/dubbo because the code formatting issues should be fixed at forked repos, do you mean the forked repos is also under apache organization?
by the way, this PR is posted only for for discussion of #15388. We still need to discuss whether it's necessary to do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Controlling permissions for GITHUB_TOKEN
https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/controlling-permissions-for-github_token
contents: write allows the action to create a release.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see, there are many contributors who don't enable github actions on their forked repos.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the write permission is ganted for the PR branch of the forked repos such as https://github.com/zrlw/dubbo, it should not be trigged on apache/dubbo because the code formatting issues should be fixed at forked repos, do you mean the forked repos is also under apache organization? by the way, this PR is posted only for for discussion of #15388. We still need to discuss whether it's necessary to do this.

Question about it.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

steps:
- name: "Checkout"
uses: actions/checkout@v4
Expand Down Expand Up @@ -64,15 +67,45 @@ jobs:
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
cat mvn.log | grep "ERROR" | sed 's/Check if code needs formatting Check if code aligns with code style [0-9A-Z:.-]\+//' | sed 's/\[ERROR] //' | head -n -11 >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "Please run \`mvn spotless:apply\` to fix the formatting issues." >> $GITHUB_STEP_SUMMARY
- name: "Fail if code needs formatting"
- name: "Fix code formatting issues by using spotless:apply"
id: apply
if: ${{ steps.check.outcome == 'failure' }}
uses: actions/github-script@v7.0.1
run: mvn --log-file spotless.log spotless:apply
continue-on-error: true
- name: "Upload spotless apply result"
if: ${{ steps.check.outcome == 'failure' }}
uses: actions/upload-artifact@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
core.setFailed("Formatting issues found! \nRun \`mvn spotless:apply\` to fix.")

name: spotless-result
path: spotless.log
- name: "Generate Summary for successful spotless:apply"
if: ${{ steps.check.outcome == 'failure' && steps.apply.outcome == 'success' }}
run: |
echo ":ballot_box_with_check: Kudos! Code formatting issues are fixed by using spotless:apply!" >> $GITHUB_STEP_SUMMARY
- name: "Generate Summary for failed spotless:apply"
if: ${{ steps.check.outcome == 'failure' && steps.apply.outcome == 'failure' }}
run: |
echo "## :negative_squared_cross_mark: Code formatting issues aren't fixed by using spotless:apply!" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
cat spotless.log | grep "ERROR" | sed 's/\[ERROR] //' | head -n -11 >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
- name: "Commit code formatting changes back to the PR branch"
id: commit
if: ${{ steps.check.outcome == 'failure' && steps.apply.outcome == 'success' }}
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Apply code formatting changes with Spotless"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
- name: "Generate Summary for successful commit"
if: ${{ steps.check.outcome == 'failure' && steps.apply.outcome == 'success' && steps.commit.outcome == 'success'}}
run: |
echo ":ballot_box_with_check: Kudos! Code formatting changes are committed!" >> $GITHUB_STEP_SUMMARY
- name: "Generate Summary for failed commit"
if: ${{ steps.check.outcome == 'failure' && steps.apply.outcome == 'success' && steps.commit.outcome == 'failure'}}
run: |
echo "## :negative_squared_cross_mark: Code formatting changes aren't committed!" >> $GITHUB_STEP_SUMMARY
license:
name: "Check License"
needs: check-format
Expand Down