-
Notifications
You must be signed in to change notification settings - Fork 15
102 lines (84 loc) · 3.05 KB
/
Copy pathcmake-format-check.yaml
File metadata and controls
102 lines (84 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: CMake Format Check
run-name: "${{ github.actor }} running CMake format check"
on:
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
detect-cmake-format-changes:
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
outputs:
has_changes: ${{ steps.filter.outputs.matched }}
changed_files: ${{ steps.filter.outputs.matched_files }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
path: phlex-src
- name: Detect CMake formatting changes
id: filter
uses: ./phlex-src/.github/actions/detect-relevant-changes
with:
repo-path: phlex-src
base-ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
head-ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
file-type: cmake
- name: Report detection outcome
run: |
if [ "${{ steps.filter.outputs.matched }}" != "true" ]; then
echo "::notice::No CMake-related changes detected; formatting check will be skipped."
else
echo "::group::CMake-related files"
printf '%s\n' "${{ steps.filter.outputs.matched_files }}"
echo "::endgroup::"
fi
cmake-format-check:
needs: detect-cmake-format-changes
if: ${{ needs.detect-cmake-format-changes.outputs.has_changes == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
path: phlex-src
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install cmake-format
run: pip install cmakelang
- name: Check CMake formatting
run: |
cd phlex-src
echo "Checking CMake file formatting..."
cmake_files=$(find . -type f \( -name "CMakeLists.txt" -o -name "CMakeLists.txt.in" -o -name "*.cmake" -o -name "*.cmake.in" \) ! -path "*/build/*" ! -path "*/_deps/*")
if [ -z "$cmake_files" ]; then
echo "No CMake files found to check"
exit 0
fi
format_errors=0
for file in $cmake_files; do
echo "Checking $file..."
if ! cmake-format --check "$file"; then
echo "❌ Format error in: $file"
format_errors=$((format_errors + 1))
fi
done
if [ $format_errors -gt 0 ]; then
echo ""
echo "::error::Found $format_errors file(s) with formatting issues"
echo "Run 'cmake-format -i <file>' locally or comment '@phlexbot format' on the PR to auto-fix"
exit 1
fi
echo "✓ All CMake files are properly formatted"
cmake-format-check-skipped:
needs: detect-cmake-format-changes
if: ${{ needs.detect-cmake-format-changes.outputs.has_changes != 'true' }}
runs-on: ubuntu-latest
steps:
- name: No relevant CMake changes detected
run: echo "No CMake-related changes detected; cmake-format check skipped."