This repository was archived by the owner on Jan 14, 2025. It is now read-only.
forked from kunzimariano/VersionOne.Build.Common
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVersionOne.Build.Common.ps1
More file actions
168 lines (138 loc) · 4.48 KB
/
VersionOne.Build.Common.ps1
File metadata and controls
168 lines (138 loc) · 4.48 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
properties {
$config = Get-ConfigObject
$version = Get-Version
}
#groups of tasks
task default -depends local
task local -depends restoreAndUpdatePackages,build,runUnitTests,runExtensions
task jenkins -depends restoreAndUpdatePackages,build,runUnitTests,pushMyget,runExtensions
#tasks
task validateInput {
#TODO: validate build.properties.json
}
task build -depends clean,setAssemblyInfo {
$solution = $config.solution
$configuration = $config.configuration
$platform = $config.platform
exec { msbuild $solution -t:Build -p:Configuration=$configuration "-p:Platform=$platform" }
}
task clean {
$solution = $config.solution
$configuration = $config.configuration
$platform = $config.platform
exec { msbuild $solution -t:Clean -p:Configuration=$configuration "-p:Platform=$platform" }
}
task publish{
$project = $config.projectToPublish
$configuration = $config.configuration
exec { msbuild $project -t:Publish -p:Configuration=$configuration }
}
task restoreAndUpdatePackages {
exec { .\\.nuget\nuget.exe restore $config.solution -Source $config.nugetSources }
exec { .\\.nuget\nuget.exe update $config.solution -Source $config.nugetSources }
}
task setAssemblyInfo{
Update-AssemblyInfo
}
task setUpNuget {
New-NugetDirectory
Get-NugetBinary
}
task generateNugetPackage{
$project = $config.projectToPackage
$configuration = $config.configuration
exec { .\\.nuget\nuget.exe pack $project -Verbosity Detailed -Version $version -prop Configuration=$configuration }
}
task pushMyget -depends GenerateNugetPackage{
exec { .\\.nuget\nuget.exe push *.nupkg $env:MYGET_API_KEY -Source $env:MYGET_REPO_URL }
}
task installNunitRunners{
exec { .\\.nuget\nuget.exe install NUnit.Runners -OutputDirectory packages }
}
task runUnitTests -depends installNunitRunners{
$testRunner = Get-NewestFilePath "nunit-console-x86.exe"
$configuration = $config.configuration
(ls -r *.Tests.dll) | where { $_.FullName -like "*\bin\Release\*.Tests.dll" } | foreach {
$fullName = $_.FullName
exec { iex "$testRunner $fullName" }
}
}
task runExtensions{
ls build-ex.*.ps1 | sort | foreach{
if ($_ -like "*.script.*") {
Write-Host "The next extension has been loaded: $_ " -ForegroundColor green
& $_
}
}
}
#helpers
function Get-ConfigObject(){
Get-Content .\build.properties.json -Raw | ConvertFrom-Json
}
function Get-EnvironmentVariableOrDefault([string] $variable, [string]$default){
if([Environment]::GetEnvironmentVariable($variable))
{
[Environment]::GetEnvironmentVariable($variable)
}
else
{
$default
}
}
function Get-NewestFilePath([string]$file){
$paths = @(Get-ChildItem -r -Path packages -filter $file | Sort-Object FullName -descending)
$paths[0].FullName
}
function New-NugetDirectory(){
new-item (Get-Location).Path -name .nuget -type directory -force
}
function Get-NugetBinary (){
$destination = (Get-Location).Path + '\.nuget\nuget.exe'
Invoke-WebRequest -Uri "http://nuget.org/nuget.exe" -OutFile $destination
}
function Update-AssemblyInfo(){
$versionPattern = 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
$versionAssembly = 'AssemblyVersion("' + $version + '")';
$versionFilePattern = 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
$versionAssemblyFile = 'AssemblyFileVersion("' + $version + '")';
Get-ChildItem -r -filter AssemblyInfo.cs |
Update-Assemblies
Get-ChildItem -r -filter AssemblyInfo.fs |
Update-Assemblies
}
function Update-Assemblies() {
param(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[object[]]
$files
)
process
{
foreach ($file in $files)
{
Write-Host Updating file $file.FullName
$tmp = ($file.FullName + ".tmp")
if (test-path ($tmp)) { remove-item $tmp }
(get-content $file.FullName) |
% {$_ -replace $versionFilePattern, $versionAssemblyFile } |
% {$_ -replace $versionPattern, $versionAssembly } > $tmp
if (test-path ($file.FullName)) { remove-item $file.FullName }
move-item $tmp $file.FullName -force
}
}
}
function Get-Version(){
#TODO: refactor all this
$year = (get-date).ToUniversalTime().ToString("yy")
$hourMinute = (get-date).ToUniversalTime().ToString("HHmm")
$buildNumber = Get-EnvironmentVariableOrDefault "BUILD_NUMBER" $hourMinute
$dayOfyear = (get-date).DayOfYear
if(([string]$dayOfyear).Length -eq 1){
$dayOfyear= "00" + $dayOfyear
}
elseif(([string]$dayOfyear).Length -eq 2){
$dayOfyear = "0" + $dayOfyear
}
$config.major + "." + $config.minor + "." + $year + $dayOfyear + "." + $buildNumber
}