1
- name : Forward List Cross Platform Build
1
+ name : CMake CI
2
2
3
3
on :
4
4
push :
5
- branches : [ main, develop ]
6
5
pull_request :
7
- branches : [ main, develop ]
8
-
9
- permissions :
10
- contents : read
11
6
12
7
jobs :
13
- lint_format :
14
- name : Lint & Format Check
8
+ build-and-test :
15
9
runs-on : ubuntu-latest
16
- steps :
17
- - name : Checkout code
18
- uses : actions/checkout@v4
19
- with :
20
- fetch-depth : 0
21
-
22
- - name : Install development tools
23
- run : |
24
- sudo apt-get -qq update
25
- sudo apt-get -qq install -y clang-tidy clang-format cmake build-essential
26
-
27
- - name : Configure CMake for linting
28
- run : |
29
- if [ -f "CMakeLists.txt" ]; then
30
- cmake -B build -S . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Debug
31
- else
32
- echo "No CMakeLists.txt found, skipping CMake configuration"
33
- fi
34
10
35
- - name : Run clang-format check
36
- run : |
37
- echo "Checking C++ file formatting..."
38
- CPP_FILES=$(find . -name "*.cpp" -o -name "*.hpp" -o -name "*.c" -o -name "*.h" 2>/dev/null || true)
39
-
40
- if [ -n "$CPP_FILES" ]; then
41
- echo "Found C++ files:"
42
- echo "$CPP_FILES"
43
-
44
- for file in $CPP_FILES; do
45
- if [ -f "$file" ]; then
46
- echo "Checking format: $file"
47
- clang-format --dry-run --Werror "$file" || echo "Warning: $file may need formatting"
48
- fi
49
- done
50
- else
51
- echo "No C++ files found to format"
52
- fi
53
-
54
- build :
55
- name : Build on ${{ matrix.os }}
56
- runs-on : ${{ matrix.os }}
57
- needs : [lint_format]
58
-
59
- permissions :
60
- contents : read
61
- issues : write
62
- pull-requests : write
63
-
64
- strategy :
65
- fail-fast : false
66
- matrix :
67
- os : [ubuntu-latest, windows-latest, macos-latest]
68
- include :
69
- - os : ubuntu-latest
70
- name : " Linux"
71
- executable_ext : " "
72
- - os : windows-latest
73
- name : " Windows"
74
- executable_ext : " .exe"
75
- - os : macos-latest
76
- name : " macOS"
77
- executable_ext : " "
78
-
79
11
steps :
80
- - name : Checkout code
12
+ - name : Checkout
81
13
uses : actions/checkout@v4
82
14
83
- - name : Install dependencies (Ubuntu)
84
- if : matrix.os == 'ubuntu-latest'
85
- run : |
86
- sudo apt-get -qq update
87
- sudo apt-get -qq install -y cmake build-essential
88
-
89
- - name : Install dependencies (macOS)
90
- if : matrix.os == 'macos-latest'
15
+ - name : Install build tools
91
16
run : |
92
- brew install cmake
17
+ sudo apt-get update
18
+ sudo apt-get install -y cmake ninja-build g++ clang
93
19
94
- - name : Setup MSVC (Windows)
95
- if : matrix.os == 'windows-latest'
96
- uses : ilammy/msvc-dev-cmd@v1
20
+ - name : Configure (CMake)
21
+ run : cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
97
22
98
- - name : Check for CMakeLists.txt
99
- run : |
100
- if [ -f "CMakeLists.txt" ]; then
101
- echo "✅ Found CMakeLists.txt"
102
- cat CMakeLists.txt
103
- else
104
- echo "❌ No CMakeLists.txt found - creating basic one"
105
- cat > CMakeLists.txt << 'EOF'
106
- cmake_minimum_required(VERSION 3.16)
107
- project(CppTest VERSION 1.0.0 LANGUAGES CXX)
108
-
109
- set(CMAKE_CXX_STANDARD 17)
110
- set(CMAKE_CXX_STANDARD_REQUIRED ON)
111
-
112
- # Find all .cpp files
113
- file(GLOB_RECURSE SOURCES "*.cpp")
114
-
115
- if(SOURCES)
116
- list(GET SOURCES 0 MAIN_SOURCE)
117
- get_filename_component(TARGET_NAME ${MAIN_SOURCE} NAME_WE)
118
-
119
- add_executable(${TARGET_NAME} ${MAIN_SOURCE})
120
-
121
- if(WIN32)
122
- target_compile_options(${TARGET_NAME} PRIVATE /W4)
123
- else()
124
- target_compile_options(${TARGET_NAME} PRIVATE -Wall -Wextra)
125
- if(UNIX AND NOT APPLE)
126
- find_package(Threads REQUIRED)
127
- target_link_libraries(${TARGET_NAME} Threads::Threads)
128
- endif()
129
- endif()
130
-
131
- message(STATUS "Created target: ${TARGET_NAME} from ${MAIN_SOURCE}")
132
- else()
133
- message(FATAL_ERROR "No .cpp files found!")
134
- endif()
135
- EOF
136
- echo "✅ Created basic CMakeLists.txt"
137
- fi
138
- shell : bash
139
-
140
- - name : Validate project setup
141
- run : |
142
- echo "Final project validation:"
143
- echo "========================"
144
-
145
- echo "Files in current directory:"
146
- ls -la
147
-
148
- echo ""
149
- echo "CMakeLists.txt content:"
150
- if [ -f "CMakeLists.txt" ]; then
151
- cat CMakeLists.txt
152
- else
153
- echo "❌ CMakeLists.txt not found!"
154
- exit 1
155
- fi
156
-
157
- echo ""
158
- echo "Source files found:"
159
- find . -maxdepth 2 \( -name "*.cpp" -o -name "*.c" -o -name "*.hpp" -o -name "*.h" \) -type f || echo "No source files"
160
- shell : bash
23
+ - name : Build
24
+ run : cmake --build build -j
161
25
162
- - name : Configure CMake
163
- run : |
164
- echo "Configuring CMake for ${{ matrix.name }}..."
165
- cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
166
-
167
- - name : Build project
168
- run : |
169
- echo "Building project on ${{ matrix.name }}..."
170
- cmake --build build --config Release --parallel 4
171
-
172
- - name : Test executable
173
- run : |
174
- echo "Testing executable on ${{ matrix.name }}..."
175
-
176
- # Find executable files in build directory
177
- if [ "${{ matrix.os }}" = "windows-latest" ]; then
178
- EXE_FILES=$(find build -name "*.exe" -type f 2>/dev/null || true)
179
- if [ -n "$EXE_FILES" ]; then
180
- for exe in $EXE_FILES; do
181
- echo "Found executable: $exe"
182
- echo "Testing execution..."
183
- timeout 10 "$exe" || echo "Execution completed (may have timed out)"
184
- done
185
- else
186
- echo "No executable files found"
187
- echo "Contents of build directory:"
188
- ls -la build/ || dir build
189
- fi
190
- else
191
- # Linux/macOS
192
- EXE_FILES=$(find build -type f -executable 2>/dev/null || true)
193
- if [ -n "$EXE_FILES" ]; then
194
- for exe in $EXE_FILES; do
195
- # Skip CMake internal files
196
- if [[ "$exe" != *"CMake"* ]]; then
197
- echo "Found executable: $exe"
198
- echo "Testing execution..."
199
- timeout 10 "$exe" || echo "Execution completed (may have timed out)"
200
- fi
201
- done
202
- else
203
- echo "No executable files found"
204
- echo "Contents of build directory:"
205
- ls -la build/
206
- fi
207
- fi
208
- shell : bash
209
- continue-on-error : true
210
-
211
- - name : Verify build success
212
- run : |
213
- echo "Build verification for ${{ matrix.name }}:"
214
- echo "========================================="
215
-
216
- if [ -d "build" ]; then
217
- echo "✅ Build directory exists"
218
-
219
- # Count built files
220
- BUILT_FILES=$(find build -type f \( -name "*.exe" -o -name "*.a" -o -name "*.lib" -o -name "*.so" -o -name "*.dylib" \) 2>/dev/null | wc -l)
221
- echo "Built artifacts: $BUILT_FILES files"
222
-
223
- if [ $BUILT_FILES -gt 0 ]; then
224
- echo "✅ Build artifacts created successfully"
225
- echo "Build completed successfully on ${{ matrix.name }}"
226
- else
227
- echo "⚠️ No build artifacts found, but build directory exists"
228
- fi
229
- else
230
- echo "❌ Build directory not found"
231
- exit 1
232
- fi
233
- shell : bash
234
-
235
- - name : Upload build artifacts
236
- if : success()
237
- uses : actions/upload-artifact@v4
238
- with :
239
- name : cpp-build-${{ matrix.name }}
240
- path : |
241
- build/
242
- !build/**/*.o
243
- !build/**/*.obj
244
- !build/**/CMakeFiles/
245
- retention-days : 3
246
-
247
- - name : Label PR on failure
248
- if : ${{ failure() && matrix.os == 'ubuntu-latest' && github.event_name == 'pull_request' }}
249
- uses : actions/github-script@v7
250
- with :
251
- script : |
252
- github.rest.issues.addLabels({
253
- issue_number: context.issue.number,
254
- owner: context.repo.owner,
255
- repo: context.repo.repo,
256
- labels: ['build-failed']
257
- });
258
-
259
- summary :
260
- name : Build Summary
261
- runs-on : ubuntu-latest
262
- needs : [build]
263
- if : always()
264
- steps :
265
- - name : Build results summary
266
- run : |
267
- echo "Forward List Project Build Summary"
268
- echo "=================================="
269
-
270
- if [ "${{ needs.build.result }}" = "success" ]; then
271
- echo "✅ SUCCESS: All platforms built successfully!"
272
- echo ""
273
- echo "✅ Linux (Ubuntu) - PASSED"
274
- echo "✅ Windows (Latest) - PASSED"
275
- echo "✅ macOS (Latest) - PASSED"
276
- echo ""
277
- echo "🎉 Forward List project is ready for cross-platform development!"
278
- echo ""
279
- echo "📦 Project Components Verified:"
280
- echo " - ✅ Header files (header/)"
281
- echo " - ✅ Source files (src/, implementation/)"
282
- echo " - ✅ CMake configuration"
283
- echo " - ✅ Cross-platform compilation"
284
- echo ""
285
- echo "🔗 Build artifacts have been uploaded for each platform."
286
- else
287
- echo "❌ FAILED: Some builds failed"
288
- echo ""
289
- echo "Please check the individual job logs above for details."
290
- echo ""
291
- echo "Common fixes for Forward List projects:"
292
- echo "- Verify header/forward_list.hpp exists and compiles"
293
- echo "- Check src/forward_list.cpp implementation"
294
- echo "- Ensure CMakeLists.txt includes correct paths"
295
- echo "- Verify C++17 compatibility of template code"
296
- echo "- Check for missing includes or dependencies"
297
- exit 1
298
- fi- PASSED"
299
- echo ""
300
- echo "🎉 Project is ready for cross-platform development!"
301
- else
302
- echo "❌ FAILED: Some builds failed"
303
- echo ""
304
- echo "Please check the individual job logs above for details."
305
- echo ""
306
- echo "Common fixes:"
307
- echo "- Ensure CMakeLists.txt is properly configured"
308
- echo "- Check C++17 compatibility"
309
- echo "- Verify all source files compile"
310
- echo "- Check for platform-specific issues"
311
- exit 1
312
- fi
26
+ - name : Test (ctest)
27
+ run : ctest --test-dir build --output-on-failure
0 commit comments