GitHub Action for clang-format checks. Note that this Action does NOT format your code for you - it only verifies that your repository's code follows your project's formatting conventions.
You can define your own formatting rules in a .clang-format
file at your repository root, or you can provide a fallback style (see fallback-style
). You can also provide a path to check. If you want to run checks against multiple paths in your repository, you can use this Action in a matrix run.
You can sponsor me here!
clang-format-version
[optional]: The version ofclang-format
that you want to run on your codebase.- Default:
10
- Available versions: every version of
clang-format
available on Ubuntu Groovy.
- Default:
check-path
[optional]: The path to the directory in the repo that should be checked for C/C++ formatting.- Default:
.
- For cleaner output (i.e. with no double-slashed paths), the final directory in this path should have no trailing slash, e.g.
src
and notsrc/
.
- Default:
fallback-style
[optional]: The fallback style forclang-format
if no.clang-format
file exists in your repository.- Default:
llvm
- Available values:
LLVM
,Google
,Chromium
,Mozilla
,WebKit
and others listed in theclang-format
docs for BasedOnStyle.
- Default:
This action checks all C/C++ files in the provided directory in the GitHub workspace are formatted correctly using clang-format
. If no directory is provided or the provided path is not a directory in the GitHub workspace, all C/C++ files are checked.
The following file extensions are checked:
- Header files:
.h
.H
.hpp
.hh
.h++
.hxx
- Source files:
.c
.C
.cpp
.cc
.c++
.cxx
- SUCCESS: zero exit-code if C/C++ files in
check-path
are formatted correctly - FAILURE: nonzero exit-code if C/C++ files in
check-path
are not formatted correctly
To use this action, create a .github/workflows/clang-format-check.yml
in your repository containing:
name: clang-format Check
on: [push, PR]
jobs:
formatting-check:
name: Formatting Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run clang-format style check for C/C++ programs.
uses: jidicula/[email protected]
with:
clang-format-version: '11'
check-path: 'src'
fallback-style: 'Mozilla' # optional
To use this action on multiple paths in parallel, create a .github/workflows/clang-format-check.yml
in your repository containing:
name: clang-format Check
on: [push, PR]
jobs:
formatting-check:
name: Formatting Check
runs-on: ubuntu-latest
strategy:
matrix:
path:
- 'src'
- 'examples'
steps:
- uses: actions/checkout@v2
- name: Run clang-format style check for C/C++ programs.
uses: jidicula/[email protected]
with:
clang-format-version: '11'
check-path: ${{ matrix.path }}
fallback-style: 'Mozilla' # optional
These public repos use this Action.