-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.ps1
76 lines (65 loc) · 2.08 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<#
.SYNOPSIS
A psake bootstraper; This script runs one or more tasks defined in the psake file.
.EXAMPLE
.\build.ps1 -Help;
This example prints a list of all the available tasks.
#>
Param(
[ValidateNotNullorEmpty()]
[string[]]$Tasks = @("default"),
[Alias('f')]
[string]$Filter = "*",
[Alias('no-commit')]
[switch]$SkipCommit,
[Alias('h', '?')]
[switch]$Help,
[Alias('d', "dry")]
[switch]$DryRun,
[switch]$Debug,
[switch]$Major,
[switch]$Minor,
[switch]$Force
)
# Initializing required variables.
$Configuration = "Release";
if ($Debug) { $Configuration = "Debug"; }
# Getting the current branch of source control.
$branchName = $env:BUILD_SOURCEBRANCHNAME;
if ([string]::IsNullOrEmpty($branchName))
{
$match = [Regex]::Match((& git branch), '\*\s*(?<name>\w+)');
if ($match.Success) { $branchName = $match.Groups["name"].Value; }
}
# Installing then invoking the Psake tasks.
$toolsFolder = Join-Path $PSScriptRoot "tools";
$psakeModule = Join-Path $toolsFolder "psake/*/*.psd1";
if (-not (Test-Path $psakeModule))
{
if (-not (Test-Path $toolsFolder)) { New-Item $toolsFolder -ItemType Directory | Out-Null; }
Save-Module "psake" -Path $toolsFolder;
}
Import-Module $psakeModule -Force;
$taskFile = Join-Path $PSScriptRoot "build/tasks.psake.ps1";
if ($Help) { Invoke-Psake -buildFile $taskFile -docs; }
else
{
Write-Host -ForegroundColor DarkGray "User: $([Environment]::UserName)@$([Environment]::MachineName)";
Write-Host -ForegroundColor DarkGray "Platform: $([Environment]::OSVersion.Platform)";
Write-Host -ForegroundColor DarkGray "Branch: $branchName";
Write-Host -ForegroundColor DarkGray "Configuration: $Configuration";
Write-Host "";
Invoke-psake $taskFile -nologo -taskList $Tasks -properties @{
"Filter"=$Filter;
"Major"=$Major.IsPresent;
"Minor"=$Minor.IsPresent;
"Force"=$Force.IsPresent;
"DryRun"=$DryRun.IsPresent;
"ToolsFolder"=$toolsFolder;
"CurrentBranch"=$branchName;
"Configuration"=$Configuration;
"SolutionFolder"=$PSScriptRoot;
"ShouldCommitChanges"=(-not $SkipCommit.IsPresent);
}
if (-not $psake.build_success) { exit 1; }
}