GithubHelp home page GithubHelp logo

krzmbrzl / clang-format-action Goto Github PK

View Code? Open in Web Editor NEW

This project forked from plfiorini/clang-format-action

0.0 2.0 0.0 219 KB

GitHub Action for clang-format checking

License: MIT License

Dockerfile 0.89% Shell 31.23% C 16.97% C++ 42.43% Processing 8.49%

clang-format-action's Introduction

main Build and Test shell-lint
3.5.x Build and Test shell-lint

clang-format-action

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.

Versions supported

  • clang-format-9
  • clang-format-10 (n.b. use v3.5.0 of this action to access it)
  • clang-format-11
  • clang-format-12
  • clang-format-13
  • clang-format-14

Do you find this useful?

You can sponsor me here!

Inputs

  • clang-format-version [optional]: The version of clang-format that you want to run on your codebase.
    • Default: 13
    • Available versions: every version of clang-format available on Debian Sid.
  • check-path [optional]: The path to the directory in the repo that should be checked for C/C++/Protobuf 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 not src/.
  • fallback-style [optional]: The fallback style for clang-format if no .clang-format file exists in your repository.
    • Default: llvm
    • Available values: LLVM, Google, Chromium, Mozilla, WebKit and others listed in the clang-format docs for BasedOnStyle.
  • exclude-regex [optional]: A regex to exclude files or directories that should not be checked.
    • Default: ^$
    • Pattern matching is done with a real regex, not a glob expression. You can exclude multiple patterns like this: (hello|world).

This action checks all C/C++/Protobuf (including Arduino .ino and .pde) 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++/Protobuf 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
    • .ino
    • .pde
  • Protobuf files:
    • .proto

Returns:

  • SUCCESS: zero exit-code if C/C++/Protobuf files in check-path are formatted correctly
  • FAILURE: nonzero exit-code if C/C++/Protobuf files in check-path are not formatted correctly

Usage

Single Path

To use this action, create a .github/workflows/clang-format-check.yml in your repository containing:

name: clang-format Check
on: [push, pull_request]
jobs:
  formatting-check:
    name: Formatting Check
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Run clang-format style check for C/C++/Protobuf programs.
      uses: jidicula/[email protected]
      with:
        clang-format-version: '13'
        check-path: 'src'
        fallback-style: 'Mozilla' # optional

Multiple Paths

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, pull_request]
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++/Protobuf programs.
      uses: jidicula/[email protected]
      with:
        clang-format-version: '13'
        check-path: ${{ matrix.path }}
        fallback-style: 'Mozilla' # optional

Multiple Paths with Exclusion Regexes

To use this action on multiple paths in parallel with exclusions, create a .github/workflows/clang-format-check.yml in your repository containing:

name: clang-format Check
on: [push, pull_request]
jobs:
  formatting-check:
    name: Formatting Check
    runs-on: ubuntu-latest
    strategy:
      matrix:
        path:
          - check: 'src'
            exclude: '(hello|world)' # Exclude file paths containing "hello" or "world"
          - check: 'examples'
            exclude: ''              # Nothing to exclude
    steps:
    - uses: actions/checkout@v2
    - name: Run clang-format style check for C/C++/Protobuf programs.
      uses: jidicula/[email protected]
      with:
        clang-format-version: '13'
        check-path: ${{ matrix.path['check'] }}
        exclude-regex: ${{ matrix.path['exclude'] }}
        fallback-style: 'Mozilla' # optional

Who uses this?

These public repos use this Action.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.