-
Notifications
You must be signed in to change notification settings - Fork 1
/
Build.psm1
56 lines (47 loc) · 1.93 KB
/
Build.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function HashToRevision([string] $hash){
$longHash = [Int32]::Parse($hash.Substring(0,4), [System.Globalization.NumberStyles]::HexNumber)
#AssemblyVersionAttribute does not support revisions greater than 2**16 - 2
if($longHash -le 65534) {
return $longHash
} else {
return [Int32]::Parse($hash.Substring(0,3), [System.Globalization.NumberStyles]::HexNumber)
}
}
function TestVersionTag([string] $tag) {
$tag -Match '^v\.\d\.\d{1,2}\.\d{1,3}$'
}
function SetVersion([string] $projectFile, [string] $newVersion){
Write-Host "Setting csproj version"
[xml]$xml = Get-Content $projectFile
$propertyGroups = $xml.Project.PropertyGroup
foreach ($pg in $xml.Project.PropertyGroup | Where-Object {$_.Version -ne $null -and $_.PackageId -ne $Null}) {
$pg.Version = $newVersion
}
$xml.Save($projectFile)
}
function SetReleaseVariable($newVersion){
Write-Host "Updating Build variables"
Set-AppveyorBuildVariable -Name "DeployArtifacts" -Value "true"
Set-AppveyorBuildVariable -Name "ReleaseVersion" -Value $newVersion
}
function PrepareRelease([string] $projectFile){
$commitHashInt = HashToRevision $env:APPVEYOR_REPO_COMMIT
Write-Host "Preparing release"
Write-Host "APPVEYOR_REPO_TAG: $($env:APPVEYOR_REPO_TAG)"
Write-Host "APPVEYOR_REPO_TAG_NAME: $($env:APPVEYOR_REPO_TAG_NAME)"
if ($env:APPVEYOR_REPO_TAG -eq "true" -and (TestVersionTag $env:APPVEYOR_REPO_TAG_NAME)) {
$newVersion = "$($env:APPVEYOR_REPO_TAG_NAME.TrimStart("v.")).$commitHashInt"
Write-Host "New release $($newVersion)"
Update-AppveyorBuild -Version $newVersion
SetVersion $projectFile $newVersion
SetReleaseVariable $newVersion
}
else
{
Update-AppveyorBuild -Version "$($env:APPVEYOR_BUILD_VERSION).$commitHashInt"
}
}
function Set-ReleaseInformation($projectFile){
PrepareRelease $projectFile
}
Export-ModuleMember -Function *-*