Keeps your repo tidy by running clang-format
on every PR.
Add the following to .github/workflows/pr.yaml
:
name: PR
on:
pull_request:
jobs:
checks:
runs-on: ubuntu-latest
name: checks
steps:
- name: clang-format
id: clang-format
uses: tinybeachthor/gitbot-format@releases/v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
config-path: '.clang-format'
Enjoy automatic clang-format
linting.
Optionally, to allow formatting, add .github/workflows/comment.yaml
:
name: Comment
on:
pull_request:
types:
- opened
- edited
issue_comment:
types:
- created
- edited
jobs:
format:
runs-on: ubuntu-latest
name: Format
env:
TAKE_ACTION: true
steps:
- name: Check for trigger word
uses: khan/[email protected]
id: trigger
with:
trigger: '/format'
reaction: hooray
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: clang-format
id: clang-format
uses: tinybeachthor/gitbot-format@releases/v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
config-path: '.clang-format'
if: steps.trigger.outputs.triggered == 'true'
This will trigger auto-formatting whenever you comment /format
in a PR.
Just a regular .clang-format
file in the root of the repo.
Checks on the default branch first, PR branch second, and defaults
to -style=Google
if none found.
Only looks on files changed in a PR, so that it does not introduce extra changes from beyond the scope of the PR.
Why prefer stylefile from the default branch to feature branch stylefile?
Since the goal is to keep the format of the whole codebase consistent, preferring the default branch stylefile will enforce the same style on all feature branches and make changes to the stylefile propagate instantly (no need to rebase every feature branch)
ISC © 2020 Martin Toman [email protected]