-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
45 lines (35 loc) · 2.09 KB
/
build.ps1
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
[CmdletBinding(PositionalBinding = $false)]
param(
[string] $Configuration = "Release",
[string] $BuildNumber
)
Push-Location $PSScriptRoot
$envBranch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $env:BUILD_SOURCEBRANCHNAME}[$env:APPVEYOR_REPO_BRANCH -ne $NULL]
$envBuildNumber = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = $BuildNumber}[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]
$packageOutputFolder = "$PSScriptRoot\package"
$branch = @{ $true = $envBranch; $false = $(git symbolic-ref --short -q HEAD) }[$envBranch -ne $NULL];
$autoVersion = [math]::floor((New-TimeSpan $(Get-Date) $(Get-Date -month 1 -day 1 -year 2016 -hour 0 -minute 0 -second 0)).TotalMinutes * -1).ToString() + "-" + (Get-Date).ToString("ss")
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $envBuildNumber, 10); $false = "0-local-$autoVersion" }[$envBuildNumber -ne $NULL -and $envBuildNumber -ne ""];
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and -not $revision.StartsWith("local")]
$packSuffix = @{ $true=""; $false="--version-suffix=$suffix"}[$suffix -eq ""]
$commitHash = $(git rev-parse --short HEAD)
$buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""]
Write-Host "build: Branch is $branch"
Write-host "build: Revision is $revision"
Write-Host "build: Suffix is $suffix"
Write-Host "build: Package version suffix is $packSuffix"
Write-Host "build: Build version suffix is $buildSuffix"
Write-Host "build: Configuration = $Configuration"
Write-Host "Cleaning anything old"
dotnet clean -c $Configuration
Write-Host "Building"
mkdir -Force $packageOutputFolder | Out-Null
Get-ChildItem $packageOutputFolder | Remove-Item -Recurse
dotnet publish -c $Configuration --version-suffix=$buildSuffix --output $packageOutputFolder
if ($LastExitCode -ne 0) {
Write-Host "Error with build, aborting build." -Foreground "Red"
Exit 1
}
Compress-Archive -Force -Path $packageOutputFolder -DestinationPath $PSScriptRoot\azure-file-uploader-$packSuffix.zip
Write-Host "Complete"
Pop-Location