Skip to content

Commit 4ef3b4f

Browse files
Out of process - CI
1 parent 1c8bae7 commit 4ef3b4f

File tree

4 files changed

+448
-0
lines changed

4 files changed

+448
-0
lines changed

.github/workflows/next-gen-ci.yml

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
name: next-gen-ci
2+
3+
on:
4+
push:
5+
branches: [ out-of-process-collection ]
6+
paths:
7+
- 'next-gen/**'
8+
pull_request:
9+
branches: [ out-of-process-collection ]
10+
paths:
11+
- 'next-gen/**'
12+
workflow_dispatch:
13+
inputs:
14+
force_run:
15+
description: 'Force run even if no next-gen changes'
16+
required: false
17+
default: 'false'
18+
19+
env:
20+
NUGET_PACKAGES: ${{ github.workspace }}/packages
21+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
22+
23+
permissions:
24+
contents: read
25+
26+
jobs:
27+
build-and-test:
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
include:
32+
- machine: windows-2022
33+
dotnet-version: "9.0.105"
34+
- machine: ubuntu-22.04
35+
dotnet-version: "9.0.105"
36+
- machine: macos-13
37+
dotnet-version: "9.0.105"
38+
- machine: ubuntu-22.04-arm
39+
dotnet-version: "9.0.105"
40+
runs-on: ${{ matrix.machine }}
41+
defaults:
42+
run:
43+
working-directory: next-gen
44+
steps:
45+
46+
- name: Checkout
47+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # tag: v4.2.2
48+
with:
49+
fetch-depth: 0 # fetching all, needed to correctly calculate version
50+
51+
- name: Setup .NET
52+
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # tag: v4.3.1
53+
with:
54+
dotnet-version: ${{ matrix.dotnet-version }}
55+
global-json-file: next-gen/global.json
56+
57+
- name: Check for NuGet packages cache
58+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # tag: v4.2.3
59+
id: nuget-cache
60+
with:
61+
key: next-gen-${{ hashFiles('next-gen/**/Directory.packages.props', 'next-gen/**/*.csproj') }}
62+
path: ${{ env.NUGET_PACKAGES }}
63+
64+
- name: Restore NuGet packages
65+
if: ${{ steps.nuget-cache.outputs.cache-hit != 'true' }}
66+
run: dotnet restore next-gen.sln
67+
68+
- name: Build solution
69+
run: dotnet build next-gen.sln --configuration Release --no-restore
70+
71+
- name: Run tests
72+
run: dotnet test next-gen.sln --configuration Release --no-build --verbosity normal --logger trx --results-directory test-results
73+
74+
- name: Upload test results
75+
if: always()
76+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # tag: v4.6.2
77+
with:
78+
name: test-results-${{ matrix.machine }}
79+
path: next-gen/test-results/
80+
81+
code-quality:
82+
runs-on: ubuntu-22.04
83+
defaults:
84+
run:
85+
working-directory: next-gen
86+
steps:
87+
88+
- name: Checkout
89+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # tag: v4.2.2
90+
with:
91+
fetch-depth: 0 # fetching all, needed to correctly calculate version
92+
93+
- name: Setup .NET
94+
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # tag: v4.3.1
95+
with:
96+
dotnet-version: "9.0.105"
97+
global-json-file: next-gen/global.json
98+
99+
- name: Check for NuGet packages cache
100+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # tag: v4.2.3
101+
id: nuget-cache
102+
with:
103+
key: next-gen-${{ hashFiles('next-gen/**/Directory.packages.props', 'next-gen/**/*.csproj') }}
104+
path: ${{ env.NUGET_PACKAGES }}
105+
106+
- name: Restore NuGet packages
107+
if: ${{ steps.nuget-cache.outputs.cache-hit != 'true' }}
108+
run: dotnet restore next-gen.sln
109+
110+
- name: Check formatting
111+
run: dotnet format next-gen.sln --verify-no-changes --verbosity diagnostic
112+
113+
- name: Build solution with warnings as errors
114+
run: dotnet build next-gen.sln --configuration Release --no-restore /warnaserror
115+
116+
security-scan:
117+
runs-on: ubuntu-22.04
118+
defaults:
119+
run:
120+
working-directory: next-gen
121+
steps:
122+
123+
- name: Checkout
124+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # tag: v4.2.2
125+
with:
126+
fetch-depth: 0 # fetching all, needed to correctly calculate version
127+
128+
- name: Setup .NET
129+
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # tag: v4.3.1
130+
with:
131+
dotnet-version: "9.0.105"
132+
global-json-file: next-gen/global.json
133+
134+
- name: Restore NuGet packages
135+
run: dotnet restore next-gen.sln
136+
137+
- name: Run security scan
138+
run: |
139+
dotnet list next-gen.sln package --vulnerable --include-transitive --format json > vulnerability-report.json || true
140+
if [ -s vulnerability-report.json ] && [ "$(cat vulnerability-report.json)" != "{}" ]; then
141+
echo "Vulnerabilities found:"
142+
cat vulnerability-report.json
143+
exit 1
144+
fi
145+
146+
- name: Upload vulnerability report
147+
if: always()
148+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # tag: v4.6.2
149+
with:
150+
name: vulnerability-report
151+
path: next-gen/vulnerability-report.json
152+
153+
summary:
154+
runs-on: ubuntu-22.04
155+
needs:
156+
- build-and-test
157+
- code-quality
158+
- security-scan
159+
if: always()
160+
steps:
161+
162+
- name: Check if all jobs passed
163+
run: |
164+
echo "Build and test result: ${{ needs.build-and-test.result }}"
165+
echo "Code quality result: ${{ needs.code-quality.result }}"
166+
echo "Security scan result: ${{ needs.security-scan.result }}"
167+
168+
if [ "${{ needs.build-and-test.result }}" != "success" ]; then
169+
echo "Build and test failed"
170+
exit 1
171+
fi
172+
173+
if [ "${{ needs.code-quality.result }}" != "success" ]; then
174+
echo "Code quality checks failed"
175+
exit 1
176+
fi
177+
178+
if [ "${{ needs.security-scan.result }}" != "success" ]; then
179+
echo "Security scan failed"
180+
exit 1
181+
fi
182+
183+
echo "All checks passed successfully!"

