From d91f1ba73b938d1249516094d92bf6d0743c2b3a Mon Sep 17 00:00:00 2001 From: chrehall68 Date: Wed, 24 May 2023 18:19:45 -0700 Subject: [PATCH 1/8] add clangformat workflow and file --- .clang-format | 21 ++++++++++++++++++ .github/workflows/clangformat.yml | 37 +++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 .clang-format create mode 100644 .github/workflows/clangformat.yml diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..7ad600db --- /dev/null +++ b/.clang-format @@ -0,0 +1,21 @@ +# Setup +Language: Cpp +BasedOnStyle: LLVM +IndentWidth: 4 +TabWidth: 4 +UseTab: Never +ColumnLimit: 80 + +# MultiLine / Packing configuration +PackConstructorInitializers: NextLine +BinPackArguments: false +BinPackParameters: false +BreakBeforeBinaryOperators: None +AllowShortIfStatementsOnASingleLine: true + +# Braces and wrapping styles +BreakBeforeBraces: Custom +BraceWrapping: + AfterControlStatement: MultiLine + BeforeElse: true + BeforeCatch: true diff --git a/.github/workflows/clangformat.yml b/.github/workflows/clangformat.yml new file mode 100644 index 00000000..32f9a031 --- /dev/null +++ b/.github/workflows/clangformat.yml @@ -0,0 +1,37 @@ +# ClangFormat +# Author: Eliot Hall +# This program formats all cpp files in the repository +name: ClangFormat + +on: + pull_request: + branches: ["master"] + push: + branches: ["master"] + +jobs: + format: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Format .cpp and .hpp files + run: + clang-format ${{github.workspace}}/src/*.cpp ${{github.workspace}}/include/botui/*.h -style=file:${{github.workspace}}/.clang-format -i + - name: Setup git config + run: | + git config user.name "Clang Formatter Bot" + git config user.email "" + - name: Push to GitHub + run: | + echo ${{github.head_ref}} + echo ${{github.base_ref}} + echo ${{github.action_ref}} + echo ${{github.ref}} + echo ${{github.ref_name}} + git commit -a -m "AutoFormat with clang-format" + git push origin HEAD:${{github.head_ref}} + \ No newline at end of file From ce697e7f89758f0debab97a30ab603bcdb24ea54 Mon Sep 17 00:00:00 2001 From: chrehall68 Date: Wed, 24 May 2023 18:35:11 -0700 Subject: [PATCH 2/8] get all h* and c* and only run on pr --- .github/workflows/clangformat.yml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/clangformat.yml b/.github/workflows/clangformat.yml index 32f9a031..0c80e2d8 100644 --- a/.github/workflows/clangformat.yml +++ b/.github/workflows/clangformat.yml @@ -6,8 +6,6 @@ name: ClangFormat on: pull_request: branches: ["master"] - push: - branches: ["master"] jobs: format: @@ -20,18 +18,15 @@ jobs: ref: ${{ github.event.pull_request.head.sha }} - name: Format .cpp and .hpp files run: - clang-format ${{github.workspace}}/src/*.cpp ${{github.workspace}}/include/botui/*.h -style=file:${{github.workspace}}/.clang-format -i + clang-format -style=file:${{github.workspace}}/.clang-format -i \ + $(find ${{github.workspace}} -name "*.h*") \ + $(find ${{github.workspace}} -name "*.c*") - name: Setup git config run: | git config user.name "Clang Formatter Bot" git config user.email "" - name: Push to GitHub run: | - echo ${{github.head_ref}} - echo ${{github.base_ref}} - echo ${{github.action_ref}} - echo ${{github.ref}} - echo ${{github.ref_name}} git commit -a -m "AutoFormat with clang-format" git push origin HEAD:${{github.head_ref}} \ No newline at end of file From 264584f6cbf9fe3908d17749e39dc9636e0445f3 Mon Sep 17 00:00:00 2001 From: chrehall68 Date: Wed, 24 May 2023 18:40:45 -0700 Subject: [PATCH 3/8] don't error if no work to do --- .github/workflows/clangformat.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/clangformat.yml b/.github/workflows/clangformat.yml index 0c80e2d8..0164dff5 100644 --- a/.github/workflows/clangformat.yml +++ b/.github/workflows/clangformat.yml @@ -6,6 +6,8 @@ name: ClangFormat on: pull_request: branches: ["master"] + push: + branches: ["master"] jobs: format: @@ -25,8 +27,9 @@ jobs: run: | git config user.name "Clang Formatter Bot" git config user.email "" - - name: Push to GitHub + - name: Push to GitHub run: | - git commit -a -m "AutoFormat with clang-format" + git add -A + git diff --quiet HEAD || git commit -m "AutoFormat with clang-format" git push origin HEAD:${{github.head_ref}} \ No newline at end of file From 3b0c9663496ddf334ac4abfb6586413eca9fd87c Mon Sep 17 00:00:00 2001 From: chrehall68 Date: Wed, 24 May 2023 18:42:59 -0700 Subject: [PATCH 4/8] don't use backslashes --- .github/workflows/clangformat.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/clangformat.yml b/.github/workflows/clangformat.yml index 0164dff5..b3604e7d 100644 --- a/.github/workflows/clangformat.yml +++ b/.github/workflows/clangformat.yml @@ -20,8 +20,8 @@ jobs: ref: ${{ github.event.pull_request.head.sha }} - name: Format .cpp and .hpp files run: - clang-format -style=file:${{github.workspace}}/.clang-format -i \ - $(find ${{github.workspace}} -name "*.h*") \ + clang-format -style=file:${{github.workspace}}/.clang-format -i + $(find ${{github.workspace}} -name "*.h*") $(find ${{github.workspace}} -name "*.c*") - name: Setup git config run: | From 3eeab10110e3ae6b126b79188c6459eb64a790c2 Mon Sep 17 00:00:00 2001 From: chrehall68 Date: Wed, 24 May 2023 18:53:46 -0700 Subject: [PATCH 5/8] put command on same line --- .github/workflows/clangformat.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/clangformat.yml b/.github/workflows/clangformat.yml index b3604e7d..13aaa465 100644 --- a/.github/workflows/clangformat.yml +++ b/.github/workflows/clangformat.yml @@ -20,9 +20,7 @@ jobs: ref: ${{ github.event.pull_request.head.sha }} - name: Format .cpp and .hpp files run: - clang-format -style=file:${{github.workspace}}/.clang-format -i - $(find ${{github.workspace}} -name "*.h*") - $(find ${{github.workspace}} -name "*.c*") + clang-format -style=file:${{github.workspace}}/.clang-format -i $(find ${{github.workspace}} -name "*.h*") $(find ${{github.workspace}} -name "*.c*") - name: Setup git config run: | git config user.name "Clang Formatter Bot" From b5a72bd45965bc6284120b1be2bbf1e8e2a24d02 Mon Sep 17 00:00:00 2001 From: chrehall68 Date: Wed, 24 May 2023 18:57:00 -0700 Subject: [PATCH 6/8] fix format error --- .github/workflows/clangformat.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/clangformat.yml b/.github/workflows/clangformat.yml index 13aaa465..787ee493 100644 --- a/.github/workflows/clangformat.yml +++ b/.github/workflows/clangformat.yml @@ -20,7 +20,11 @@ jobs: ref: ${{ github.event.pull_request.head.sha }} - name: Format .cpp and .hpp files run: - clang-format -style=file:${{github.workspace}}/.clang-format -i $(find ${{github.workspace}} -name "*.h*") $(find ${{github.workspace}} -name "*.c*") + # don't include .c* since that would format .clang-format + clang-format -style=file:${{github.workspace}}/.clang-format -i + $(find ${{github.workspace}} -name "*.h*") + $(find ${{github.workspace}} -name "*.c") + $(find ${{github.workspace}} -name "*.cpp") - name: Setup git config run: | git config user.name "Clang Formatter Bot" From 1a11eb877c33b8dcec516a55cba6a835d4d671c7 Mon Sep 17 00:00:00 2001 From: chrehall68 Date: Wed, 24 May 2023 18:59:49 -0700 Subject: [PATCH 7/8] allow formatting to run on master --- .github/workflows/clangformat.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/clangformat.yml b/.github/workflows/clangformat.yml index 787ee493..8863acfe 100644 --- a/.github/workflows/clangformat.yml +++ b/.github/workflows/clangformat.yml @@ -33,5 +33,5 @@ jobs: run: | git add -A git diff --quiet HEAD || git commit -m "AutoFormat with clang-format" - git push origin HEAD:${{github.head_ref}} + git push origin HEAD:$(${{github.head_ref}} || ${{github.base_ref}}) \ No newline at end of file From 529d18e759b99c7e0f81be36c1a91e5fe0148178 Mon Sep 17 00:00:00 2001 From: chrehall68 Date: Wed, 24 May 2023 19:01:06 -0700 Subject: [PATCH 8/8] only run on pr's --- .github/workflows/clangformat.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/clangformat.yml b/.github/workflows/clangformat.yml index 8863acfe..a74c40ed 100644 --- a/.github/workflows/clangformat.yml +++ b/.github/workflows/clangformat.yml @@ -5,8 +5,6 @@ name: ClangFormat on: pull_request: - branches: ["master"] - push: branches: ["master"] jobs: @@ -33,5 +31,5 @@ jobs: run: | git add -A git diff --quiet HEAD || git commit -m "AutoFormat with clang-format" - git push origin HEAD:$(${{github.head_ref}} || ${{github.base_ref}}) + git push origin HEAD:${{github.head_ref}} \ No newline at end of file