Skip to content

Commit ea10105

Browse files
authored
Remove Cake Build (#94)
We no longer require Cake build nor we use it extensively! Update Azure Pipelines (CI YAML) Script to be more modern and runnable across platforms. Replaced the headers check with a PowerShell script mimicking the Cake script's `UpdateHeaders` task functionality.
1 parent c5ab771 commit ea10105

8 files changed

+107
-446
lines changed

azure-pipelines.yml

+17-19
Original file line numberDiff line numberDiff line change
@@ -18,66 +18,64 @@ jobs:
1818

1919
# Install NuGet
2020
- task: NuGetToolInstaller@0
21-
displayName: Install NuGet 5.6.0
21+
displayName: Install NuGet 6.0
2222
inputs:
23-
versionSpec: 5.6.0
23+
versionSpec: 6.0.0
2424

2525
# Install NerdBank GitVersioning
2626
- task: DotNetCoreCLI@2
2727
displayName: Install NBGV tool
2828
inputs:
2929
command: custom
3030
custom: tool
31-
arguments: install --tool-path . nbgv
31+
arguments: install -g nbgv
32+
33+
# Set Build Version
3234
- script: nbgv cloud
3335
displayName: Set NBGV version
3436

3537
# Verify headers
36-
- powershell: .\build\build.ps1 -Target Verify
38+
- pwsh: build/Update-Headers.ps1 -Verify
3739
displayName: Verify headers
3840

3941
# Build solution
40-
- powershell: dotnet build -c Release
42+
- script: dotnet build -c Release
4143
displayName: Build solution
4244

4345
# Run .NET 6 tests
44-
- powershell: dotnet test --logger "trx;LogFileName=VsTestResultsNet6.trx" --framework net6.0 --configuration Release
46+
- script: dotnet test -c Release -f net6.0 -l "trx;LogFileName=VSTestResults_net6.0.trx"
4547
displayName: Run .NET 6 unit tests
4648

4749
# Run .NET Core 3.1 tests
48-
- powershell: dotnet test --logger "trx;LogFileName=VsTestResultsNetCore31.trx" --framework netcoreapp3.1 --configuration Release
50+
- script: dotnet test -c Release -f netcoreapp3.1 -l "trx;LogFileName=VSTestResults_netcoreapp3.1.trx"
4951
displayName: Run .NET Core 3.1 unit tests
5052

5153
# Run .NET Framework 4.7.2 tests
52-
- powershell: dotnet test --logger "trx;LogFileName=VsTestResultsNet472.trx" --framework net472 --configuration Release
54+
- script: dotnet test -c Release -f net472 -l "trx;LogFileName=VSTestResults_net472.trx"
5355
displayName: Run .NET Framework 4.7.2 unit tests
5456

5557
# Publish test results
5658
- task: PublishTestResults@2
5759
displayName: Publish test results
5860
inputs:
5961
testResultsFormat: 'VSTest'
60-
testResultsFiles: '**/VsTestResults*.trx'
62+
testResultsFiles: '**/VSTestResults*.trx'
6163
condition: always()
6264

6365
# Create the NuGet package(s)
64-
- powershell: dotnet pack --configuration Release
66+
- script: dotnet pack -c Release
6567
displayName: Create NuGet package(s)
6668

6769
# Sign package(s)
68-
- task: PowerShell@2
70+
- pwsh: build/Sign-Package.ps1
6971
displayName: Authenticode sign packages
70-
inputs:
71-
filePath: build/Sign-Package.ps1
7272
env:
7373
SignClientUser: $(SignClientUser)
7474
SignClientSecret: $(SignClientSecret)
75-
ArtifactDirectory: bin\nupkg
76-
condition: and(succeeded(), not(eq(variables['build.reason'], 'PullRequest')), not(eq(variables['SignClientSecret'], '')), not(eq(variables['SignClientUser'], '')))
75+
ArtifactDirectory: bin/nupkg
76+
condition: and(succeeded(), not(eq(variables['Build.Reason'], 'PullRequest')), not(eq(variables['SignClientSecret'], '')), not(eq(variables['SignClientUser'], '')))
7777

7878
# Publish build artifacts
79-
- task: PublishPipelineArtifact@1
79+
- publish: bin/nupkg
80+
artifact: Packages
8081
displayName: Publish package artifacts
81-
inputs:
82-
targetPath: .\bin\nupkg
83-
artifactName: Packages

build/Build.bat

-3
This file was deleted.

build/Update-Headers.ps1

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Script to Update Header comment in C# sources within this repository.
2+
3+
# This script duplicates the fuctionality provided by the 'UpdateHeaders' target in Cake script present previously.
4+
# Since, Cake build has been removed, this fuctionality has been implimented here in this PowerShell script.
5+
6+
[CmdletBinding()]
7+
Param(
8+
[Alias("Verify")]
9+
[switch]$DryRun,
10+
[switch]$Clean
11+
)
12+
13+
function Clear-BuildArtifacts {
14+
if (Get-Command dotnet) {
15+
Write-Host "Starting 'dotnet msbuild -t:Clean' to clean-up build outputs"
16+
dotnet msbuild -noLogo -noAutoRsp -v:m -t:Clean
17+
}
18+
elseif (Get-Command msbuild) {
19+
Write-Host "Starting 'msbuild -t:Clean' to clean-up build outputs"
20+
msbuild -noLogo -noAutoRsp -v:m -t:Clean
21+
}
22+
elseif (Get-Command git) {
23+
Write-Host "Starting 'git clean -Xdf' to clean-up build outputs"
24+
git clean -Xdf
25+
}
26+
else {
27+
Write-Warning "Can't find dotnet/msbuild/git to clean-up build outputs"
28+
}
29+
}
30+
31+
function Get-SourceFiles ([string]$Path, [string]$Extension) {
32+
$fileType = $Extension.TrimStart('.')
33+
$fileFilter = "*.$fileType"
34+
$fileExcludes = "*.g.$fileType", "*.i.$fileType", "*TemporaryGeneratedFile*.$fileType"
35+
$sourceFiles = Get-ChildItem -Path $Path -File -Recurse -Filter $fileFilter -Exclude $fileExcludes
36+
return $sourceFiles.Where({ !($_.FullName.Contains("\bin\") -or $_.FullName.Contains("\obj\")) })
37+
}
38+
39+
# Set Repot Root
40+
$repoRoot = Split-Path -Path $PSScriptRoot -Parent
41+
Push-Location $repoRoot
42+
43+
# Clean-up Repository build outputs
44+
if ($Clean) {
45+
Clear-BuildArtifacts
46+
}
47+
48+
# Get C# source files recursively
49+
$sourceFiles = Get-SourceFiles -Path $repoRoot -Extension ".cs"
50+
51+
Write-Host "Checking $($sourceFiles.Count) C# file header(s)"
52+
53+
$hasMissing = $false
54+
foreach ($sourceFile in $sourceFiles) {
55+
56+
$oldContent = Get-Content $sourceFile -Raw | Out-String -NoNewline
57+
58+
if ($oldContent.Contains("// <auto-generated/>") -or $oldContent.Contains("// <auto-generated>")) {
59+
continue
60+
}
61+
62+
$headerFilePath = Join-Path $PSScriptRoot "header.txt"
63+
$headerContent = Get-Content $headerFilePath -Raw | Out-String
64+
$regexHeader = "^(//.*\r?\n)*\r?\n"
65+
$newContent = $oldContent -replace $regexHeader,$headerContent | Out-String -NoNewline
66+
67+
if (-not ($newContent -eq $oldContent)) {
68+
$sourceFilePath = [System.IO.Path]::GetRelativePath($repoRoot, $sourceFile.FullName)
69+
70+
if ($DryRun) {
71+
Write-Warning "Wrong/missing file header in '$sourceFilePath'"
72+
$hasMissing = $true
73+
}
74+
else {
75+
Write-Host "Updating '$sourceFilePath' file header..."
76+
Set-Content -Path $sourceFile -Value $newContent -NoNewline
77+
}
78+
}
79+
}
80+
81+
if ($DryRun -and $hasMissing) {
82+
Write-Error "Please run 'Update-Headers.ps1' to verify and add missing headers ins source files before commiting your changes."
83+
}
84+
else {
85+
Write-Host "All $($sourceFiles.Count) C# file header(s) are up to date."
86+
}
87+
88+
# Pop out of Repo Root
89+
Pop-Location

build/UpdateHeaders.bat

-3
This file was deleted.

build/build.cake

-120
This file was deleted.

0 commit comments

Comments
 (0)