From 0c643f82b2fc62c9d11b130ca5ad6d8210d25118 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 8 Sep 2025 10:54:31 +0000 Subject: [PATCH 1/5] Initial plan From 3232a01349621d10765d2412175ed797d84077e5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 8 Sep 2025 10:59:40 +0000 Subject: [PATCH 2/5] Add GitHub Actions CI workflow for automated testing Co-authored-by: Sven-vh <54216207+Sven-vh@users.noreply.github.com> --- .github/workflows/ci.yml | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ea6802a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,45 @@ +name: CI + +on: + pull_request: + branches: [ main ] + push: + branches: [ main ] + +jobs: + test: + runs-on: windows-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup MSBuild + uses: microsoft/setup-msbuild@v2 + + - name: Setup NuGet + uses: NuGet/setup-nuget@v2 + + - name: Restore NuGet packages + run: nuget restore FluentBuilderPattern.sln + + - name: Build solution + run: msbuild FluentBuilderPattern.sln /p:Configuration=Release /p:Platform=x64 /p:WarningLevel=4 /verbosity:minimal + + - name: Run unit tests + run: | + $testExe = ".\UnitTests\out\Release-x64\UnitTests.exe" + if (Test-Path $testExe) { + & $testExe --gtest_output=xml:test_results.xml + } else { + Write-Error "Test executable not found at $testExe" + exit 1 + } + shell: powershell + + - name: Upload test results + uses: actions/upload-artifact@v4 + if: always() + with: + name: test-results + path: test_results.xml \ No newline at end of file From 5eb6e34137495c1236662fad916e39f453feb0cb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 8 Sep 2025 11:01:15 +0000 Subject: [PATCH 3/5] Enhance CI workflow with better error handling and add documentation Co-authored-by: Sven-vh <54216207+Sven-vh@users.noreply.github.com> --- .github/workflows/ci.yml | 39 +++++++++++++++++++++++++++++++---- BRANCH_PROTECTION_SETUP.md | 42 ++++++++++++++++++++++++++++++++++++++ README.md | 26 +++++++++++++++++++++++ 3 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 BRANCH_PROTECTION_SETUP.md diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea6802a..ea51562 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,20 +21,51 @@ jobs: uses: NuGet/setup-nuget@v2 - name: Restore NuGet packages - run: nuget restore FluentBuilderPattern.sln + run: | + Write-Host "Restoring NuGet packages..." + nuget restore FluentBuilderPattern.sln + if ($LASTEXITCODE -ne 0) { + Write-Error "NuGet restore failed" + exit 1 + } + shell: powershell - name: Build solution - run: msbuild FluentBuilderPattern.sln /p:Configuration=Release /p:Platform=x64 /p:WarningLevel=4 /verbosity:minimal + run: | + Write-Host "Building solution..." + msbuild FluentBuilderPattern.sln /p:Configuration=Release /p:Platform=x64 /p:WarningLevel=4 /verbosity:minimal + if ($LASTEXITCODE -ne 0) { + Write-Error "Build failed" + exit 1 + } + shell: powershell - - name: Run unit tests + - name: Verify test executable exists run: | $testExe = ".\UnitTests\out\Release-x64\UnitTests.exe" if (Test-Path $testExe) { - & $testExe --gtest_output=xml:test_results.xml + Write-Host "Test executable found at: $testExe" + Write-Host "File size: $((Get-Item $testExe).Length) bytes" } else { Write-Error "Test executable not found at $testExe" + Write-Host "Contents of UnitTests\out directory:" + if (Test-Path ".\UnitTests\out") { + Get-ChildItem -Recurse ".\UnitTests\out" + } + exit 1 + } + shell: powershell + + - name: Run unit tests + run: | + $testExe = ".\UnitTests\out\Release-x64\UnitTests.exe" + Write-Host "Running tests..." + & $testExe --gtest_output=xml:test_results.xml + if ($LASTEXITCODE -ne 0) { + Write-Error "Tests failed with exit code $LASTEXITCODE" exit 1 } + Write-Host "All tests passed!" shell: powershell - name: Upload test results diff --git a/BRANCH_PROTECTION_SETUP.md b/BRANCH_PROTECTION_SETUP.md new file mode 100644 index 0000000..8e4e2d0 --- /dev/null +++ b/BRANCH_PROTECTION_SETUP.md @@ -0,0 +1,42 @@ +# Branch Protection Setup + +To ensure that all pull requests must pass tests before being merged into `main`, follow these steps: + +## Setting up Branch Protection Rules + +1. Go to your repository on GitHub +2. Navigate to **Settings** > **Branches** +3. Click **Add rule** or **Edit** if a rule already exists for `main` +4. Configure the following settings: + +### Required Settings: +- **Branch name pattern**: `main` +- ✅ **Restrict pushes that create files larger than 100MB** +- ✅ **Require a pull request before merging** + - ✅ **Require approvals**: 1 (or more as desired) + - ✅ **Dismiss stale PR approvals when new commits are pushed** +- ✅ **Require status checks to pass before merging** + - ✅ **Require branches to be up to date before merging** + - **Status checks**: Select `test` (this is the job name from the CI workflow) + +### Optional but Recommended: +- ✅ **Require conversation resolution before merging** +- ✅ **Include administrators** (applies rules to repository admins too) + +## What This Achieves + +With these settings enabled: +- No direct pushes to `main` are allowed +- All changes must go through pull requests +- The CI tests must pass before a PR can be merged +- PRs must be up-to-date with the latest `main` branch +- At least one approval is required for each PR + +## Testing the Setup + +1. Create a test branch +2. Make a small change and create a PR +3. Verify that the CI workflow runs automatically +4. Confirm that the merge button is disabled until tests pass + +The CI workflow will run on every push to a PR targeting `main`, ensuring code quality is maintained. \ No newline at end of file diff --git a/README.md b/README.md index bbf9a44..7179793 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,30 @@ ![Fluent Builder Drawing](images/Drawings.svg) # FluentBuilderPattern + +[![CI](https://github.com/Sven-vh/fluent-builder-pattern/actions/workflows/ci.yml/badge.svg)](https://github.com/Sven-vh/fluent-builder-pattern/actions/workflows/ci.yml) + C++ Scope based fluent builders pattern + +## CI/CD + +This project includes automated testing via GitHub Actions. All pull requests to the `main` branch are automatically tested to ensure code quality and functionality. + +### Running Tests Locally + +The project uses Google Test for unit testing. To run tests locally: + +1. Open the solution in Visual Studio +2. Restore NuGet packages +3. Build the solution (Release/x64 recommended) +4. Run the UnitTests project + +### GitHub Actions Workflow + +The CI workflow automatically: +- Restores NuGet packages +- Builds the entire solution +- Runs all unit tests +- Uploads test results as artifacts + +This ensures that all changes are properly tested before being merged into the main branch. From b47d8ae87318538d37f24fe6ae5b69b7976495d1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 8 Sep 2025 11:02:36 +0000 Subject: [PATCH 4/5] Add local CI testing documentation for developers Co-authored-by: Sven-vh <54216207+Sven-vh@users.noreply.github.com> --- LOCAL_CI_TEST.md | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 LOCAL_CI_TEST.md diff --git a/LOCAL_CI_TEST.md b/LOCAL_CI_TEST.md new file mode 100644 index 0000000..9152691 --- /dev/null +++ b/LOCAL_CI_TEST.md @@ -0,0 +1,68 @@ +# Local CI Test Script + +This PowerShell script simulates the GitHub Actions CI workflow for local testing. + +**Note**: This requires Windows with Visual Studio Build Tools or Visual Studio installed. + +```powershell +# Test script to simulate CI workflow locally +Write-Host "=== Local CI Test ===" + +# Check prerequisites +$nuget = Get-Command nuget -ErrorAction SilentlyContinue +$msbuild = Get-Command msbuild -ErrorAction SilentlyContinue + +if (-not $nuget) { + Write-Error "NuGet CLI not found. Please install NuGet CLI." + exit 1 +} + +if (-not $msbuild) { + Write-Error "MSBuild not found. Please install Visual Studio or Build Tools." + exit 1 +} + +try { + # Step 1: Restore packages + Write-Host "1. Restoring NuGet packages..." + nuget restore FluentBuilderPattern.sln + if ($LASTEXITCODE -ne 0) { throw "NuGet restore failed" } + + # Step 2: Build solution + Write-Host "2. Building solution..." + msbuild FluentBuilderPattern.sln /p:Configuration=Release /p:Platform=x64 /p:WarningLevel=4 /verbosity:minimal + if ($LASTEXITCODE -ne 0) { throw "Build failed" } + + # Step 3: Check if test executable exists + $testExe = ".\UnitTests\out\Release-x64\UnitTests.exe" + if (-not (Test-Path $testExe)) { + throw "Test executable not found at $testExe" + } + Write-Host "3. Test executable found: $testExe" + + # Step 4: Run tests + Write-Host "4. Running tests..." + & $testExe --gtest_output=xml:test_results_local.xml + if ($LASTEXITCODE -ne 0) { throw "Tests failed" } + + Write-Host "✅ All steps passed! Your changes should pass CI." +} +catch { + Write-Host "❌ Local CI test failed: $_" + exit 1 +} +``` + +## Usage + +1. Save this as `test-ci-locally.ps1` +2. Run in PowerShell: `.\test-ci-locally.ps1` +3. If successful, your changes should pass the GitHub Actions CI + +## Differences from GitHub Actions + +- Uses your local Visual Studio/Build Tools version instead of GitHub's +- May have different dependency versions +- Local environment variables and paths may differ + +For the most accurate test, push to a branch and create a PR to see the actual CI results. \ No newline at end of file From 7c5e3831763afe76b31ccbc16460b0e241d0cf4d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 8 Sep 2025 11:10:11 +0000 Subject: [PATCH 5/5] Fix Release build include path for scope.hpp Co-authored-by: Sven-vh <54216207+Sven-vh@users.noreply.github.com> --- UnitTests/UnitTests.vcxproj | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/UnitTests/UnitTests.vcxproj b/UnitTests/UnitTests.vcxproj index c354de7..6b072d9 100644 --- a/UnitTests/UnitTests.vcxproj +++ b/UnitTests/UnitTests.vcxproj @@ -29,6 +29,11 @@ $(ProjectDir)out-int\$(Configuration)-$(Platform)\ $(SolutionDir);$(IncludePath) + + $(ProjectDir)out\$(Configuration)-$(Platform)\ + $(ProjectDir)out-int\$(Configuration)-$(Platform)\ + $(SolutionDir);$(IncludePath) +