CMAKE - Add cmake-format
Change-Id: I4036859491934ed26303530d0dc1afb4f1b0d0cd Signed-off-by: Galantsev, Dmitrii <dmitrii.galantsev@amd.com>
This commit is contained in:
committato da
Galantsev, Dmitrii
parent
02c0786a2c
commit
f89beb90f5
@@ -0,0 +1,97 @@
|
||||
# caution: most of this file was written using Claude 3.7 Sonnet
|
||||
name: CMake Format Check
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ amd-staging ]
|
||||
paths:
|
||||
- '**/*.cmake'
|
||||
- '**/CMakeLists.txt'
|
||||
- '**/*.cmake.in'
|
||||
pull_request:
|
||||
branches: [ amd-staging ]
|
||||
paths:
|
||||
- '**/*.cmake'
|
||||
- '**/CMakeLists.txt'
|
||||
- '**/*.cmake.in'
|
||||
workflow_dispatch: # Allows manual triggering
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
jobs:
|
||||
check-cmake-format:
|
||||
name: Check CMake files formatting
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # Full history for better diff context
|
||||
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.10'
|
||||
cache: 'pip'
|
||||
|
||||
- name: Install cmake-format
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install cmake-format==0.6.13
|
||||
|
||||
- name: Check CMake formatting
|
||||
id: check-format
|
||||
run: |
|
||||
echo "::group::Finding CMake files"
|
||||
FILES=$(find . -type f \( -name "CMakeLists.txt" -o -name "*.cmake" -o -name "*.cmake.in" \) \
|
||||
-not -path "*/\.*" \
|
||||
-not -path "*/build/*")
|
||||
echo "Found $(echo "$FILES" | wc -l) CMake files to check"
|
||||
echo "::endgroup::"
|
||||
|
||||
# Create an array to store failed files
|
||||
declare -a failed_files
|
||||
|
||||
# Check if files are formatted correctly
|
||||
for file in $FILES; do
|
||||
echo "Checking $file..."
|
||||
if ! cmake-format --check "$file"; then
|
||||
failed_files+=("$file")
|
||||
echo "::error file=$file::File needs formatting"
|
||||
fi
|
||||
done
|
||||
|
||||
# Generate report and exit with error if any files failed
|
||||
if [ ${#failed_files[@]} -ne 0 ]; then
|
||||
echo "Failed files: ${failed_files[*]}"
|
||||
echo "FAILED_FILES=${failed_files[*]}" >> $GITHUB_ENV
|
||||
exit 1
|
||||
else
|
||||
echo "All CMake files are formatted correctly!"
|
||||
fi
|
||||
|
||||
- name: Generate diff for failed files
|
||||
if: failure() && env.FAILED_FILES != ''
|
||||
run: |
|
||||
echo "## CMake Format Check Failed" >> $GITHUB_STEP_SUMMARY
|
||||
echo "The following files need formatting:" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
for file in ${FAILED_FILES}; do
|
||||
echo "### $file" >> $GITHUB_STEP_SUMMARY
|
||||
done
|
||||
|
||||
cat << 'EOF' >> $GITHUB_STEP_SUMMARY
|
||||
### How to fix
|
||||
Run this command locally to fix formatting issues:
|
||||
```bash
|
||||
# Install cmake-format
|
||||
pip install cmake-format==0.6.13
|
||||
|
||||
# Format files
|
||||
cmake-format -i <file>
|
||||
```
|
||||
EOF
|
||||
Fai riferimento in un nuovo problema
Block a user