From 40ddc21be06da9efd26a1ac487a188ca8f42e0f7 Mon Sep 17 00:00:00 2001 From: Chris3606 Date: Mon, 27 Jan 2025 19:55:05 -0600 Subject: [PATCH] Added build scripts. --- .gitignore | 3 ++ nuget/build.ps1 | 87 +++++++++++++++++++++++++++++++++++++++++++++++++ nuget/push.bat | 2 -- 3 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 nuget/build.ps1 delete mode 100644 nuget/push.bat diff --git a/.gitignore b/.gitignore index 13b590e..494dbce 100644 --- a/.gitignore +++ b/.gitignore @@ -329,3 +329,6 @@ ASALocalRun/ # MFractors (Xamarin productivity tool) working folder .mfractor/ + +**/*.key +nuget/archive/ \ No newline at end of file diff --git a/nuget/build.ps1 b/nuget/build.ps1 new file mode 100644 index 0000000..6502c71 --- /dev/null +++ b/nuget/build.ps1 @@ -0,0 +1,87 @@ +# Configuration +$scriptDir = $PSScriptRoot +$rootDir = Join-Path $scriptDir ".." +$archive = Join-Path $scriptDir archive +$corePackage = "TheSadRogue.Primitives" +$dependentPackages = @("TheSadRogue.Primitives.MonoGame", "TheSadRogue.Primitives.SFML") +$nugetKeyPath = Join-Path $scriptDir "nuget.key" + +# Delete any NuGet packages not moved to archive +Write-Output "Removing old nupkg files" +Remove-Item "$scriptDir\*.nupkg","$scriptDir\*.snupkg" -Force + +# Make sure archive directory exists +if(!(Test-Path $archive)) +{ + New-Item -Path $archive -ItemType Directory -Force | Out-Null +} + +# Build core package +Write-Output "Building $corePackage Debug and Release" +$output = Invoke-Expression "dotnet build $rootDir\$corePackage\$corePackage.csproj -c Debug --no-cache"; if ($LASTEXITCODE -ne 0) { Write-Error "Failed"; Write-Output $output; throw } +$output = Invoke-Expression "dotnet build $rootDir\$corePackage\$corePackage.csproj -c Release --no-cache"; if ($LASTEXITCODE -ne 0) { Write-Error "Failed"; Write-Output $output; throw } + +# Find the version we're using +$version = (Get-Content $rootDir\$corePackage\$corePackage.csproj | Select-String "(.*)<").Matches[0].Groups[1].Value +$nugetKey = Get-Content $nugetKeyPath +Write-Output "Target $coreProjectVersion version is $version" + +# Push packages to nuget +Write-Output "Pushing $corePackage packages" +$corePackages = Get-ChildItem "$corePackage.*.nupkg" | Select-Object -ExpandProperty Name + +foreach ($package in $corePackages) { + $output = Invoke-Expression "dotnet nuget push `"$package`" -s nuget.org -k $nugetKey --skip-duplicate"; if ($LASTEXITCODE -ne 0) { Write-Error "Failed"; Write-Output $output; throw } +} + +Write-Output "Query NuGet for 10 minutes to find the new package" + +$timeout = New-TimeSpan -Minutes 10 +$timer = [Diagnostics.StopWatch]::StartNew() +[Boolean]$foundPackage = $false + +# Loop searching for the new SadConsole package +while ($timer.elapsed -lt $timeout){ + + $existingVersions = (Invoke-WebRequest "https://api-v2v3search-0.nuget.org/query?q=PackageId:$corePackage&prerelease=true").Content | ConvertFrom-Json + + if ($existingVersions.totalHits -eq 0) { + throw "Unable to get any results from NuGet" + } + + if ($null -eq ($existingVersions.data.versions | Where-Object version -eq $version)) { + Write-Output "Waiting 30 seconds to retry..." + Start-Sleep -Seconds 30 + + } + else { + Write-Output "Found package. Waiting 1 extra minute to let things settle" + $foundPackage = $true + Start-Sleep -Seconds 60 + break + } +} + +# Found the core package, start building and pushing the other packages +if ($foundPackage){ + + foreach ($project in $dependentPackages) { + # Build package + Write-Output "Building $project Debug and Release" + $output = Invoke-Expression "dotnet build $rootDir\$project\$project.csproj -c Debug -p:UseProjectReferences=false --no-cache"; if ($LASTEXITCODE -ne 0) { Write-Error "Failed"; Write-Output $output; throw } + $output = Invoke-Expression "dotnet build $rootDir\$project\$project.csproj -c Release -p:UseProjectReferences=false --no-cache"; if ($LASTEXITCODE -ne 0) { Write-Error "Failed"; Write-Output $output; throw } + + # Push packages to nuget + Write-Output "Pushing $project packages" + $packages = Get-ChildItem "$project*.nupkg" | Select-Object -ExpandProperty Name + + foreach ($package in $packages) { + $output = Invoke-Expression "dotnet nuget push `"$package`" -s nuget.org -k $nugetKey --skip-duplicate"; if ($LASTEXITCODE -ne 0) { Write-Error "Failed"; Write-Output $output; throw } + } + } + + # Archive the packages + Move-Item "$scriptDir\*.nupkg","$scriptDir\*.snupkg" $archive -force +} else { + Write-Error "$corePackage didn't appear on NuGet within 10 minutes." +} \ No newline at end of file diff --git a/nuget/push.bat b/nuget/push.bat deleted file mode 100644 index 7138354..0000000 --- a/nuget/push.bat +++ /dev/null @@ -1,2 +0,0 @@ -nuget push TheSadRogue.Primitives.%1-debug.nupkg -Source https://api.nuget.org/v3/index.json -nuget push TheSadRogue.Primitives.%1.nupkg -Source https://api.nuget.org/v3/index.json \ No newline at end of file