NEXT-GEN-CI-TESTING.md

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# Next-Gen CI Testing Guide
2+
3+
This document explains how to test the new `next-gen-ci` workflow locally before pushing changes.
4+
5+
## Overview
6+
7+
The `next-gen-ci` workflow is designed specifically for the `out-of-process-collection` branch and only runs when changes are made to files within the `next-gen/` folder.
8+
9+
## Features
10+
11+
- **Smart triggering**: Only runs on `out-of-process-collection` branch when `next-gen/**` files change
12+
- **Multi-platform testing**: Windows, Linux, macOS, and ARM64
13+
- **Comprehensive checks**: Build, test, code quality, and security scanning
14+
- **Proper isolation**: All operations scoped to `next-gen` folder
15+
- **No conflicts**: Won't interfere with main branch CI when syncing changes
16+
17+
## Local Testing with `act`
18+
19+
### Prerequisites
20+
21+
1. **Install act**:
22+
```powershell
23+
winget install nektos.act
24+
```
25+
26+
2. **Docker**: Required for running containers
27+
```powershell
28+
docker --version
29+
```
30+
31+
### Quick Validation Scripts
32+
33+
Two PowerShell scripts are provided for testing:
34+
35+
#### 1. Basic Build Validation
36+
```powershell
37+
.\validate-next-gen.ps1
38+
```
39+
This script tests the actual .NET build process in the `next-gen` folder:
40+
- Package restore
41+
- Solution build
42+
- Test execution
43+
- Code formatting checks
44+
45+
#### 2. Workflow Testing
46+
```powershell
47+
.\test-next-gen-ci.ps1
48+
```
49+
This script validates the GitHub Actions workflow:
50+
- Workflow syntax validation
51+
- Dry-run of all jobs
52+
- Confirms workflow structure
53+
54+
### Manual Testing with `act`
55+
56+
#### Test All Jobs (Dry Run)
57+
```bash
58+
# Test workflow syntax
59+
act -W .github/workflows/next-gen-ci.yml --list
60+
61+
# Test individual jobs (dry run)
62+
act -W .github/workflows/next-gen-ci.yml -j build-and-test -n
63+
act -W .github/workflows/next-gen-ci.yml -j code-quality -n
64+
act -W .github/workflows/next-gen-ci.yml -j security-scan -n
65+
act -W .github/workflows/next-gen-ci.yml -j summary -n
66+
```
67+
68+
#### Run Jobs for Real
69+
```bash
70+
# Run security scan (fastest)
71+
act -W .github/workflows/next-gen-ci.yml -j security-scan
72+
73+
# Run code quality checks
74+
act -W .github/workflows/next-gen-ci.yml -j code-quality
75+
76+
# Run full build and test (slowest, but most comprehensive)
77+
act -W .github/workflows/next-gen-ci.yml -j build-and-test -P ubuntu-22.04=catthehacker/ubuntu:act-22.04
78+
```
79+
80+
### Expected Results
81+
82+
#### ✅ Successful Validation
83+
- All projects build without errors
84+
- Tests pass (may have some warnings)
85+
- Code formatting issues are reported as warnings (can be fixed)
86+
- Security scan completes without vulnerabilities
87+
88+
#### ❌ Common Issues
89+
- **Build failures**: Check if dependencies are restored
90+
- **Test failures**: Review test output in generated artifacts
91+
- **Format issues**: Run `dotnet format next-gen.sln` to fix
92+
- **Security issues**: Review and update vulnerable packages
93+
94+
## Workflow Jobs
95+
96+
### 1. `build-and-test`
97+
- **Purpose**: Build solution and run tests on multiple platforms
98+
- **Platforms**: Windows 2022, Ubuntu 22.04, macOS 13, Ubuntu ARM64
99+
- **Artifacts**: Test results for each platform
100+
101+
### 2. `code-quality`
102+
- **Purpose**: Check code formatting and build with warnings as errors
103+
- **Platform**: Ubuntu 22.04
104+
- **Checks**: `dotnet format` and warning-free build
105+
106+
### 3. `security-scan`
107+
- **Purpose**: Scan for vulnerable NuGet packages
108+
- **Platform**: Ubuntu 22.04
109+
- **Artifacts**: Vulnerability report (if any found)
110+
111+
### 4. `summary`
112+
- **Purpose**: Aggregate results from all other jobs
113+
- **Dependency**: Runs after all other jobs complete
114+
- **Behavior**: Fails if any dependent job fails
115+
116+
## Tips for Development
117+
118+
1. **Test locally first**: Use the validation scripts before pushing
119+
2. **Fix formatting**: Run `dotnet format next-gen.sln` to resolve style issues
120+
3. **Check security**: Review any reported vulnerabilities
121+
4. **Platform-specific issues**: Use `act` to test on Linux containers if developing on Windows
122+
123+
## Integration with Main Branch
124+
125+
This workflow is designed to:
126+
- **Not conflict** with the main branch CI when syncing changes
127+
- **Only run** when `next-gen/` files are modified
128+
- **Use separate** artifact names to avoid collisions
129+
- **Provide** clear status checks for the `out-of-process-collection` branch
130+
131+
The main CI workflow remains unchanged, preventing merge conflicts during branch synchronization.

