Skip to content

Commit

Permalink
Merge pull request #37 from wazuh/enhancement/add-github-action-with-…
Browse files Browse the repository at this point in the history
…clang-format-check

Add github action to check that all files are formatted
  • Loading branch information
TomasTurina authored Jul 16, 2024
2 parents 3895d9d + 1bed5a6 commit 824bb1a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
10 changes: 5 additions & 5 deletions .github/actions/clang_format/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ inputs:

runs:
using: "composite"
steps:
steps:
- name: Dependencies for local execution
if: env.ACT # Only run for local execution
shell: bash
Expand All @@ -22,11 +22,11 @@ runs:
sudo apt update
# Dependencies for testing:
# - clang-format
# - clang-format
- name: Install dependencies
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: clang-format
packages: clang-format
version: 1.0

- name: Check Coding style
Expand All @@ -37,11 +37,11 @@ runs:
arguments="--dry-run "
# Retrieve all the source files for the desired module
sourceFiles=$(find ${{ inputs.path }} -type f \( -name "*.cpp" -o -name "*.hpp" \) | tr '\n' ' ')
sourceFiles=$(find ${{ inputs.path }} -type f \( -name '*.[ch]' -o -name "*.cpp" -o -name "*.hpp" \) | tr '\n' ' ')
arguments+="-i $sourceFiles "
ERRORS_FILE=${{ inputs.path }}/clang_format_errors.txt
clang-format $arguments 2> ${ERRORS_FILE}
clang-format $arguments 2>&1 | tee ${ERRORS_FILE}
# Check if there are errors
if [ -s "${ERRORS_FILE}" ]; then
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/clang-format-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Clang Format Check

on:
push:
branches:
- '**'
pull_request:
types:
- opened
- synchronize
- reopened

jobs:
clang-format:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Run Clang Format Check
uses: ./.github/actions/clang_format
with:
path: 'src/'
id: 'wazuh-agent'
2 changes: 2 additions & 0 deletions src/common/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DisableFormat: true
SortIncludes: Never
2 changes: 2 additions & 0 deletions src/modules/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DisableFormat: true
SortIncludes: Never

0 comments on commit 824bb1a

Please sign in to comment.