-
-
Notifications
You must be signed in to change notification settings - Fork 24
feat: add auto-fix option for automatic clang-format fixing #443
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
base: main
Are you sure you want to change the base?
Changes from 9 commits
9c53f38
34b53ca
5c5b162
7117c22
eaa44a9
ab42a8a
0788568
bfa3613
e3fd91b
f644f7e
350675e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| name: cpp-linter (auto-fix) | ||
| on: | ||
| pull_request: | ||
| branches: [main, master, develop] | ||
| paths: ['**.c', '**.cpp', '**.h', '**.hpp', '**.cxx', '**.hxx', '**.cc', '**.hh', '**CMakeLists.txt', 'meson.build', '**.cmake'] | ||
|
|
||
| jobs: | ||
| cpp-linter: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write # needed for auto-fix commits | ||
| pull-requests: write | ||
| steps: | ||
| - uses: actions/checkout@v7 | ||
| # For auto-fix commits to trigger new CI runs, use a PAT instead: | ||
| # with: | ||
| # token: ${{ secrets.MY_PAT }} | ||
|
|
||
| - uses: cpp-linter/cpp-linter-action@v2 | ||
| id: linter | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| with: | ||
| style: 'file' # Use .clang-format config file | ||
| tidy-checks: '-*' # disable clang-tidy | ||
| auto-fix: 'true' # auto-apply clang-format fixes | ||
|
|
||
| - name: Fail fast?! | ||
| if: steps.linter.outputs.clang-format-checks-failed > 0 | ||
| run: exit 1 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,3 +78,40 @@ The [`tidy-review`](inputs-outputs.md#tidy-review), [`format-review`](inputs-out | |
| permissions: | ||
| pull-requests: write | ||
| ``` | ||
|
|
||
| ## Auto-fix | ||
|
|
||
| The [`auto-fix`](inputs-outputs.md#auto-fix) feature requires `contents: write` permission | ||
| in addition to any other permissions needed for other features: | ||
|
|
||
| ```yaml | ||
| permissions: | ||
| contents: write # (1)! | ||
| ``` | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| 1. Needed to commit and push the formatted changes back to the PR branch. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also note that this permission is only needed by the token used in However, the - uses: actions/checkout@v6
with:
# MY_TOKEN must have `contents: write` permission.
# using default token does not trigger CI runs on `git push`
token: ${{ secrets.MY_TOKEN }}
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another problem that might arise here is when auto-fixing PR changes from a third-party fork. My previous comment was made with experience about pushing changes to the same remote. If the changes need to be pushed to a different remote, then that is a different set of permissions. |
||
|
|
||
| !!! warning "CI re-triggering with auto-fix" | ||
|
|
||
| The default `GITHUB_TOKEN` **cannot** trigger new CI runs when pushing | ||
| a commit. If you need the auto-fix commit to trigger CI checks | ||
| (e.g. to verify the fix builds clean), use a personal access token | ||
| (PAT) with `contents: write` scope: | ||
|
|
||
| ```yaml | ||
| - uses: actions/checkout@v7 | ||
| with: | ||
| token: ${{ secrets.MY_PAT }} | ||
| ``` | ||
|
|
||
| When using the default `GITHUB_TOKEN`, you can include `[skip ci]` in | ||
| the auto-fix commit message to avoid unnecessary CI runs on the | ||
| fix commit itself. See the [`auto-fix-commit-msg`](./inputs-outputs.md#auto-fix-commit-msg) input. | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| !!! warning "Pull requests from third-party forks" | ||
|
|
||
| Auto-fix does not work on pull requests from third-party forks. The | ||
| `GITHUB_TOKEN` lacks write permission to the fork repository, and | ||
| `git push` to the fork's branch is not possible. Consider | ||
| restricting `auto-fix` to `push` events or pull requests from the | ||
| same repository. | ||
Uh oh!
There was an error while loading. Please reload this page.