Skip to content

Commit 40ddc21

Browse files
committed
Added build scripts.
1 parent 8bd23c5 commit 40ddc21

File tree

3 files changed

+90
-2
lines changed

3 files changed

+90
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,6 @@ ASALocalRun/
329329

330330
# MFractors (Xamarin productivity tool) working folder
331331
.mfractor/
332+
333+
**/*.key
334+
nuget/archive/

nuget/build.ps1

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Configuration
2+
$scriptDir = $PSScriptRoot
3+
$rootDir = Join-Path $scriptDir ".."
4+
$archive = Join-Path $scriptDir archive
5+
$corePackage = "TheSadRogue.Primitives"
6+
$dependentPackages = @("TheSadRogue.Primitives.MonoGame", "TheSadRogue.Primitives.SFML")
7+
$nugetKeyPath = Join-Path $scriptDir "nuget.key"
8+
9+
# Delete any NuGet packages not moved to archive
10+
Write-Output "Removing old nupkg files"
11+
Remove-Item "$scriptDir\*.nupkg","$scriptDir\*.snupkg" -Force
12+
13+
# Make sure archive directory exists
14+
if(!(Test-Path $archive))
15+
{
16+
New-Item -Path $archive -ItemType Directory -Force | Out-Null
17+
}
18+
19+
# Build core package
20+
Write-Output "Building $corePackage Debug and Release"
21+
$output = Invoke-Expression "dotnet build $rootDir\$corePackage\$corePackage.csproj -c Debug --no-cache"; if ($LASTEXITCODE -ne 0) { Write-Error "Failed"; Write-Output $output; throw }
22+
$output = Invoke-Expression "dotnet build $rootDir\$corePackage\$corePackage.csproj -c Release --no-cache"; if ($LASTEXITCODE -ne 0) { Write-Error "Failed"; Write-Output $output; throw }
23+
24+
# Find the version we're using
25+
$version = (Get-Content $rootDir\$corePackage\$corePackage.csproj | Select-String "<Version>(.*)<").Matches[0].Groups[1].Value
26+
$nugetKey = Get-Content $nugetKeyPath
27+
Write-Output "Target $coreProjectVersion version is $version"
28+
29+
# Push packages to nuget
30+
Write-Output "Pushing $corePackage packages"
31+
$corePackages = Get-ChildItem "$corePackage.*.nupkg" | Select-Object -ExpandProperty Name
32+
33+
foreach ($package in $corePackages) {
34+
$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 }
35+
}
36+
37+
Write-Output "Query NuGet for 10 minutes to find the new package"
38+
39+
$timeout = New-TimeSpan -Minutes 10
40+
$timer = [Diagnostics.StopWatch]::StartNew()
41+
[Boolean]$foundPackage = $false
42+
43+
# Loop searching for the new SadConsole package
44+
while ($timer.elapsed -lt $timeout){
45+
46+
$existingVersions = (Invoke-WebRequest "https://api-v2v3search-0.nuget.org/query?q=PackageId:$corePackage&prerelease=true").Content | ConvertFrom-Json
47+
48+
if ($existingVersions.totalHits -eq 0) {
49+
throw "Unable to get any results from NuGet"
50+
}
51+
52+
if ($null -eq ($existingVersions.data.versions | Where-Object version -eq $version)) {
53+
Write-Output "Waiting 30 seconds to retry..."
54+
Start-Sleep -Seconds 30
55+
56+
}
57+
else {
58+
Write-Output "Found package. Waiting 1 extra minute to let things settle"
59+
$foundPackage = $true
60+
Start-Sleep -Seconds 60
61+
break
62+
}
63+
}
64+
65+
# Found the core package, start building and pushing the other packages
66+
if ($foundPackage){
67+
68+
foreach ($project in $dependentPackages) {
69+
# Build package
70+
Write-Output "Building $project Debug and Release"
71+
$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 }
72+
$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 }
73+
74+
# Push packages to nuget
75+
Write-Output "Pushing $project packages"
76+
$packages = Get-ChildItem "$project*.nupkg" | Select-Object -ExpandProperty Name
77+
78+
foreach ($package in $packages) {
79+
$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 }
80+
}
81+
}
82+
83+
# Archive the packages
84+
Move-Item "$scriptDir\*.nupkg","$scriptDir\*.snupkg" $archive -force
85+
} else {
86+
Write-Error "$corePackage didn't appear on NuGet within 10 minutes."
87+
}

nuget/push.bat

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)