| 1 |
# caution: most of this file was written using Claude 3.7 Sonnet |
| 2 |
name: CMake Format Check |
| 3 |
|
| 4 |
on: |
| 5 |
push: |
| 6 |
branches: [ amd-staging ] |
| 7 |
paths: |
| 8 |
- '**/*.cmake' |
| 9 |
- '**/CMakeLists.txt' |
| 10 |
- '**/*.cmake.in' |
| 11 |
pull_request: |
| 12 |
branches: [ amd-staging ] |
| 13 |
paths: |
| 14 |
- '**/*.cmake' |
| 15 |
- '**/CMakeLists.txt' |
| 16 |
- '**/*.cmake.in' |
| 17 |
workflow_dispatch: # Allows manual triggering |
| 18 |
|
| 19 |
defaults: |
| 20 |
run: |
| 21 |
shell: bash |
| 22 |
|
| 23 |
jobs: |
| 24 |
check-cmake-format: |
| 25 |
name: Check CMake files formatting |
| 26 |
runs-on: self-hosted |
| 27 |
container: catthehacker/ubuntu:act-latest |
| 28 |
|
| 29 |
steps: |
| 30 |
- name: Checkout repository |
| 31 |
uses: actions/checkout@v4 |
| 32 |
with: |
| 33 |
fetch-depth: 0 # Full history for better diff context |
| 34 |
|
| 35 |
- name: Setup Python |
| 36 |
uses: actions/setup-python@v5 |
| 37 |
with: |
| 38 |
python-version: '3.10' |
| 39 |
cache: 'pip' |
| 40 |
|
| 41 |
- name: Install cmake-format |
| 42 |
run: | |
| 43 |
python -m pip install --upgrade pip |
| 44 |
pip install cmake-format==0.6.13 |
| 45 |
|
| 46 |
- name: Check CMake formatting |
| 47 |
id: check-format |
| 48 |
run: | |
| 49 |
echo "::group::Finding CMake files" |
| 50 |
FILES=$(find . -type f \( -name "CMakeLists.txt" -o -name "*.cmake" -o -name "*.cmake.in" \) \ |
| 51 |
-not -path "*/esmi_ib_library/*" \ |
| 52 |
-not -path "*/\.*" \ |
| 53 |
-not -path "*/build/*") |
| 54 |
echo "Found $(echo "$FILES" | wc -l) CMake files to check" |
| 55 |
echo "::endgroup::" |
| 56 |
|
| 57 |
# Create an array to store failed files |
| 58 |
declare -a failed_files |
| 59 |
|
| 60 |
# Check if files are formatted correctly |
| 61 |
for file in $FILES; do |
| 62 |
echo "Checking $file..." |
| 63 |
if ! cmake-format --check "$file"; then |
| 64 |
failed_files+=("$file") |
| 65 |
echo "::error file=$file::File needs formatting" |
| 66 |
fi |
| 67 |
done |
| 68 |
|
| 69 |
# Generate report and exit with error if any files failed |
| 70 |
if [ ${#failed_files[@]} -ne 0 ]; then |
| 71 |
echo "Failed files: ${failed_files[*]}" |
| 72 |
echo "FAILED_FILES=${failed_files[*]}" >> $GITHUB_ENV |
| 73 |
exit 1 |
| 74 |
else |
| 75 |
echo "All CMake files are formatted correctly!" |
| 76 |
fi |
| 77 |
|
| 78 |
- name: Generate diff for failed files |
| 79 |
if: failure() && env.FAILED_FILES != '' |
| 80 |
run: | |
| 81 |
echo "## CMake Format Check Failed" >> $GITHUB_STEP_SUMMARY |
| 82 |
echo "The following files need formatting:" >> $GITHUB_STEP_SUMMARY |
| 83 |
echo "" >> $GITHUB_STEP_SUMMARY |
| 84 |
|
| 85 |
for file in ${FAILED_FILES}; do |
| 86 |
echo "### $file" >> $GITHUB_STEP_SUMMARY |
| 87 |
done |
| 88 |
|
| 89 |
cat << 'EOF' >> $GITHUB_STEP_SUMMARY |
| 90 |
### How to fix |
| 91 |
Run this command locally to fix formatting issues: |
| 92 |
```bash |
| 93 |
# Install cmake-format |
| 94 |
pip install cmake-format==0.6.13 |
| 95 |
|
| 96 |
# Format files |
| 97 |
cmake-format -i <file> |
| 98 |
``` |
| 99 |
EOF |