Skip to content
Open
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
189 changes: 189 additions & 0 deletions .github/workflows/next-gen-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
name: next-gen-ci

on:
push:
branches: [ out-of-process-collection ]
paths:
- 'next-gen/**'
pull_request:
branches: [ out-of-process-collection ]
paths:
- 'next-gen/**'
workflow_dispatch:
inputs:
force_run:
description: 'Force run even if no next-gen changes'
required: false
default: 'false'

env:
NUGET_PACKAGES: ${{ github.workspace }}/packages
DOTNET_CLI_TELEMETRY_OPTOUT: 1

permissions:
contents: read

jobs:
build-and-test:
strategy:
fail-fast: false
matrix:
include:
- machine: windows-2022
dotnet-version: "9.0.303"
- machine: ubuntu-22.04
dotnet-version: "9.0.303"
- machine: macos-13
dotnet-version: "9.0.303"
- machine: ubuntu-22.04-arm
dotnet-version: "9.0.303"
runs-on: ${{ matrix.machine }}
defaults:
run:
working-directory: next-gen
steps:

- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # tag: v4.2.2
with:
fetch-depth: 0 # fetching all, needed to correctly calculate version

- name: Setup .NET
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # tag: v4.3.1
with:
dotnet-version: ${{ matrix.dotnet-version }}
global-json-file: next-gen/global.json

- name: Check for NuGet packages cache
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # tag: v4.2.3
id: nuget-cache
with:
key: next-gen-${{ hashFiles('next-gen/**/Directory.packages.props', 'next-gen/**/*.csproj') }}
path: ${{ env.NUGET_PACKAGES }}

- name: Restore NuGet packages
run: dotnet restore next-gen.sln

- name: Build solution
run: dotnet build next-gen.sln --configuration Release --no-restore

- name: Run tests
run: dotnet test next-gen.sln --configuration Release --no-build --verbosity normal --logger trx --results-directory test-results

- name: Upload test results
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # tag: v4.6.2
with:
name: test-results-${{ matrix.machine }}
path: next-gen/test-results/

code-quality:
runs-on: ubuntu-22.04
defaults:
run:
working-directory: next-gen
steps:

- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # tag: v4.2.2
with:
fetch-depth: 0 # fetching all, needed to correctly calculate version

- name: Setup .NET
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # tag: v4.3.1
with:
dotnet-version: "9.0.303"
global-json-file: next-gen/global.json

- name: Check for NuGet packages cache
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # tag: v4.2.3
id: nuget-cache
with:
key: next-gen-${{ hashFiles('next-gen/**/Directory.packages.props', 'next-gen/**/*.csproj') }}
path: ${{ env.NUGET_PACKAGES }}

- name: Restore NuGet packages
run: dotnet restore next-gen.sln

- name: Check formatting
run: dotnet format next-gen.sln --verify-no-changes --verbosity diagnostic

- name: Build solution with warnings as errors
run: dotnet build next-gen.sln --configuration Release --no-restore /warnaserror

security-scan:
runs-on: ubuntu-22.04
defaults:
run:
working-directory: next-gen
steps:

- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # tag: v4.2.2
with:
fetch-depth: 0 # fetching all, needed to correctly calculate version

- name: Setup .NET
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # tag: v4.3.1
with:
dotnet-version: "9.0.303"
global-json-file: next-gen/global.json

- name: Restore NuGet packages
run: dotnet restore next-gen.sln

- name: Run security scan
run: |
# Run the vulnerability scan and capture output
dotnet list next-gen.sln package --vulnerable --include-transitive --format json > vulnerability-report.json || true

echo "Generated vulnerability report:"
cat vulnerability-report.json

# Check if there are actual vulnerabilities by looking for the vulnerabilities array with content
# The JSON structure includes "vulnerabilities": [...] only when actual vulnerabilities exist
if grep -q '"vulnerabilities":\s*\[[^]]\+\]' vulnerability-report.json; then
echo "Security vulnerabilities detected!"
exit 1
else
echo "No security vulnerabilities found."
fi

- name: Upload vulnerability report
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # tag: v4.6.2
with:
name: vulnerability-report
path: next-gen/vulnerability-report.json

summary:
runs-on: ubuntu-22.04
needs:
- build-and-test
- code-quality
- security-scan
if: always()
steps:

- name: Check if all jobs passed
run: |
echo "Build and test result: ${{ needs.build-and-test.result }}"
echo "Code quality result: ${{ needs.code-quality.result }}"
echo "Security scan result: ${{ needs.security-scan.result }}"

if [ "${{ needs.build-and-test.result }}" != "success" ]; then
echo "Build and test failed"
exit 1
fi

if [ "${{ needs.code-quality.result }}" != "success" ]; then
echo "Code quality checks failed"
exit 1
fi

if [ "${{ needs.security-scan.result }}" != "success" ]; then
echo "Security scan failed"
exit 1
fi

echo "All checks passed successfully!"
2 changes: 1 addition & 1 deletion next-gen/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<IsTestProject>$(MSBuildProjectName.Contains('.Test'))</IsTestProject>

<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>$(RepoRoot)\KeyPair.snk</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)keypair.snk</AssemblyOriginatorKeyFile>

<Authors>OpenTelemetry Authors</Authors>
<Copyright>Copyright © $([System.DateTime]::Now.ToString(yyyy))</Copyright>
Expand Down
132 changes: 132 additions & 0 deletions next-gen/NEXT-GEN-CI-TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Next-Gen CI Testing Guide

This document explains how to test the new `next-gen-ci` workflow locally before pushing changes.

