This document provides a detailed guide to the CI/CD automation scripts used in the stevedunn/vogen project. It outlines the scripts and configuration files that facilitate automated building, testing, and deployment processes.

Overview

The CI/CD setup leverages several PowerShell scripts and a Dockerfile to ensure consistent and repeatable builds. Automating the CI/CD pipeline helps maintain code quality and efficiency throughout the development lifecycle.

Key Scripts in the Project

1. Dockerfile

The Dockerfile is the entry point for building the application in a containerized environment:

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

COPY . .

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

This file specifies the base image (dotnet/sdk:7.0), copies the entire project directory into the image, and sets the entry point to execute the Build.ps1 script.

2. Build.ps1

The Build.ps1 script handles the building, testing, and packaging of the application. Below is a section of the script illustrating its structure:

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

WriteStage("Building release version of Vogen...")

if(Test-Path $artifacts) { Remove-Item $artifacts -Force -Recurse }

New-Item -Path $artifacts -ItemType Directory

This snippet demonstrates the use of a helper function Exec to execute commands, checking if any errors occur during execution. The script also manages artifact cleanup and directory creation.

WriteStage("Cleaning, restoring, and building release version of Vogen...")

WriteStage("... clean ...")
exec { & dotnet clean Vogen.sln -c Release --verbosity $verbosity }

WriteStage("... restore ...")
exec { & dotnet restore Vogen.sln --no-cache --verbosity $verbosity }

exec { & dotnet build Vogen.sln -c Release -p Thorough=true --no-restore --verbosity $verbosity}

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

The script executes key commands for cleaning, restoring, and building the solution, followed by running tests.

3. RunSnapshots.ps1

The RunSnapshots.ps1 script is responsible for running snapshot tests, essential for validating changes over time:

if($reset)
{
    WriteStage("... resetting snapshots before running them ...")
    exec { & dotnet build Vogen.sln -c Release -p Thorough=true -p ResetSnapshots=true --no-restore --verbosity $verbosity}
}
else
{
    WriteStage("... running snapshots ...")
    exec { & dotnet build Vogen.sln -c Release -p Thorough=true --no-restore --verbosity $verbosity}
}

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

This script checks for conditions to reset the snapshots and runs the designated snapshot tests, providing feedback on the testing process.

Conclusion

The CI/CD setup for the stevedunn/vogen project comprises structured scripts leveraging PowerShell and Docker. The scripts handle various tasks, such as building the application, running tests, and managing artifacts.

While the CI/CD processes are robust, it is critical to keep the scripts updated according to new project needs or development practices.

For future improvements, consider integrating additional checks, notifications, or deploying environments based on merging logic and outcomes from tests.