From b825911353f9d96ddb13ee915c6725cd801e1376 Mon Sep 17 00:00:00 2001 From: C4 Patino Date: Thu, 24 Jul 2025 21:02:05 -0500 Subject: [PATCH] feat: added c and cpp setup actions and added to format --- .github/actions/setup-c/action.yml | 11 +++++++++++ .github/actions/setup-cpp/action.yml | 11 +++++++++++ .github/workflows/format-nix.yml | 14 ++++++++++++++ .github/workflows/format.yml | 20 ++++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 .github/actions/setup-c/action.yml create mode 100644 .github/actions/setup-cpp/action.yml diff --git a/.github/actions/setup-c/action.yml b/.github/actions/setup-c/action.yml new file mode 100644 index 0000000..69c6272 --- /dev/null +++ b/.github/actions/setup-c/action.yml @@ -0,0 +1,11 @@ +name: Setup C++ Development Environment +description: Install and configure clang-format and other C++ tools + +runs: + using: composite + steps: + - name: Install clang-format + shell: bash + run: | + sudo apt-get update + sudo apt-get install -y clang-format diff --git a/.github/actions/setup-cpp/action.yml b/.github/actions/setup-cpp/action.yml new file mode 100644 index 0000000..69c6272 --- /dev/null +++ b/.github/actions/setup-cpp/action.yml @@ -0,0 +1,11 @@ +name: Setup C++ Development Environment +description: Install and configure clang-format and other C++ tools + +runs: + using: composite + steps: + - name: Install clang-format + shell: bash + run: | + sudo apt-get update + sudo apt-get install -y clang-format diff --git a/.github/workflows/format-nix.yml b/.github/workflows/format-nix.yml index 6d80953..191c4b3 100644 --- a/.github/workflows/format-nix.yml +++ b/.github/workflows/format-nix.yml @@ -66,6 +66,20 @@ jobs: "rust") (cd "$TARGET_DIR" && cargo fmt --all) ;; + "cpp") + if find "$TARGET_DIR" -type f \( -name "*.cpp" -o -name "*.hpp" \) -not -path "*/extern/*" | grep -q .; then + find "$TARGET_DIR" -type f \( -name "*.cpp" -o -name "*.hpp" \) -not -path "*/extern/*" -exec clang-format -i --style=file {} \; + else + echo "No C++ files found in $TARGET_DIR. Skipping clang-format." + fi + ;; + "c") + if find "$TARGET_DIR" -type f \( -name "*.c" -o -name "*.h" \) -not -path "*/extern/*" | grep -q .; then + find "$TARGET_DIR" -type f \( -name "*.c" -o -name "*.h" \) -not -path "*/extern/*" -exec clang-format -i --style=file {} \; + else + echo "No C files found in $TARGET_DIR. Skipping clang-format." + fi + ;; *) echo "unsupported language: ${{ inputs.language }}" exit 1 diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index c4c90d2..17b040d 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -32,6 +32,12 @@ jobs: - name: set up csharp if: inputs.language == 'csharp' uses: c4patino/actions/.github/actions/setup-csharp@main + - name: set up c + if: inputs.language == 'c' + uses: c4patino/actions/.github/actions/setup-c@main + - name: set up cpp + if: inputs.language == 'cpp' + uses: c4patino/actions/.github/actions/setup-cpp@main - name: set up go if: inputs.language == 'go' uses: c4patino/actions/.github/actions/setup-go@main @@ -94,6 +100,20 @@ jobs: "rust") (cd "$TARGET_DIR" && cargo fmt --all) ;; + "cpp") + if find "$TARGET_DIR" -type f \( -name "*.cpp" -o -name "*.hpp" \) -not -path "*/extern/*" | grep -q .; then + find "$TARGET_DIR" -type f \( -name "*.cpp" -o -name "*.hpp" \) -not -path "*/extern/*" -exec clang-format -i --style=file {} \; + else + echo "No C++ files found in $TARGET_DIR. Skipping clang-format." + fi + ;; + "c") + if find "$TARGET_DIR" -type f \( -name "*.c" -o -name "*.h" \) -not -path "*/extern/*" | grep -q .; then + find "$TARGET_DIR" -type f \( -name "*.c" -o -name "*.h" \) -not -path "*/extern/*" -exec clang-format -i --style=file {} \; + else + echo "No C files found in $TARGET_DIR. Skipping clang-format." + fi + ;; *) echo "unsupported language: ${{ inputs.language }}" exit 1