mirror of
https://github.com/ntop/ntopng.git
synced 2026-07-09 16:00:51 +00:00
Add code formatter in the CI pipeline (#7372)
* Create formatter CI This step in the CI pipeline is responsible for enforcing the coding style to the cpp code. * Update formatter.yml * Give writing permission to the code formatter action * Add the workflow-dispatch event trigger * Add first sketch of coding style * Run build CI only after the formatter * Disable include sorting on the formatter * Fix formatter CI * Fix code formatter in pull requests * Fix code formatter CI Commit the changes made by the formatter only when pushing to a remote branch. When dealing with pull requests the CI fails if the code is not properly formatted and does not commit the changes * Remove formatter CI from PR * Enable Build CI in PR
This commit is contained in:
parent
dc8e0b4d88
commit
2ecb162dfb
3 changed files with 41 additions and 3 deletions
7
.clang-format
Normal file
7
.clang-format
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
BasedOnStyle: Google
|
||||
---
|
||||
Language: Cpp
|
||||
IndentWidth: 2
|
||||
SortIncludes: Never
|
||||
---
|
||||
9
.github/workflows/build.yml
vendored
9
.github/workflows/build.yml
vendored
|
|
@ -1,9 +1,12 @@
|
|||
name: Build
|
||||
on:
|
||||
push:
|
||||
branches: [ "dev" ]
|
||||
pull_request:
|
||||
branches: [ "dev" ]
|
||||
branches: [dev]
|
||||
workflow_run:
|
||||
workflows: [Formatter]
|
||||
types:
|
||||
- completed
|
||||
branches: [dev]
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
build:
|
||||
|
|
|
|||
28
.github/workflows/formatter.yml
vendored
Normal file
28
.github/workflows/formatter.yml
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
# This workflow uses clang-format to force the right coding style.
|
||||
name: Formatter
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "dev" ]
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
formatter:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
# Give the default GITHUB_TOKEN write permission to commit and push the changed files back to the repository.
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Run formatter
|
||||
run: find ./src ./include/ -type f \( -name '*.cpp' -o -name '*.h' \) -exec clang-format --style=file -i '{}' \;
|
||||
|
||||
# Commit the changes when pushing to a remote branch
|
||||
- name: Commit
|
||||
uses: stefanzweifel/git-auto-commit-action@v4
|
||||
with:
|
||||
commit_user_name: clang-format-bot
|
||||
commit_message: 'Automated commit of clang-format CI changes.'
|
||||
Loading…
Add table
Add a link
Reference in a new issue