Skip to content

Commit

Permalink
Added build scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris3606 committed Jan 28, 2025
1 parent 8bd23c5 commit 40ddc21
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,6 @@ ASALocalRun/

# MFractors (Xamarin productivity tool) working folder
.mfractor/

**/*.key
nuget/archive/
87 changes: 87 additions & 0 deletions nuget/build.ps1
Original file line number Diff line number Diff line change
@@ -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 "<Version>(.*)<").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."
}
2 changes: 0 additions & 2 deletions nuget/push.bat

This file was deleted.

0 comments on commit 40ddc21

Please sign in to comment.