|
| 1 | +#!/usr/bin/env pwsh |
| 2 | + |
| 3 | +<# |
| 4 | +.SYNOPSIS |
| 5 | + Build, test, and pack DocoptNet with multi-Roslyn variant support. |
| 6 | +
|
| 7 | +.DESCRIPTION |
| 8 | + This script orchestrates builds across Roslyn 3.10 (baseline) and Roslyn 4.4 variants, |
| 9 | + runs tests for both variants, and produces a NuGet package containing both analyzer DLLs. |
| 10 | +
|
| 11 | +.PARAMETER Build |
| 12 | + Build the solution (default parameter set). |
| 13 | +
|
| 14 | +.PARAMETER Test |
| 15 | + Run tests. Note: May fail on non-Windows platforms if .NET Framework tests cannot run. |
| 16 | +
|
| 17 | +.PARAMETER Pack |
| 18 | + Create a NuGet package containing both analyzer variants. |
| 19 | +
|
| 20 | +.PARAMETER Configuration |
| 21 | + The build configuration (default: Release). |
| 22 | +
|
| 23 | +.PARAMETER NoBuild |
| 24 | + Skip the build step when running tests (only applies to baseline tests). |
| 25 | +
|
| 26 | +.PARAMETER VersionSuffix |
| 27 | + Optional version suffix for the NuGet package (e.g., "beta1"). |
| 28 | +
|
| 29 | +.PARAMETER PackageReleaseNotesFile |
| 30 | + Optional path to a file containing release notes for the NuGet package. |
| 31 | +
|
| 32 | +.EXAMPLE |
| 33 | + ./build.ps1 |
| 34 | + Build both Roslyn variants (baseline + 4.4). |
| 35 | +
|
| 36 | +.EXAMPLE |
| 37 | + ./build.ps1 -Test |
| 38 | + Build and test both Roslyn variants. |
| 39 | +
|
| 40 | +.EXAMPLE |
| 41 | + ./build.ps1 -Test -NoBuild |
| 42 | + Run tests without rebuilding baseline (Roslyn 4.4 tests always build as needed). |
| 43 | +
|
| 44 | +.EXAMPLE |
| 45 | + ./build.ps1 -Pack -VersionSuffix "beta1" |
| 46 | + Build and pack with version suffix. |
| 47 | +
|
| 48 | +.EXAMPLE |
| 49 | + ./build.ps1 -Pack -PackageReleaseNotesFile "/path/to/notes.txt" |
| 50 | + Build and pack with release notes from a file. |
| 51 | +#> |
| 52 | + |
| 53 | +[CmdletBinding(DefaultParameterSetName = 'Build')] |
| 54 | +param( |
| 55 | + [Parameter(ParameterSetName = 'Build')] |
| 56 | + [switch] $Build, |
| 57 | + |
| 58 | + [Parameter(ParameterSetName = 'Test', Mandatory)] |
| 59 | + [switch] $Test, |
| 60 | + |
| 61 | + [Parameter(ParameterSetName = 'Pack', Mandatory)] |
| 62 | + [switch] $Pack, |
| 63 | + |
| 64 | + [Parameter(ParameterSetName = 'Build')] |
| 65 | + [Parameter(ParameterSetName = 'Test')] |
| 66 | + [Parameter(ParameterSetName = 'Pack')] |
| 67 | + [string] $Configuration = 'Release', |
| 68 | + |
| 69 | + [Parameter(ParameterSetName = 'Test')] |
| 70 | + [switch] $NoBuild, |
| 71 | + |
| 72 | + [Parameter(ParameterSetName = 'Pack')] |
| 73 | + [string] $VersionSuffix, |
| 74 | + |
| 75 | + [Parameter(ParameterSetName = 'Pack')] |
| 76 | + [string] $PackageReleaseNotesFile |
| 77 | +) |
| 78 | + |
| 79 | +$ErrorActionPreference = 'Stop' |
| 80 | +Set-StrictMode -Version Latest |
| 81 | + |
| 82 | +# Make the script directory-independent |
| 83 | +Push-Location $PSScriptRoot |
| 84 | +try { |
| 85 | + function Invoke-DotNet { |
| 86 | + param( |
| 87 | + [string[]] $Arguments |
| 88 | + ) |
| 89 | + |
| 90 | + Write-Host "dotnet $($Arguments -join ' ')" -ForegroundColor Cyan |
| 91 | + & dotnet @Arguments |
| 92 | + if ($LASTEXITCODE -ne 0) { |
| 93 | + throw "dotnet command failed with exit code $LASTEXITCODE" |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + function Invoke-BuildFlow { |
| 98 | + Write-Host "`n=== Building Baseline (Roslyn 3.10) ===" -ForegroundColor Green |
| 99 | + Invoke-DotNet 'build', '--configuration', $Configuration |
| 100 | + |
| 101 | + Write-Host "`n=== Building Roslyn 4.4 Variant ===" -ForegroundColor Green |
| 102 | + Invoke-DotNet 'build', 'src/DocoptNet/DocoptNet.csproj', '-f', 'netstandard2.0', '-p:RoslynVersion=4.4', '--configuration', $Configuration |
| 103 | + } |
| 104 | + |
| 105 | + function Invoke-TestFlow { |
| 106 | + if (-not $NoBuild) { |
| 107 | + Invoke-BuildFlow |
| 108 | + } |
| 109 | + |
| 110 | + Write-Host "`n=== Running Tests ===" -ForegroundColor Green |
| 111 | + Invoke-DotNet 'test', '--no-build', '--configuration', $Configuration |
| 112 | + |
| 113 | + # Note: Roslyn 4.4 analyzer is validated through integration tests |
| 114 | + # that use the packed NuGet package containing both analyzer variants |
| 115 | + } |
| 116 | + |
| 117 | + function Invoke-PackFlow { |
| 118 | + Invoke-BuildFlow |
| 119 | + |
| 120 | + Write-Host "`n=== Packing NuGet Package ===" -ForegroundColor Green |
| 121 | + $packArgs = @('pack', 'src/DocoptNet/DocoptNet.csproj', '--no-build', '--configuration', $Configuration) |
| 122 | + if ($VersionSuffix) { |
| 123 | + $packArgs += @('--version-suffix', $VersionSuffix) |
| 124 | + } |
| 125 | + if ($PackageReleaseNotesFile) { |
| 126 | + $packArgs += "-p:PackageReleaseNotesFile=$PackageReleaseNotesFile" |
| 127 | + } |
| 128 | + Invoke-DotNet $packArgs |
| 129 | + } |
| 130 | + |
| 131 | + # Execute the appropriate flow based on parameter set |
| 132 | + switch ($PSCmdlet.ParameterSetName) { |
| 133 | + 'Build' { |
| 134 | + Invoke-BuildFlow |
| 135 | + } |
| 136 | + 'Test' { |
| 137 | + Invoke-TestFlow |
| 138 | + } |
| 139 | + 'Pack' { |
| 140 | + Invoke-PackFlow |
| 141 | + } |
| 142 | + } |
| 143 | + |
| 144 | + Write-Host "`n=== Success ===" -ForegroundColor Green |
| 145 | +} |
| 146 | +finally { |
| 147 | + Pop-Location |
| 148 | +} |
0 commit comments