Skip to content

Commit f577a1b

Browse files
CopilotAtif Aziz
andauthored
Add script for multi-Roslyn build orchestration (#214)
--------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Atif Aziz <code@raboof>
1 parent cf9049b commit f577a1b

File tree

4 files changed

+210
-8
lines changed

4 files changed

+210
-8
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ jobs:
4848
run: dotnet tool restore
4949

5050
- name: Build
51-
run: dotnet build --configuration ${{ env.CONFIGURATION }}
52-
53-
- name: Build Roslyn 4.4 variant
54-
run: dotnet build src/DocoptNet/DocoptNet.csproj -f netstandard2.0 -p:RoslynVersion=4.4 --configuration ${{ env.CONFIGURATION }}
51+
run: dotnet pwsh ./build.ps1 -Build -Configuration ${{ env.CONFIGURATION }}
5552

5653
- name: Pack (Windows only)
5754
if: runner.os == 'Windows'
@@ -79,11 +76,16 @@ jobs:
7976
}
8077
8178
Add-Content $releaseNotesFile -Encoding UTF8 "Commit @ ${{ github.sha }}"
82-
$packArgs = @()
79+
80+
$packParams = @{
81+
Configuration = '${{ env.CONFIGURATION }}'
82+
PackageReleaseNotesFile = $releaseNotesFile
83+
}
8384
if ($versionSuffix) {
84-
$packArgs += @('--version-suffix', $versionSuffix)
85+
$packParams.VersionSuffix = $versionSuffix
8586
}
86-
dotnet pack --no-build --configuration ${{ env.CONFIGURATION }} @packArgs "-p:PackageReleaseNotesFile=$releaseNotesFile"
87+
88+
& ./build.ps1 -Pack @packParams
8789
if ($LASTEXITCODE) { throw "Pack failed" }
8890
8991
Get-ChildItem -File -Filter docopt.net.*.nupkg dist |

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,58 @@ Install [the package][nupkg] in a .NET project using:
7070

7171
dotnet add package docopt.net
7272

73+
## Building from Source
74+
75+
The repository uses a PowerShell script to orchestrate multi-Roslyn variant builds. Ensure you have the required tools installed:
76+
77+
```bash
78+
dotnet tool restore
79+
```
80+
81+
### Build
82+
83+
To build the project with both Roslyn 3.10 (baseline) and Roslyn 4.4 variants:
84+
85+
```bash
86+
dotnet pwsh ./build.ps1
87+
```
88+
89+
or simply:
90+
91+
```bash
92+
dotnet pwsh ./build.ps1 -Build -Configuration Release
93+
```
94+
95+
### Test
96+
97+
To run tests:
98+
99+
```bash
100+
dotnet pwsh ./build.ps1 -Test
101+
```
102+
103+
To run tests without rebuilding:
104+
105+
```bash
106+
dotnet pwsh ./build.ps1 -Test -NoBuild
107+
```
108+
109+
### Pack
110+
111+
To create a NuGet package containing both analyzer variants:
112+
113+
```bash
114+
dotnet pwsh ./build.ps1 -Pack
115+
```
116+
117+
**Note:** Running `dotnet pack` directly without first building all Roslyn variants will fail with an error message. Always use `./build.ps1 -Pack` to ensure both analyzer variants are included in the package.
118+
119+
To pack with a version suffix:
120+
121+
```bash
122+
dotnet pwsh ./build.ps1 -Pack -VersionSuffix "beta1"
123+
```
124+
73125
## Copyright and License
74126

75127
- &copy; 2012-2014 Vladimir Keleshev <vladimir@keleshev.com>

build.ps1

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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+
}

tests/Integration/run.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ try
2424
}
2525
Remove-Item -Recurse -Force (Join-Path $props.RestorePackagesPath docopt.net) -ErrorAction SilentlyContinue
2626
if (!$noPack) {
27-
dotnet pack -c Release ../..
27+
& ../../build.ps1 -Pack -Configuration Release
2828
if ($LASTEXITCODE) { throw }
2929
}
3030
Remove-Item bin, obj -Recurse -Force -ErrorAction SilentlyContinue

0 commit comments

Comments
 (0)