CI/CD Automation Scripts

The CI/CD automation for the stevedunn/intellenum project is structured around PowerShell scripts that facilitate building, testing, and packaging the application. Below is a detailed overview of the scripts and the CI/CD process involved.

Directory Structure

The project includes the following main scripts that are directly responsible for CI/CD automation:

PowerShell Scripts

Build.ps1

The Build.ps1 script is the central script that manages the build process.

Key Functions:

  • Build Execution: It executes the build process for the project and runs tests.

Example Code Snippet:

function Exec {
    [CmdletBinding()]
    param(
        [Parameter(Position=0,Mandatory=1)][scriptblock]$cmd,
        [Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd)
    )
    & $cmd
    if ($lastexitcode -ne 0) {
        throw ("Exec: " + $errorMessage)
    }
}

WriteStage("Building $buildConfig version of Intellenum...")
exec { & dotnet build src/Intellenum/Intellenum.csproj -c $buildConfig --verbosity detailed }

WriteStage("Running analyzer tests...")
exec { & dotnet test tests/AnalyzerTests/AnalyzerTests.csproj -c $buildConfig --no-build -l trx -l "GitHubActions;report-warnings=false" --verbosity $verbosity }

WriteStage("Finally, packing the $buildConfig version into " + $artifacts)
exec { & dotnet pack src/Intellenum.Pack.csproj -c $buildConfig -o $artifacts --no-build --verbosity $verbosity }

WriteStage("Done! Package generated at " + $artifacts)

RunBenchmarks.ps1

This script is used to execute benchmarks on the project.

Key Functions:

  • Benchmark Execution: It manages the compilation and execution of benchmarks.

Example Code Snippet:

function Exec {
    [CmdletBinding()]
    param(
        [Parameter(Position=0,Mandatory=1)][scriptblock]$cmd,
        [Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd)
    )
    & $cmd
    if ($lastexitcode -ne 0) {
        throw ("Exec: " + $errorMessage)
    }
}

WriteStage("Running benchmarks ... short job?: $short")
exec { & dotnet clean .\src\Benchmarks\Benchmarks.csproj --verbosity $verbosity }
exec { & dotnet restore .\src\Benchmarks\Benchmarks.csproj --verbosity $verbosity }
exec { & dotnet build .\src\Benchmarks\Benchmarks.csproj -c Release --no-restore --verbosity detailed }

if($short) {
    exec { & pushd; cd .\src\Benchmarks; dotnet run --project Benchmarks.csproj -c release --no-build -- --job short --verbosity $verbosity }
} else {
    exec { & pushd; cd .\src\Benchmarks; dotnet run --project Benchmarks.csproj -c release -- --verbosity $verbosity }
}

exec { & popd }

RunSnapshots.ps1

This script manages the execution of snapshot tests to ensure consistent behavior.

Key Functions:

  • Snapshot Testing: Executes various snapshot tests defined in the codebase.

Example Code Snippet:

function Exec {
    [CmdletBinding()]
    param(
        [Parameter(Position=0,Mandatory=1)][scriptblock]$cmd,
        [Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd)
    )
    & $cmd
    if ($lastexitcode -ne 0) {
        throw ("Exec: " + $errorMessage)
    }
}

WriteStage("Running snapshot tests...")
# Add commands for running snapshot tests here

Dockerfile

The project utilizes a Dockerfile for containerization, which enables consistent deployment across environments.

Key Components:

FROM mcr.microsoft.com/dotnet/sdk:7.0

COPY . .

ENTRYPOINT [ "powershell.exe", "./Build.ps1" ]

CI/CD Workflow Integration

The scripts are integrated with GitHub Actions workflows located in the .github/workflows/ directory. Key workflow files include:

  • build.yaml
  • benchmark.yaml
  • publish.yaml
  • deploy.yaml
  • codeql-analysis.yaml

Each of these YAML files defines specific triggers, jobs, and steps that utilize the PowerShell scripts for CI/CD tasks.

Conclusion

With the provided automation scripts and their integration into the GitHub Actions workflows, the stevedunn/intellenum project ensures that all build, test, and packaging processes are automated, facilitating continuous integration and delivery.

Sources: Dockerfile, RunSnapshots.ps1, RunBenchmarks.ps1, Build.ps1.