Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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: |
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: |
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: Verify test executable exists
run: |
$testExe = ".\UnitTests\out\Release-x64\UnitTests.exe"
if (Test-Path $testExe) {
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
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: test_results.xml
42 changes: 42 additions & 0 deletions BRANCH_PROTECTION_SETUP.md
Original file line number Diff line number Diff line change
@@ -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.
68 changes: 68 additions & 0 deletions LOCAL_CI_TEST.md
Original file line number Diff line number Diff line change
@@ -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.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions UnitTests/UnitTests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
<IntDir>$(ProjectDir)out-int\$(Configuration)-$(Platform)\</IntDir>
<IncludePath>$(SolutionDir);$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(ProjectDir)out\$(Configuration)-$(Platform)\</OutDir>
<IntDir>$(ProjectDir)out-int\$(Configuration)-$(Platform)\</IntDir>
<IncludePath>$(SolutionDir);$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
Expand Down
Loading