From 6fa2da4a113175f1d438813b94a79c9823c26841 Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Mon, 29 Jul 2024 10:53:11 +1000 Subject: [PATCH] Generalise local and CI build experiences The app can be build with "dotnet" without custom scripts. Packaging and publishing moved into MSBuild targets. --- Directory.Build.props | 13 +++ Directory.Build.targets | 2 - Directory.Packages.props | 29 +++++ GitExtensions.PluginManager.sln | 5 + Packages.props | 22 ---- appveyor.yml | 77 +++++++++--- .../GitExtensions.PluginManager.csproj | 41 +------ .../Project.Publish.targets | 110 ++++++++++++++++++ .../PackageManager.UI.csproj | 2 +- test/Directory.Build.props | 26 +++-- test/Directory.Build.targets | 25 ++++ tools/Prepare-Release.ps1 | 50 -------- tools/Run-Tests.ps1 | 17 --- tools/Zip-GitExtensionsPlugin.ps1 | 28 ----- 14 files changed, 267 insertions(+), 180 deletions(-) create mode 100644 Directory.Packages.props delete mode 100644 Packages.props create mode 100644 src/GitExtensions.PluginManager/Project.Publish.targets create mode 100644 test/Directory.Build.targets delete mode 100644 tools/Prepare-Release.ps1 delete mode 100644 tools/Run-Tests.ps1 delete mode 100644 tools/Zip-GitExtensionsPlugin.ps1 diff --git a/Directory.Build.props b/Directory.Build.props index 1c5ba26..467a37d 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -5,6 +5,8 @@ latest $(NoWarn);1573;1591;1712 true + true + win-x86 @@ -19,4 +21,15 @@ 0.0.0.1 + + + $([MSBuild]::NormalizeDirectory('$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'appveyor.yml'))')) + + $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', '$(Configuration)')) + $([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'obj')) + $([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'bin')) + $([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'TestResults')) + $([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'tmp')) + + diff --git a/Directory.Build.targets b/Directory.Build.targets index 498bd13..4de98b5 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -1,5 +1,3 @@ - - \ No newline at end of file diff --git a/Directory.Packages.props b/Directory.Packages.props new file mode 100644 index 0000000..3949efc --- /dev/null +++ b/Directory.Packages.props @@ -0,0 +1,29 @@ + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + diff --git a/GitExtensions.PluginManager.sln b/GitExtensions.PluginManager.sln index 4f389d9..652962d 100644 --- a/GitExtensions.PluginManager.sln +++ b/GitExtensions.PluginManager.sln @@ -4,6 +4,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00 VisualStudioVersion = 17.5.33130.490 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GitExtensions.PluginManager", "src\GitExtensions.PluginManager\GitExtensions.PluginManager.csproj", "{4EB0566E-6D4F-43AF-AA97-2A15ABB66787}" + ProjectSection(ProjectDependencies) = postProject + {3B5E3720-B3CB-4A12-B2D4-6BCB6BE78FF1} = {3B5E3720-B3CB-4A12-B2D4-6BCB6BE78FF1} + {B302D166-37CE-439D-8AE1-0CCB80BAD332} = {B302D166-37CE-439D-8AE1-0CCB80BAD332} + {E7AD4376-D8B1-469D-A2E3-38059A5EB152} = {E7AD4376-D8B1-469D-A2E3-38059A5EB152} + EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PackageManager.UI", "src\PackageManager.UI\PackageManager.UI.csproj", "{6F4FA02A-B061-4607-925E-27B122DE60BC}" EndProject diff --git a/Packages.props b/Packages.props deleted file mode 100644 index 726578f..0000000 --- a/Packages.props +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/appveyor.yml b/appveyor.yml index df85ec1..a76e794 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,10 +1,13 @@ -#---------------------------------# -# general configuration # -#---------------------------------# - # version format version: 3.0.0.{build} +matrix: + fast_finish: true + +# Build worker image (VM template) +image: +- Visual Studio 2022 + # version suffix, if any (e.g. '-RC1', '-beta' otherwise '') environment: version_suffix: '' @@ -13,17 +16,16 @@ environment: # Disable the .NET first time experience to skip caching NuGet packages and speed up the build. DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true - # Do not build on tags (GitHub and BitBucket) skip_tags: true -#---------------------------------# -# environment configuration # -#---------------------------------# - -# Build worker image (VM template) -image: -- Visual Studio 2022 +# Build settings, not to be confused with "before_build" and "after_build". +# "project" is relative to the original build directory and not influenced by directory changes in "before_build". +build: + # enable MSBuild parallel builds + parallel: true + # MSBuild verbosity level + verbosity: minimal # enable patching of Directory.Build.props dotnet_csproj: @@ -39,21 +41,62 @@ dotnet_csproj: # build configuration # #---------------------------------# +install: +- ps: | + # Install the required .NET SDK + Invoke-WebRequest "https://dot.net/v1/dotnet-install.ps1" -OutFile "./dotnet-install.ps1" + ./dotnet-install.ps1 -Channel LTS -InstallDir 'C:\Program Files\dotnet' + # Remove the script so it doesn't "pollute" the build + Remove-Item -Path .\dotnet-install.ps1 + build_script: -- ps: .\tools\Prepare-Release.ps1 +- ps: | + dotnet restore --verbosity q --nologo /bl:.\artifacts\logs\restore.binlog + if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } + +- ps: | + dotnet build -c Release --verbosity q --nologo /bl:.\artifacts\logs\build.binlog + if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } + +- ps: | + dotnet publish --configuration Release --verbosity q -bl:.\artifacts\logs\publish.binlog + if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } #---------------------------------# # tests configuration # #---------------------------------# test_script: -- ps: .\tools\Run-Tests.ps1 +- ps: | + dotnet test -c Release --no-restore --no-build --nologo --verbosity q --test-adapter-path:. --logger:Appveyor --logger:trx /bl:.\artifacts\logs\tests.binlog + if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } #---------------------------------# # artifacts configuration # #---------------------------------# artifacts: -- path: .\GitExtensions.PluginManager.*.zip -- path: .\GitExtensions.PluginManager.*.nupkg -- path: .\*.binlog +- path: .\artifacts\GitExtensions.PluginManager.*.zip +- path: .\artifacts\GitExtensions.PluginManager.*.nupkg +- path: .\artifacts\logs\*.binlog + + +# on build failure +on_failure: +- ps: | + Get-ChildItem -recurse artifacts\Release\TestsResults\*.trx -ErrorAction SilentlyContinue ` + | ForEach-Object { + Push-AppveyorArtifact "$_" + } +- ps: | + Get-ChildItem -recurse artifacts\Release\TestsResults\*.trx | ` + ForEach-Object { + $file = $_.FullName.Replace('[', '``[').Replace(']', '``]') + #Write-Output "Processing $file" + + [xml]$xml = Get-Content -Path $file + $xml.TestRun.Results.UnitTestResult | Where-Object outcome -eq 'Failed' | ForEach-Object { + $errorMessage = "$($_.Output.ErrorInfo.Message)`r`n$($_.Output.ErrorInfo.StackTrace)`r`n" + Write-Host $errorMessage -ForegroundColor Red + } + } diff --git a/src/GitExtensions.PluginManager/GitExtensions.PluginManager.csproj b/src/GitExtensions.PluginManager/GitExtensions.PluginManager.csproj index f5c7c6c..1d3cada 100644 --- a/src/GitExtensions.PluginManager/GitExtensions.PluginManager.csproj +++ b/src/GitExtensions.PluginManager/GitExtensions.PluginManager.csproj @@ -1,4 +1,5 @@  + true @@ -9,12 +10,7 @@ OnOutputUpdated $(MSBuildThisFileDirectory)$(MSBuildProjectName).nuspec 1701;1702;NU5100;NU5101;NU5103;NU5128 - - - - PackageManager\PackageManager.UI.exe - true - ..\PackageManager.UI\bin\$(Configuration)\$(TargetFramework)\publish\PackageManager.UI.exe + false @@ -37,7 +33,8 @@ - + @@ -51,38 +48,10 @@ Resources.Designer.cs - - - - - - - - - id=$(PackageId); - version=$(PackageVersion); - configuration=$(Configuration); - tags=$(PackageTags.Replace(';',' ')); - projectUrl=$(PackageProjectUrl); - iconUrl=$(PackageIconUrl); - repositoryUrl=$(RepositoryUrl); - repositoryType=$(RepositoryType); - repositoryCommit=$(RepositoryCommit); - author=$(Authors); - copyright=$(Copyright); - description=$(Description); - targetDir=$(TargetDir); - - - - - - - - + \ No newline at end of file diff --git a/src/GitExtensions.PluginManager/Project.Publish.targets b/src/GitExtensions.PluginManager/Project.Publish.targets new file mode 100644 index 0000000..83b760a --- /dev/null +++ b/src/GitExtensions.PluginManager/Project.Publish.targets @@ -0,0 +1,110 @@ + + + <_PackageManagerFolder>PackageManager + + + + + + <_PackageManagerSourcePath>$([MSBuild]::NormalizePath('$(RepoRoot)', 'src', 'PackageManager.UI', 'bin', '$(Configuration)', '$(TargetFramework)', '$(PackageManagerUIRuntimeIdentifier)', 'publish', 'PackageManager.UI.exe')) + <_PackageManagerTargetPath>$(_PackageManagerFolder)\PackageManager.UI.exe + + + + + + + + + + + + + + id=$(PackageId); + version=$(PackageVersion); + configuration=$(Configuration); + tags=$(PackageTags.Replace(';',' ')); + projectUrl=$(PackageProjectUrl); + iconUrl=$(PackageIconUrl); + repositoryUrl=$(RepositoryUrl); + repositoryType=$(RepositoryType); + repositoryCommit=$(RepositoryCommit); + author=$(Authors); + copyright=$(Copyright); + description=$(Description); + targetDir=$(TargetDir); + + + + + + + + + $([MSBuild]::NormalizePath('$(ArtifactsDir)', '..')) + + + + + + + <_PublishPortableFileName>GitExtensions.PluginManager.$(PackageVersion).zip + <_PublishPortablePath>$([MSBuild]::NormalizePath('$(ArtifactsDir)', '..', '$(_PublishPortableFileName)')) + + + <_PublishedPath>$([MSBuild]::NormalizeDirectory('$(PublishDir)')) + + + + + <_ZipContent Include="$([MSBuild]::NormalizePath('$(TargetDir)', '$(_PackageManagerFolder)'))\*.*" /> + + + + + + + \ No newline at end of file diff --git a/src/PackageManager.UI/PackageManager.UI.csproj b/src/PackageManager.UI/PackageManager.UI.csproj index 0f0a19b..e123c6f 100644 --- a/src/PackageManager.UI/PackageManager.UI.csproj +++ b/src/PackageManager.UI/PackageManager.UI.csproj @@ -10,7 +10,7 @@ true false - win-x86 + $(PackageManagerUIRuntimeIdentifier) true diff --git a/test/Directory.Build.props b/test/Directory.Build.props index 5aa7950..4eaf531 100644 --- a/test/Directory.Build.props +++ b/test/Directory.Build.props @@ -6,12 +6,24 @@ PackageManager - - - - - - - + + false + true + + + + false + true + + + + false + true + + + + false + true + \ No newline at end of file diff --git a/test/Directory.Build.targets b/test/Directory.Build.targets new file mode 100644 index 0000000..6c0167e --- /dev/null +++ b/test/Directory.Build.targets @@ -0,0 +1,25 @@ + + + + + trx + $(ArtifactsTestResultsDir) + + + + $(PlatformTarget) + x64 + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/Prepare-Release.ps1 b/tools/Prepare-Release.ps1 deleted file mode 100644 index f22f70e..0000000 --- a/tools/Prepare-Release.ps1 +++ /dev/null @@ -1,50 +0,0 @@ -Push-Location $PSScriptRoot; - -$targetPath = '..\'; - -$isAppveyor = $True -eq $env:APPVEYOR; - -If (!$isAppveyor) -{ - Write-Host "Running a local build"; - - $targetPath = Join-Path $targetPath 'artifacts'; -} - -function EnsureLastCommandSucceeded() -{ - if (!($LastExitCode -eq 0)) - { - Pop-Location; - Write-Error -Message "MSBuild failed with $LastExitCode" -ErrorAction Stop - } -} - -# Install the required .NET SDK -Invoke-WebRequest "https://dot.net/v1/dotnet-install.ps1" -OutFile "./dotnet-install.ps1" -./dotnet-install.ps1 -Channel LTS -InstallDir 'C:\Program Files\dotnet' -# Remove the script so it doesn't "pollute" the build -Remove-Item -Path .\dotnet-install.ps1 - -Write-Host "Restore solution" -dotnet restore ..\GitExtensions.PluginManager.sln -p:RuntimeIdentifier=win-x86 -EnsureLastCommandSucceeded - -Write-Host "Publish PackageManager.UI" -dotnet publish ..\src\PackageManager.UI\PackageManager.UI.csproj -c Release -p:PublishDir=bin\Release\net8.0-windows\publish\ -bl:$targetPath\build-PackageManager.UI.binlog -EnsureLastCommandSucceeded - -Write-Host "Publish GitExtensions.PluginManager" -dotnet publish ..\src\GitExtensions.PluginManager\GitExtensions.PluginManager.csproj --configuration Release -verbosity:minimal -bl:$targetPath\build-GitExtensions.PluginManager.binlog -EnsureLastCommandSucceeded - -if (!(Test-Path $targetPath)) -{ - New-Item -ItemType Directory -Force -Path $targetPath -} - -Write-Host "Copy artifacts" -Copy-Item ..\src\GitExtensions.PluginManager\bin\Release\GitExtensions.PluginManager.*.zip $targetPath -Copy-Item ..\src\GitExtensions.PluginManager\bin\Release\GitExtensions.PluginManager.*.nupkg $targetPath - -Pop-Location; \ No newline at end of file diff --git a/tools/Run-Tests.ps1 b/tools/Run-Tests.ps1 deleted file mode 100644 index 7a942c5..0000000 --- a/tools/Run-Tests.ps1 +++ /dev/null @@ -1,17 +0,0 @@ -Push-Location $PSScriptRoot; - -$targetPath = '..\'; - -$isAppveyor = $True -eq $env:APPVEYOR; - -If (!$isAppveyor) -{ - Write-Host "Running locally"; - - $targetPath = Join-Path $targetPath 'artifacts'; -} - -dotnet test ..\test\PackageManager.NuGet.Tests\PackageManager.NuGet.Tests.csproj -c Release --test-adapter-path:.. --logger:Appveyor /property:Platform=AnyCPU -bl:$targetPath\build-PackageManager.NuGet.Tests.binlog -dotnet test ..\test\PackageManager.Tests\PackageManager.Tests.csproj -c Release --test-adapter-path:.. --logger:Appveyor /property:Platform=AnyCPU -bl:$targetPath\build-PackageManager.Tests.binlog - -Pop-Location; \ No newline at end of file diff --git a/tools/Zip-GitExtensionsPlugin.ps1 b/tools/Zip-GitExtensionsPlugin.ps1 deleted file mode 100644 index 46b53cb..0000000 --- a/tools/Zip-GitExtensionsPlugin.ps1 +++ /dev/null @@ -1,28 +0,0 @@ -param([string] $Version, [string] $Configuration = 'Release') - -If (-not($Version)) -{ - Throw "Parameter -Version is required"; -} - -Push-Location $PSScriptRoot; - -$sourceBasePath = "..\src\GitExtensions.PluginManager\bin\" + $Configuration; - -$name = "GitExtensions.PluginManager-" + $Version; -$target = $sourceBasePath + "\GitExtensions.PluginManager." + $Version + ".zip"; - -$tempPath = Join-Path $env:TEMP -ChildPath $name; -$tempPmPath = Join-Path $tempPath -ChildPath "PackageManager"; -New-Item -Force -ItemType Directory $tempPath | Out-Null; -New-Item -Force -ItemType Directory $tempPmPath | Out-Null; - -Copy-Item -Force ($sourceBasePath + "\net8.0-windows\GitExtensions.PluginManager.dll") $tempPath | Out-Null; -Copy-Item -Force ($sourceBasePath + "\net8.0-windows\PackageManager\PackageManager.UI.exe") $tempPmPath | Out-Null; - -Compress-Archive -Path ($tempPath + "\*") -DestinationPath $target -Force; -Write-Host ("Created release zip at '" + $target + "'"); - -Remove-Item -Force -Recurse $tempPath; - -Pop-Location; \ No newline at end of file