https://github.com/jayllyz/clang-format-action
Action to check or format your code with clang-format.
https://github.com/jayllyz/clang-format-action
action clang-format clang-format-action
Last synced: 27 days ago
JSON representation
Action to check or format your code with clang-format.
- Host: GitHub
- URL: https://github.com/jayllyz/clang-format-action
- Owner: Jayllyz
- License: mit
- Created: 2024-01-06T10:27:02.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-10T07:12:03.000Z (5 months ago)
- Last Synced: 2025-03-29T10:34:58.269Z (about 1 month ago)
- Topics: action, clang-format, clang-format-action
- Language: Shell
- Homepage: https://github.com/marketplace/actions/clang-formatter-action
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Clang formatter action

[](https://github.com/jayllyz/clang-format-action)


[](https://github.com/Jayllyz/clang-format-action/actions/workflows/ci.yml)This action runs clang-format on the latest commit.
Many clang-format alternatives exist, I know, but i wanted to learn how to write a GitHub action.Also, i'll keep this updated with the latest alpine version and will try to add as many options as possible.
## Usage
Example workflow:
```yml
---
name: "Clang format"on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 2- uses: jayllyz/clang-format-action@v1
# Default options
with:
check: false
style: file
extensions: cpp,h,hpp,c
clang-version: latest# commit the changes (if there are any)
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "chore(style): clang format files"
branch: ${{ github.head_ref }}
...
```## Options
You can read more about the options here : [clang style docs](https://clang.llvm.org/docs/ClangFormatStyleOptions.html).
| Option | Description | Default |
|-----------------|------------------------------------------------------------------------------------------------------------------|---------------|
| `check` | If true, will only check if the files are formatted correctly. If false, will format the files. | `false` |
| `style` | Style to use for formatting. can be: `file`,`LLVM`,`GNU`,`Google`,`Chromium`,`Microsoft`,`Mozilla` or `Webkit`. | `file` |
| `extensions` | Comma-separated list of file extensions to check. Do not include the dot. | `cpp,h,hpp,c` |
| `clang-version` | Specify the major version of clang to use. | `latest` |
| `base-ref` | Base ref to run git-clang-format against. | `HEAD^` |## Action Badge
```md
[](https://github.com/Jayllyz/clang-format-action)
```## Credits
- [stefanzweifel/git-auto-commit-action](https://github.com/stefanzweifel/git-auto-commit-action)
- [actions/checkout](https://github.com/actions/checkout)
- [hcpsilva/clang-format-action](https://github.com/hcpsilva/clang-format-action)
- [Mavrikant/clang-format-action](https://github.com/Mavrikant/clang-format-action)## License
[MIT License](LICENSE)
## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.