test-next-gen-ci.ps1

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env pwsh
2+
# Test script for next-gen CI workflow
3+
4+
Write-Host "Testing next-gen-ci workflow locally..." -ForegroundColor Green
5+
6+
# Check if we're in the right directory
7+
if (-not (Test-Path "next-gen")) {
8+
Write-Host "❌ Error: next-gen folder not found. Are you in the repo root?" -ForegroundColor Red
9+
exit 1
10+
}
11+
12+
# Check if required files exist
13+
$requiredFiles = @(
14+
"next-gen/global.json",
15+
"next-gen/next-gen.sln",
16+
".github/workflows/next-gen-ci.yml"
17+
)
18+
19+
foreach ($file in $requiredFiles) {
20+
if (-not (Test-Path $file)) {
21+
Write-Host "❌ Error: Required file not found: $file" -ForegroundColor Red
22+
exit 1
23+
} else {
24+
Write-Host "✅ Found: $file" -ForegroundColor Green
25+
}
26+
}
27+
28+
# Test the workflow syntax
29+
Write-Host "`n🔍 Testing workflow syntax..." -ForegroundColor Yellow
30+
try {
31+
$result = act -W .github/workflows/next-gen-ci.yml --list 2>&1
32+
if ($LASTEXITCODE -eq 0) {
33+
Write-Host "✅ Workflow syntax is valid" -ForegroundColor Green
34+
} else {
35+
Write-Host "❌ Workflow syntax error:" -ForegroundColor Red
36+
Write-Host $result
37+
exit 1
38+
}
39+
} catch {
40+
Write-Host "❌ Error running act: $($_.Exception.Message)" -ForegroundColor Red
41+
exit 1
42+
}
43+
44+
# Test dry run of each job
45+
$jobs = @("build-and-test", "code-quality", "security-scan", "summary")
46+
47+
foreach ($job in $jobs) {
48+
Write-Host "`n🧪 Testing job: $job" -ForegroundColor Yellow
49+
try {
50+
$result = act -W .github/workflows/next-gen-ci.yml -j $job -n 2>&1
51+
if ($LASTEXITCODE -eq 0) {
52+
Write-Host "✅ Job $job dry-run successful" -ForegroundColor Green
53+
} else {
54+
Write-Host "❌ Job $job dry-run failed:" -ForegroundColor Red
55+
Write-Host $result
56+
}
57+
} catch {
58+
Write-Host "❌ Error testing job $job`: $($_.Exception.Message)" -ForegroundColor Red
59+
}
60+
}
61+
62+
Write-Host "`n🎉 Testing completed!" -ForegroundColor Green
63+
Write-Host "To run a specific job for real, use:" -ForegroundColor Cyan
64+
Write-Host " act -W .github/workflows/next-gen-ci.yml -j <job-name>" -ForegroundColor Cyan
65+
Write-Host "`nAvailable jobs: build-and-test, code-quality, security-scan, summary" -ForegroundColor Cyan

0 commit comments

Comments
 (0)