forked from jchannon/OwinHttpMessageHandler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.ps1
96 lines (83 loc) · 3.32 KB
/
default.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
properties {
$projectName = "OwinHttpMessageHandler"
$buildNumber = 0
$rootDir = Resolve-Path .\
$buildOutputDir = "$rootDir\build"
$reportsDir = "$buildOutputDir\reports"
$srcDir = "$rootDir\src"
$solutionFilePath = "$srcDir\$projectName.sln"
$assemblyInfoFilePath = "$srcDir\SharedAssemblyInfo.cs"
$nugetPath = "$srcDir\.nuget\nuget.exe"
}
task default -depends UpdateVersion, CreateNuGetPackages
task Clean {
Remove-Item $buildOutputDir -Force -Recurse -ErrorAction SilentlyContinue
exec { msbuild /nologo /verbosity:quiet $solutionFilePath /t:Clean }
}
task UpdateVersion {
$version = Get-Version $assemblyInfoFilePath
$oldVersion = New-Object Version $version
$newVersion = New-Object Version ($oldVersion.Major, $oldVersion.Minor, $oldVersion.Build, $buildNumber)
Update-Version $newVersion $assemblyInfoFilePath
}
task Compile -depends Clean {
exec { msbuild /nologo /verbosity:quiet $solutionFilePath /p:Configuration=Release }
}
task RunTests -depends Compile {
$xunitRunner = "$srcDir\packages\xunit.runner.console.2.1.0\tools\xunit.console.exe"
gci . -Recurse -Include *Tests.csproj, Tests.*.csproj | % {
$project = $_.BaseName
if(!(Test-Path $reportsDir\xUnit\$project)){
New-Item $reportsDir\xUnit\$project -Type Directory
}
.$xunitRunner "$srcDir\$project\bin\Release\$project.dll"
}
}
task BuildDnx {
&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}
dnvm upgrade
pushd
cd .\src
dnu restore
dnu build .\OwinHttpMessageHandler --configuration Release
dnu pack .\OwinHttpMessageHandler --configuration Release --out $buildOutputDir
dnu build .\OwinHttpMessageHandler.Tests --configuration Release
dnx .\OwinHttpMessageHandler.Tests test
popd
}
task CreateNuGetPackages -depends Compile {
if(!(Test-Path $buildOutputDir)){
New-Item $buildOutputDir -Type Directory
}
$versionString = Get-Version $assemblyInfoFilePath
$version = New-Object Version $versionString
$packageVersion = $version.Major.ToString() + "." + $version.Minor.ToString() + "." + $version.Build.ToString() + "-build" + $buildNumber.ToString().PadLeft(5,'0')
gci $srcDir -Recurse -Include *.nuspec | % {
exec { .$srcDir\.nuget\nuget.exe pack $_ -o $buildOutputDir -version $packageVersion }
}
}
function Get-Version
{
param
(
[string]$assemblyInfoFilePath
)
Write-Host "path $assemblyInfoFilePath"
$pattern = '(?<=^\[assembly\: AssemblyVersion\(\")(?<versionString>\d+\.\d+\.\d+\.\d+)(?=\"\))'
$assmblyInfoContent = Get-Content $assemblyInfoFilePath
return $assmblyInfoContent | Select-String -Pattern $pattern | Select -expand Matches |% {$_.Groups['versionString'].Value}
}
function Update-Version
{
param
(
[string]$version,
[string]$assemblyInfoFilePath
)
$newVersion = 'AssemblyVersion("' + $version + '")';
$newFileVersion = 'AssemblyFileVersion("' + $version + '")';
$tmpFile = $assemblyInfoFilePath + ".tmp"
Get-Content $assemblyInfoFilePath |
%{$_ -replace 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', $newFileVersion } | Out-File -Encoding UTF8 $tmpFile
Move-Item $tmpFile $assemblyInfoFilePath -force
}