## Overview

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.

## Features

- **Smart triggering**: Only runs on `out-of-process-collection` branch when `next-gen/**` files change
- **Multi-platform testing**: Windows, Linux, macOS, and ARM64
- **Comprehensive checks**: Build, test, code quality, and security scanning
- **Proper isolation**: All operations scoped to `next-gen` folder
- **No conflicts**: Won't interfere with main branch CI when syncing changes
- **Standard SDK versions**: Uses repository-standard .NET 9.0.303

## Local Testing with `act`

### Prerequisites

1. **Install act**:
```powershell
winget install nektos.act
```

2. **Docker**: Required for running containers
```powershell
docker --version
```

### Quick Validation Scripts

Two PowerShell scripts are provided for testing:

#### 1. Basic Build Validation
```powershell
.\validate-next-gen.ps1
```
This script tests the actual .NET build process in the `next-gen` folder:
- Package restore
- Solution build
- Test execution
- Code formatting checks

#### 2. Workflow Testing
```powershell
.\test-next-gen-ci.ps1
```
This script validates the GitHub Actions workflow:
- Workflow syntax validation
- Dry-run of all jobs
- Confirms workflow structure

### Manual Testing with `act`

#### Test All Jobs (Dry Run)
```bash
# Test workflow syntax
act -W .github/workflows/next-gen-ci.yml --list

# Test individual jobs (dry run)
act -W .github/workflows/next-gen-ci.yml -j build-and-test -n
act -W .github/workflows/next-gen-ci.yml -j code-quality -n
act -W .github/workflows/next-gen-ci.yml -j security-scan -n
act -W .github/workflows/next-gen-ci.yml -j summary -n
```

#### Run Jobs for Real
```bash
# Run security scan (fastest)
act -W .github/workflows/next-gen-ci.yml -j security-scan

# Run code quality checks
act -W .github/workflows/next-gen-ci.yml -j code-quality

# Run full build and test (slowest, but most comprehensive)
act -W .github/workflows/next-gen-ci.yml -j build-and-test -P ubuntu-22.04=catthehacker/ubuntu:act-22.04
```

### Expected Results

#### ✅ Successful Validation
- All projects build without errors
- Tests pass (may have some warnings)
- Code formatting issues are reported as warnings (can be fixed)
- Security scan completes without vulnerabilities

#### ❌ Common Issues
- **Build failures**: Check if dependencies are restored
- **Test failures**: Review test output in generated artifacts
- **Format issues**: Run `dotnet format next-gen.sln` to fix
- **Security issues**: Review and update vulnerable packages

## Workflow Jobs

### 1. `build-and-test`
- **Purpose**: Build solution and run tests on multiple platforms
- **Platforms**: Windows 2022, Ubuntu 22.04, macOS 13, Ubuntu ARM64
- **Artifacts**: Test results for each platform

### 2. `code-quality`
- **Purpose**: Check code formatting and build with warnings as errors
- **Platform**: Ubuntu 22.04
- **Checks**: `dotnet format` and warning-free build

### 3. `security-scan`
- **Purpose**: Scan for vulnerable NuGet packages
- **Platform**: Ubuntu 22.04
- **Artifacts**: Vulnerability report (if any found)

### 4. `summary`
- **Purpose**: Aggregate results from all other jobs
- **Dependency**: Runs after all other jobs complete
- **Behavior**: Fails if any dependent job fails

## Tips for Development

1. **Test locally first**: Use the validation scripts before pushing
2. **Fix formatting**: Run `dotnet format next-gen.sln` to resolve style issues
3. **Check security**: Review any reported vulnerabilities
4. **Platform-specific issues**: Use `act` to test on Linux containers if developing on Windows

## Integration with Main Branch

This workflow is designed to:
- **Not conflict** with the main branch CI when syncing changes
- **Only run** when `next-gen/` files are modified
- **Use separate** artifact names to avoid collisions
- **Provide** clear status checks for the `out-of-process-collection` branch

The main CI workflow remains unchanged, preventing merge conflicts during branch synchronization.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ protected BatchExportProcessorAsync(
IExporterAsync<TBatchWriter> exporter,
BatchExportProcessorOptions options)
{
// Validate all parameters first, before initializing anything
ArgumentNullException.ThrowIfNull(options);

_Logger = logger ?? throw new ArgumentNullException(nameof(logger));
_Exporter = exporter ?? throw new ArgumentNullException(nameof(exporter));

Expand All @@ -46,6 +46,7 @@ protected BatchExportProcessorAsync(
_ExportIntervalMilliseconds = options.ExportIntervalMilliseconds;
_ExportTimeoutMilliseconds = options.ExportTimeoutMilliseconds;

// Only start the thread after all validation and initialization is complete
_ExporterThread = new Thread(ExporterProc)
{
IsBackground = true,
Expand Down Expand Up @@ -196,7 +197,14 @@ private void ExporterProc(object? state)
ExportAsync().ContinueWith(
static (t, o) =>
{
((EventWaitHandle)o!).Set();
try
{
((EventWaitHandle)o!).Set();
}
catch (ObjectDisposedException)
{
// EventWaitHandle was disposed during shutdown, nothing to signal
}
},
_ExportAsyncTaskCompleteTrigger,
CancellationToken.None,
Expand All @@ -205,6 +213,11 @@ private void ExporterProc(object? state)

_ExportAsyncTaskCompleteTrigger.WaitOne();
}
catch (ObjectDisposedException)
{
// The processor is being disposed, exit the worker thread
return;
}
finally
{
_BufferedBatch.Reset();
Expand Down
Loading
Loading