From 635542b33d5f54e895f19d85789414600d9c959a Mon Sep 17 00:00:00 2001 From: Valerio Date: Fri, 31 Jan 2025 14:12:53 +0100 Subject: [PATCH 1/8] Add clang-format configuration and GitHub action for automatic formatting when a pull request is merged. Changes: new file: .clang-format new file: .github/workflows/clang-format.yml --- .clang-format | 57 ++++++++++++++++++++++++++++++ .github/workflows/clang-format.yml | 52 +++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 .clang-format create mode 100644 .github/workflows/clang-format.yml diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..11da2cf68 --- /dev/null +++ b/.clang-format @@ -0,0 +1,57 @@ +--- +Language: Cpp +BasedOnStyle: Google +IndentWidth: 4 +TabWidth: 4 +UseTab: Never +AllowShortFunctionsOnASingleLine: Empty + +NamespaceIndentation: None + +BraceWrapping: + AfterNamespace: true + AfterFunction: true + AfterControlStatement: true + AfterClass: true + SplitEmptyFunction: false + BeforeCatch: true + BeforeElse: true + BeforeLambdaBody: false + +AlignAfterOpenBracket: Align +AlignOperands: false +AccessModifierOffset: -4 + +BreakBeforeBraces: Custom + +BinPackParameters: false +BinPackArguments: false +Cpp11BracedListStyle: false + +PointerAlignment: Left + +SpacesInContainerLiterals: true +SpaceBeforeParens: Never +SpaceBeforeRangeBasedForLoopColon: false + +AllowAllParametersOfDeclarationOnNextLine: false + +CommentPragmas: '^!|^@' +SpaceAfterTemplateKeyword: false +SpacesInTemplateDeclarations: true + +ContinuationIndentWidth: 8 +ConstructorInitializerIndentWidth: 4 +BreakConstructorInitializers: AfterColon +ConstructorInitializerAllOnOneLineOrOnePerLine: false + +SpaceBeforeCtorInitializerColon: false +SpacesInAngles: true +SpacesInParentheses: true +SpacesInSquareBrackets: true +SpaceInEmptyParentheses: true +SpaceInEmptySquareBrackets: true +SpaceInEmptyBlock: true + +ColumnLimit: 140 +--- \ No newline at end of file diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml new file mode 100644 index 000000000..3973db75e --- /dev/null +++ b/.github/workflows/clang-format.yml @@ -0,0 +1,52 @@ +name: Clang-Format Check and Fix + +on: + push: + branches: + - develop + +jobs: + format-check: + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + with: + fetch-depth: 2 # Fetch enough history for PR diffing + + - name: Install Clang-Format + run: sudo apt-get install -y clang-format + + - name: Display Clang-Format Version + run: clang-format --version + + - name: Identify Changed Files in PR + run: | + echo "Changed files in PR:" + git diff --name-only --diff-filter=ACM origin/${{ github.base_ref }}...${{ github.head_ref }} | grep -E '\.(cpp|hpp|c|h)$' || echo "No matching files changed." + + - name: Run Clang-Format on Changed Files + run: | + git diff --name-only --diff-filter=ACM origin/${{ github.base_ref }}...${{ github.head_ref }} | grep -E '\.(cpp|hpp|c|h)$' | xargs -r clang-format -style=file -i + + - name: Check for Formatting Differences + id: check_diff + run: git diff --exit-code || echo "Formatting issues detected." + + - name: Auto-commit Formatting Changes + if: failure() + run: | + git config --local user.name "github-actions[bot]" + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git add . + git commit -m "Apply clang-format" + git push origin HEAD:${{ github.head_ref }} + + - name: Report Success or Failure + run: | + if [ "${{ steps.check_diff.outcome }}" == "failure" ]; then + echo "Formatting issues were detected and fixed." + else + echo "Code is properly formatted." + fi From 438cdb63cabcbd71e327c93a95089400e8612e1b Mon Sep 17 00:00:00 2001 From: Valerio Date: Sun, 2 Feb 2025 12:10:52 +0100 Subject: [PATCH 2/8] Remove include sorting. --- .clang-format | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.clang-format b/.clang-format index 11da2cf68..d918b45cb 100644 --- a/.clang-format +++ b/.clang-format @@ -6,6 +6,8 @@ TabWidth: 4 UseTab: Never AllowShortFunctionsOnASingleLine: Empty +SortIncludes: Never + NamespaceIndentation: None BraceWrapping: From 98bbf13333a307533fab604961d4efd9aba7e4c5 Mon Sep 17 00:00:00 2001 From: DominicDirkx Date: Mon, 3 Feb 2025 16:27:15 +0100 Subject: [PATCH 3/8] Test auto-format script --- src/simulation/propagation_setup/createEnvironmentUpdater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/simulation/propagation_setup/createEnvironmentUpdater.cpp b/src/simulation/propagation_setup/createEnvironmentUpdater.cpp index 0d87f7dcb..174252c36 100644 --- a/src/simulation/propagation_setup/createEnvironmentUpdater.cpp +++ b/src/simulation/propagation_setup/createEnvironmentUpdater.cpp @@ -37,7 +37,7 @@ void checkValidityOfRequiredEnvironmentUpdates( for( unsigned int i = 0; i < updateIterator->second.size( ); i++ ) { // Ignore global required updates. - if( updateIterator->second.at( i ) != "" ) + if( updateIterator->second.at( i ) != "" ) { // Check if body exists. if( bodies.count( updateIterator->second.at( i ) ) == 0 ) From 25d447c53621273f38a39a98fa82b01a537e44d4 Mon Sep 17 00:00:00 2001 From: Valerio Date: Mon, 3 Feb 2025 16:45:41 +0100 Subject: [PATCH 4/8] Fix git variables for push trigger. --- .github/workflows/clang-format.yml | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml index 3973db75e..2bf8ee382 100644 --- a/.github/workflows/clang-format.yml +++ b/.github/workflows/clang-format.yml @@ -13,7 +13,8 @@ jobs: - name: Checkout Code uses: actions/checkout@v3 with: - fetch-depth: 2 # Fetch enough history for PR diffing + fetch-depth: 2 + persist-credentials: true - name: Install Clang-Format run: sudo apt-get install -y clang-format @@ -21,18 +22,21 @@ jobs: - name: Display Clang-Format Version run: clang-format --version - - name: Identify Changed Files in PR + - name: Identify Changed Files in Push run: | - echo "Changed files in PR:" - git diff --name-only --diff-filter=ACM origin/${{ github.base_ref }}...${{ github.head_ref }} | grep -E '\.(cpp|hpp|c|h)$' || echo "No matching files changed." + echo "Changed files in push:" + git diff --name-only --diff-filter=ACM "${{ github.event.before }}" "${{ github.sha }}" | grep -E '\.(cpp|hpp|c|h)$' || echo "No matching files changed." - name: Run Clang-Format on Changed Files run: | - git diff --name-only --diff-filter=ACM origin/${{ github.base_ref }}...${{ github.head_ref }} | grep -E '\.(cpp|hpp|c|h)$' | xargs -r clang-format -style=file -i + git diff --name-only --diff-filter=ACM "${{ github.event.before }}" "${{ github.sha }}" | grep -E '\.(cpp|hpp|c|h)$' | xargs -r clang-format -style=file -i - name: Check for Formatting Differences id: check_diff - run: git diff --exit-code || echo "Formatting issues detected." + run: | + # This command will exit with a non-zero status if there are differences. + git diff --exit-code + continue-on-error: true - name: Auto-commit Formatting Changes if: failure() @@ -41,7 +45,9 @@ jobs: git config --local user.email "github-actions[bot]@users.noreply.github.com" git add . git commit -m "Apply clang-format" - git push origin HEAD:${{ github.head_ref }} + # Strip the "refs/heads/" prefix to get the branch name. + branch=${GITHUB_REF#refs/heads/} + git push origin HEAD:"$branch" - name: Report Success or Failure run: | From 5c1182fc894901d171b98ce5ae00c1fd2dd89b76 Mon Sep 17 00:00:00 2001 From: DominicDirkx Date: Mon, 3 Feb 2025 16:50:27 +0100 Subject: [PATCH 5/8] Testing formatter --- src/simulation/propagation_setup/createEnvironmentUpdater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/simulation/propagation_setup/createEnvironmentUpdater.cpp b/src/simulation/propagation_setup/createEnvironmentUpdater.cpp index 174252c36..d66e5b335 100644 --- a/src/simulation/propagation_setup/createEnvironmentUpdater.cpp +++ b/src/simulation/propagation_setup/createEnvironmentUpdater.cpp @@ -37,7 +37,7 @@ void checkValidityOfRequiredEnvironmentUpdates( for( unsigned int i = 0; i < updateIterator->second.size( ); i++ ) { // Ignore global required updates. - if( updateIterator->second.at( i ) != "" ) + if( updateIterator->second.at( i ) != "" ) { // Check if body exists. if( bodies.count( updateIterator->second.at( i ) ) == 0 ) From e8dc62f61e1299892eba7519d7598f1148ed3e98 Mon Sep 17 00:00:00 2001 From: DominicDirkx Date: Mon, 3 Feb 2025 16:52:53 +0100 Subject: [PATCH 6/8] Update .clang-format --- .clang-format | 2 -- 1 file changed, 2 deletions(-) diff --git a/.clang-format b/.clang-format index d918b45cb..1e5b3c71e 100644 --- a/.clang-format +++ b/.clang-format @@ -1,4 +1,3 @@ ---- Language: Cpp BasedOnStyle: Google IndentWidth: 4 @@ -56,4 +55,3 @@ SpaceInEmptySquareBrackets: true SpaceInEmptyBlock: true ColumnLimit: 140 ---- \ No newline at end of file From a1773dc46bb4eae53f1764297bae622f5c41e395 Mon Sep 17 00:00:00 2001 From: DominicDirkx Date: Mon, 3 Feb 2025 16:54:13 +0100 Subject: [PATCH 7/8] Update createEnvironmentUpdater.cpp --- src/simulation/propagation_setup/createEnvironmentUpdater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/simulation/propagation_setup/createEnvironmentUpdater.cpp b/src/simulation/propagation_setup/createEnvironmentUpdater.cpp index d66e5b335..c78587ba8 100644 --- a/src/simulation/propagation_setup/createEnvironmentUpdater.cpp +++ b/src/simulation/propagation_setup/createEnvironmentUpdater.cpp @@ -37,7 +37,7 @@ void checkValidityOfRequiredEnvironmentUpdates( for( unsigned int i = 0; i < updateIterator->second.size( ); i++ ) { // Ignore global required updates. - if( updateIterator->second.at( i ) != "" ) + if( updateIterator->second.at( i ) != "" ) { // Check if body exists. if( bodies.count( updateIterator->second.at( i ) ) == 0 ) From 4e1146fb82df9afeda90275c0fb857aaad778b1f Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Tue, 4 Feb 2025 00:43:54 +0000 Subject: [PATCH 8/8] =?UTF-8?q?Bump=20version:=202.14.0.dev1=20=E2=86=92?= =?UTF-8?q?=202.14.0.dev2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.cfg | 2 +- version | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 9b8902895..39d22701d 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.14.0.dev1 +current_version = 2.14.0.dev2 commit = True tag = True parse = (?P\d+)\.(?P\d+)\.(?P\d+)(\.(?P[a-z]+)(?P\d+))? diff --git a/version b/version index deef4992d..70b037a85 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.14.0.dev1 +2.14.0.dev2