Last active
August 29, 2015 13:56
-
-
Save grenade/4d248e9ea8f6b5e7636a to your computer and use it in GitHub Desktop.
A build initialization script for LibGit2Sharp nuget publish job
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[string] $file, # path to symbols .nupkg | |
[string[]] $exclude # files to be removed | |
) | |
$global:exclude = $exclude | |
$shell = New-Object -com shell.application | |
function Traverse { | |
param( | |
[object] $shell, | |
[object] $items, | |
[int] $indent = 0 | |
) | |
foreach ($item in $items) { | |
$tab = "" | |
for ($i = 0; $i -lt $indent; $i ++){ | |
$tab += " " | |
} | |
Write-Host ("{0}{1}" -f $tab, $item.Name) | |
if ($item.GetFolder -ne $null) { | |
Traverse $shell $item.GetFolder.items() ($indent + 1) | |
} | |
elseif ($global:exclude -Contains $item.Name) { | |
Write-Host ("{0}Removing file: {1} from {2}." -f $tab, $item.Name, $zip) -f Red | |
$shell.NameSpace($env:TEMP).MoveHere($item) | |
Remove-Item (Join-Path $env:TEMP $item.Name) | |
} | |
} | |
} | |
$zip = $file.Replace(".nupkg", ".zip") | |
Write-Host ("Creating temporary file: {0} from {1}." -f $zip, $file) | |
if (Test-Path $zip) { | |
Remove-Item $zip | |
} | |
Move-Item $file $zip | |
Traverse $shell $shell.NameSpace($zip).Items() | |
Write-Host ("Recreating package: {0} from {1}." -f $file, $zip) | |
Move-Item $zip $file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[string] $shaHash, # "%build.vcs.number%" | |
[string] $baseDir, # "%teamcity.build.checkoutDir%" | |
[string] $nugetExe, # "%teamcity.tool.NuGet.CommandLine.DEFAULT.nupkg%\tools\NuGet.exe" | |
[string] $nuspecSource = ("{0}\nuget.package\LibGit2Sharp.nuspec" -f $baseDir), | |
[string] $nuspecTarget = ("{0}\LibGit2Sharp\LibGit2Sharp.nuspec" -f $baseDir), | |
[string] $assemblyInfoFile = ("{0}\LibGit2Sharp\Properties\AssemblyInfo.cs" -f $baseDir), | |
[string] $versionSuffix = "-vNext", | |
[string] $nugetSource = "https://www.nuget.org/api/v2" | |
) | |
Write-Host ("`$assemblyInfoFile: {0}" -f $assemblyInfoFile) | |
Write-Host ("`$nugetSource: {0}" -f $nugetSource) | |
$assemblyInfo = Get-Content $assemblyInfoFile | |
$assemblyVersion = ($assemblyInfo | Select-String -Pattern '^\[assembly: AssemblyVersion\("([0-9]+(\.([0-9]+|\*)){1,3})"\)\]' | % { $_.Matches } ).Groups[1].Value | |
Write-Host ("`$assemblyVersion: {0}" -f $assemblyVersion) | |
Write-Host ("`$versionSuffix: {0}" -f $versionSuffix) | |
$major, $minor, $patch = $assemblyVersion.Split(".") | |
$oldPatch = $patch | |
(& $nugetExe list Libgit2Sharp -AllVersions -Source 'https://www.nuget.org/api/v2') | Where { $_.StartsWith(("LibGit2Sharp {0}.{1}" -f $major, $minor)) } | % { if (([int]($_.Split(" ")[1].Split(".")[2])) -ge ([int]$patch)) { $patch = ([int]($_.Split(" ")[1].Split(".")[2])) + 1 } } | |
if (([int]$oldPatch) -ne ([int]$patch)) { | |
$newAssemblyVersion = ("{0}.{1}.{2}" -f $major, $minor, $patch) | |
Write-Host ("Incrementing assembly version patch number from '{0}' to '{1}'." -f $assemblyVersion, $newAssemblyVersion) | |
$assemblyInfo | ForEach-Object { % {$_ -Replace $assemblyVersion, $newAssemblyVersion } } | Set-Content $assemblyInfoFile | |
$assemblyVersion = $newAssemblyVersion | |
} | |
if ((& $nugetExe list LibGit2Sharp -AllVersions -Source $nugetSource) | Where { $_ -eq ("LibGit2Sharp {0}{1}" -f $assemblyVersion, $versionSuffix) }) { | |
Write-Error ("NuGet repository at nuget.org already hosts a LibGit2Sharp package with current MAJOR.MINOR.PATCH version ({0}). Update assembly info in source repository and retry." -f $assemblyVersion) | |
Write-Host ("##teamcity[buildStatus status='FAILURE']") | |
exit 1 | |
} | |
$assemblyTitle = ($assemblyInfo | Select-String -Pattern '^\[assembly: AssemblyTitle\("(.*)"\)\]' | % { $_.Matches } ).Groups[1].Value | |
Write-Host ("`$assemblyTitle: {0}" -f $assemblyTitle) | |
$assemblyDescription = ($assemblyInfo | Select-String -Pattern '^\[assembly: AssemblyDescription\("(.*)"\)\]' | % { $_.Matches } ).Groups[1].Value | |
Write-Host ("`$assemblyDescription: {0}" -f $assemblyDescription) | |
$assemblyCompany = ($assemblyInfo | Select-String -Pattern '^\[assembly: AssemblyCompany\("(.*)"\)\]' | % { $_.Matches } ).Groups[1].Value | |
Write-Host ("`$assemblyCompany: {0}" -f $assemblyCompany) | |
Write-Host ("##teamcity[buildNumber '{0}']" -f $assemblyVersion) | |
Set-Content .\LibGit2Sharp\libgit2sharp_hash.txt $shaHash | |
if(Test-Path $nuspecTarget) { | |
Remove-Item $nuspecTarget | |
} | |
Write-Host ("Copying {0} to {1}" -f $nuspecSource, $nuspecTarget) | |
Copy-Item $nuspecSource $nuspecTarget |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment