Merge pull request #9 from yusuf601/feat/before_begin #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Forward List Cross Platform Build | |
on: | |
push: | |
branches: [ main, develop ] | |
pull_request: | |
branches: [ main, develop ] | |
permissions: | |
contents: read | |
jobs: | |
lint_format: | |
name: Lint & Format Check | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install development tools | |
run: | | |
sudo apt-get -qq update | |
sudo apt-get -qq install -y clang-tidy clang-format cmake build-essential | |
- name: Configure CMake for linting | |
run: | | |
if [ -f "CMakeLists.txt" ]; then | |
cmake -B build -S . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Debug | |
else | |
echo "No CMakeLists.txt found, skipping CMake configuration" | |
fi | |
- name: Run clang-format check | |
run: | | |
echo "Checking C++ file formatting..." | |
CPP_FILES=$(find . -name "*.cpp" -o -name "*.hpp" -o -name "*.c" -o -name "*.h" 2>/dev/null || true) | |
if [ -n "$CPP_FILES" ]; then | |
echo "Found C++ files:" | |
echo "$CPP_FILES" | |
for file in $CPP_FILES; do | |
if [ -f "$file" ]; then | |
echo "Checking format: $file" | |
clang-format --dry-run --Werror "$file" || echo "Warning: $file may need formatting" | |
fi | |
done | |
else | |
echo "No C++ files found to format" | |
fi | |
build: | |
name: Build on ${{ matrix.os }} | |
runs-on: ${{ matrix.os }} | |
needs: [lint_format] | |
permissions: | |
contents: read | |
issues: write | |
pull-requests: write | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest, windows-latest, macos-latest] | |
include: | |
- os: ubuntu-latest | |
name: "Linux" | |
executable_ext: "" | |
- os: windows-latest | |
name: "Windows" | |
executable_ext: ".exe" | |
- os: macos-latest | |
name: "macOS" | |
executable_ext: "" | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Install dependencies (Ubuntu) | |
if: matrix.os == 'ubuntu-latest' | |
run: | | |
sudo apt-get -qq update | |
sudo apt-get -qq install -y cmake build-essential | |
- name: Install dependencies (macOS) | |
if: matrix.os == 'macos-latest' | |
run: | | |
brew install cmake | |
- name: Setup MSVC (Windows) | |
if: matrix.os == 'windows-latest' | |
uses: ilammy/msvc-dev-cmd@v1 | |
- name: Check for CMakeLists.txt | |
run: | | |
if [ -f "CMakeLists.txt" ]; then | |
echo "✅ Found CMakeLists.txt" | |
cat CMakeLists.txt | |
else | |
echo "❌ No CMakeLists.txt found - creating basic one" | |
cat > CMakeLists.txt << 'EOF' | |
cmake_minimum_required(VERSION 3.16) | |
project(CppTest VERSION 1.0.0 LANGUAGES CXX) | |
set(CMAKE_CXX_STANDARD 17) | |
set(CMAKE_CXX_STANDARD_REQUIRED ON) | |
# Find all .cpp files | |
file(GLOB_RECURSE SOURCES "*.cpp") | |
if(SOURCES) | |
list(GET SOURCES 0 MAIN_SOURCE) | |
get_filename_component(TARGET_NAME ${MAIN_SOURCE} NAME_WE) | |
add_executable(${TARGET_NAME} ${MAIN_SOURCE}) | |
if(WIN32) | |
target_compile_options(${TARGET_NAME} PRIVATE /W4) | |
else() | |
target_compile_options(${TARGET_NAME} PRIVATE -Wall -Wextra) | |
if(UNIX AND NOT APPLE) | |
find_package(Threads REQUIRED) | |
target_link_libraries(${TARGET_NAME} Threads::Threads) | |
endif() | |
endif() | |
message(STATUS "Created target: ${TARGET_NAME} from ${MAIN_SOURCE}") | |
else() | |
message(FATAL_ERROR "No .cpp files found!") | |
endif() | |
EOF | |
echo "✅ Created basic CMakeLists.txt" | |
fi | |
shell: bash | |
- name: Validate project setup | |
run: | | |
echo "Final project validation:" | |
echo "========================" | |
echo "Files in current directory:" | |
ls -la | |
echo "" | |
echo "CMakeLists.txt content:" | |
if [ -f "CMakeLists.txt" ]; then | |
cat CMakeLists.txt | |
else | |
echo "❌ CMakeLists.txt not found!" | |
exit 1 | |
fi | |
echo "" | |
echo "Source files found:" | |
find . -maxdepth 2 \( -name "*.cpp" -o -name "*.c" -o -name "*.hpp" -o -name "*.h" \) -type f || echo "No source files" | |
shell: bash | |
- name: Configure CMake | |
run: | | |
echo "Configuring CMake for ${{ matrix.name }}..." | |
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release | |
- name: Build project | |
run: | | |
echo "Building project on ${{ matrix.name }}..." | |
cmake --build build --config Release --parallel 4 | |
- name: Test executable | |
run: | | |
echo "Testing executable on ${{ matrix.name }}..." | |
# Find executable files in build directory | |
if [ "${{ matrix.os }}" = "windows-latest" ]; then | |
EXE_FILES=$(find build -name "*.exe" -type f 2>/dev/null || true) | |
if [ -n "$EXE_FILES" ]; then | |
for exe in $EXE_FILES; do | |
echo "Found executable: $exe" | |
echo "Testing execution..." | |
timeout 10 "$exe" || echo "Execution completed (may have timed out)" | |
done | |
else | |
echo "No executable files found" | |
echo "Contents of build directory:" | |
ls -la build/ || dir build | |
fi | |
else | |
# Linux/macOS | |
EXE_FILES=$(find build -type f -executable 2>/dev/null || true) | |
if [ -n "$EXE_FILES" ]; then | |
for exe in $EXE_FILES; do | |
# Skip CMake internal files | |
if [[ "$exe" != *"CMake"* ]]; then | |
echo "Found executable: $exe" | |
echo "Testing execution..." | |
timeout 10 "$exe" || echo "Execution completed (may have timed out)" | |
fi | |
done | |
else | |
echo "No executable files found" | |
echo "Contents of build directory:" | |
ls -la build/ | |
fi | |
fi | |
shell: bash | |
continue-on-error: true | |
- name: Verify build success | |
run: | | |
echo "Build verification for ${{ matrix.name }}:" | |
echo "=========================================" | |
if [ -d "build" ]; then | |
echo "✅ Build directory exists" | |
# Count built files | |
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) | |
echo "Built artifacts: $BUILT_FILES files" | |
if [ $BUILT_FILES -gt 0 ]; then | |
echo "✅ Build artifacts created successfully" | |
echo "Build completed successfully on ${{ matrix.name }}" | |
else | |
echo "⚠️ No build artifacts found, but build directory exists" | |
fi | |
else | |
echo "❌ Build directory not found" | |
exit 1 | |
fi | |
shell: bash | |
- name: Upload build artifacts | |
if: success() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: cpp-build-${{ matrix.name }} | |
path: | | |
build/ | |
!build/**/*.o | |
!build/**/*.obj | |
!build/**/CMakeFiles/ | |
retention-days: 3 | |
- name: Label PR on failure | |
if: ${{ failure() && matrix.os == 'ubuntu-latest' && github.event_name == 'pull_request' }} | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
github.rest.issues.addLabels({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
labels: ['build-failed'] | |
}); | |
summary: | |
name: Build Summary | |
runs-on: ubuntu-latest | |
needs: [build] | |
if: always() | |
steps: | |
- name: Build results summary | |
run: | | |
echo "Forward List Project Build Summary" | |
echo "==================================" | |
if [ "${{ needs.build.result }}" = "success" ]; then | |
echo "✅ SUCCESS: All platforms built successfully!" | |
echo "" | |
echo "✅ Linux (Ubuntu) - PASSED" | |
echo "✅ Windows (Latest) - PASSED" | |
echo "✅ macOS (Latest) - PASSED" | |
echo "" | |
echo "🎉 Forward List project is ready for cross-platform development!" | |
echo "" | |
echo "📦 Project Components Verified:" | |
echo " - ✅ Header files (header/)" | |
echo " - ✅ Source files (src/, implementation/)" | |
echo " - ✅ CMake configuration" | |
echo " - ✅ Cross-platform compilation" | |
echo "" | |
echo "🔗 Build artifacts have been uploaded for each platform." | |
else | |
echo "❌ FAILED: Some builds failed" | |
echo "" | |
echo "Please check the individual job logs above for details." | |
echo "" | |
echo "Common fixes for Forward List projects:" | |
echo "- Verify header/forward_list.hpp exists and compiles" | |
echo "- Check src/forward_list.cpp implementation" | |
echo "- Ensure CMakeLists.txt includes correct paths" | |
echo "- Verify C++17 compatibility of template code" | |
echo "- Check for missing includes or dependencies" | |
exit 1 | |
fi- PASSED" | |
echo "" | |
echo "🎉 Project is ready for cross-platform development!" | |
else | |
echo "❌ FAILED: Some builds failed" | |
echo "" | |
echo "Please check the individual job logs above for details." | |
echo "" | |
echo "Common fixes:" | |
echo "- Ensure CMakeLists.txt is properly configured" | |
echo "- Check C++17 compatibility" | |
echo "- Verify all source files compile" | |
echo "- Check for platform-specific issues" | |
exit 1 | |
fi |