Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clang-format to autoformate C/C++ code #125

Merged
merged 14 commits into from
May 28, 2024
43 changes: 43 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
BasedOnStyle: Google
AlignAfterOpenBracket: 'AlwaysBreak'
AllowAllConstructorInitializersOnNextLine: 'false'
AllowAllParametersOfDeclarationOnNextLine: 'false'
AlignConsecutiveMacros: 'true'
AllowShortCaseLabelsOnASingleLine: 'true'
AllowShortFunctionsOnASingleLine: 'None'
AllowShortIfStatementsOnASingleLine: 'Never'
AllowShortLoopsOnASingleLine: 'false'
BreakBeforeBraces: Allman
BinPackArguments: 'false'
BinPackParameters: 'false'
Cpp11BracedListStyle: 'false'
ColumnLimit: 125
IndentWidth: 2
IndentPPDirectives: BeforeHash
NamespaceIndentation: All
PackConstructorInitializers: 'Never'
SpaceAfterTemplateKeyword: 'false'
SpaceBeforeCtorInitializerColon: 'true'
SpaceBeforeInheritanceColon: 'true'
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: 'true'
SpaceInEmptyBlock: true
Standard: 'Latest'
IncludeBlocks: Regroup
IncludeCategories:
# MUSICA project headers
- Regex: '<(musica)\/'
Priority: 2
# MICM, TUV-X headers
- Regex: '<(micm|tuvx)[[:alnum:].\Q/-_\E]+>'
Priority: 3
# External libraries headers
- Regex: '<([[:alnum:].\Q/-_\E]+)\/'
Priority: 4
# System headers
- Regex: '<[[:alnum:].\Q/-_\E]+>'
Priority: 5
# Main, local, private headers
- Regex: '".*'
Priority: 1
53 changes: 53 additions & 0 deletions .github/workflows/clang_format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Clang-Format

on:
push:
branches:
- main

jobs:
format:
name: Run Clang-Format
runs-on: ubuntu-latest

steps:
- name: Install Clang-Format
run: sudo apt-get update && sudo apt-get install clang-format && clang-format --version

- name: Check out code, run clang format, push changes
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Format code
run: |
find include -type f \( -name '*.hpp' -or -name '*.h' \) -exec clang-format -i --style=file --verbose {} +
find src -type f \( -name '*.cpp' -or -name '*.c' \) -exec clang-format -i --style=file --verbose {} +
- name: Check for changes
id: check-changes
run: git diff --exit-code
continue-on-error: true

- name: Commit and push changes
# a failue of this step means changes were detected
if: steps.check-changes.outcome != 'success'
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
git commit -am "Auto-format code using Clang-Format" || echo "No changes to commit"
- name: Push changes to main-formatting branch
if: steps.check-changes.outcome != 'success'
run: git push origin HEAD:main-formatting

- name: Create Pull Request
if: steps.check-changes.outcome != 'success'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Auto-format code using Clang-Format"
title: "Auto-format code changes"
body: "This is an automated pull request to apply code formatting using Clang-Format."
branch: "main-formatting"
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- Dockerfile.python
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: recursive

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/fetch_content_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- Dockerfile.fortran-nvhpc
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: recursive

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gh_pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
CC: gcc-${{ matrix.gcc-version }}
FC: gfortran-${{ matrix.gcc-version }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
lfs: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
CXX: ${{ matrix.compiler.cpp }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
- run: pip install -r python/requirements.txt --user
Expand All @@ -54,7 +54,7 @@ jobs:
FC: gfortran-${{ matrix.gcc_version }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install dependencies
run: brew install netcdf netcdf-fortran
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
CXX: ${{ matrix.compiler.cpp }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install dependencies
run: |
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
FC: gfortran-${{ matrix.gcc_version }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install dependencies
run: |
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
architecture: [x64]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up MinGW
uses: egor-tensin/setup-mingw@v2
with:
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
architecture: [Win32, x64]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
Expand All @@ -75,7 +75,7 @@ jobs:
architecture: [Win32, x64]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
Expand All @@ -102,7 +102,7 @@ jobs:
version: [11, 12, 13, 14, 15]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install Clang
run: curl -fsSL -o LLVM${{ matrix.version }}.exe https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ matrix.version }}.0.0/LLVM-${{ matrix.version }}.0.0-win64.exe ; 7z x LLVM${{ matrix.version }}.exe -y -o"C:/Program Files/LLVM"
Expand All @@ -126,7 +126,7 @@ jobs:
architecture: [Win32, x64]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
Expand Down
2 changes: 1 addition & 1 deletion cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ endif()
if (MUSICA_ENABLE_MICM AND MUSICA_BUILD_C_CXX_INTERFACE)

set_git_default(MICM_GIT_REPOSITORY https://github.com/NCAR/micm.git)
set_git_default(MICM_GIT_TAG 2a5cd4e11a6973974f3c584dfa9841d70e0a42d5)
set_git_default(MICM_GIT_TAG 5afd404)

FetchContent_Declare(micm
GIT_REPOSITORY ${MICM_GIT_REPOSITORY}
Expand Down
18 changes: 9 additions & 9 deletions include/musica/component_versions.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/**
* This file contains the version information for the different project modules
* Copyright (C) 2023-2024 National Center for Atmospheric Research,
*
* SPDX-License-Identifier: Apache-2.0* creating solvers, and solving the model.
/* Copyright (C) 2023-2024 National Center for Atmospheric Research
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once

#ifdef __cplusplus
namespace musica {
extern "C" {
namespace musica
{
extern "C"
{
#endif

char* getAllComponentVersions();
char* getAllComponentVersions();

#ifdef __cplusplus
}
}
}
#endif
Loading
Loading