forked from EventStore/EventStore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventstore.ps1
150 lines (128 loc) · 5.65 KB
/
eventstore.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
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
# Event Store Build (.NET/Windows) - eventstore.ps1
# Use Invoke-psake ? to see further description
Framework "4.0x64"
Task default -depends ?
Task ? -description "Writes script documentation to the host" {
Write-Host "Builds the managed part of the Event Store"
}
# Version and other metadata
Properties {
$versionString = "0.0.0.0"
$productName = "Event Store Open Source"
$companyName = "Event Store LLP"
$copyright = "Copyright 2012 Event Store LLP. All rights reserved."
}
# Directories
Properties {
$baseDirectory = Resolve-Path .
$srcDirectory = Join-Path $baseDirectory (Join-Path "src" "EventStore")
$libsDirectory = Join-Path $srcDirectory "libs"
#For now we'll use the output directories as configured in the solution. TODO: Change this.
#$outputDirectory = Join-Path $baseDirectory "bin\"
}
# Project Files
Properties {
$eventStoreSolution = Join-Path $srcDirectory "EventStore.sln"
}
# Fallback platform/configuration (should be overriden by invoke-psake)
Properties {
if ($platform -eq $null) {
$platform = "Any CPU" #
}
if ($configuration -eq $null) {
$configuration = "Release"
}
if ($defines -eq $null) {
$definesCommandLine = ""
} else {
$definesCommandLine = "/p:AppendedDefineConstants=$defines"
}
}
Task Build-EventStore {
try {
Invoke-Task Patch-AssemblyInfos
#TODO: put back in /p:OutDir=$outputDirectory
Exec { msbuild $eventStoreSolution /p:Configuration=$configuration /p:Platform=$platform $definesCommandLine }
} finally {
Invoke-Task Revert-AssemblyInfos
}
}
Task Patch-AssemblyInfos {
Push-Location $baseDirectory
$commitHashAndTimestamp = Get-GitCommitHashAndTimestamp
$branchName = Get-GitBranchOrTag
$assemblyInfos = Get-ChildItem -Recurse -Filter AssemblyInfo.cs
foreach ($assemblyInfo in $assemblyInfos) {
$path = Resolve-Path $assemblyInfo.FullName -Relative
Write-Verbose "Patching $path with product information."
Patch-AssemblyInfo $path $versionString $versionString $branchName $commitHashAndTimestamp $productName $companyName $copyright
}
Pop-Location
}
Task Revert-AssemblyInfos {
Push-Location $baseDirectory
$assemblyInfos = Get-ChildItem -Recurse -Filter AssemblyInfo.cs
foreach ($assemblyInfo in $assemblyInfos) {
$path = Resolve-Path $assemblyInfo.FullName -Relative
Write-Verbose "Reverting $path to original state."
& { git checkout --quiet $path }
}
Pop-Location
}
#Helper functions
Function Get-GitCommitHashAndTimestamp
{
$lastCommitLog = Exec { git log --max-count=1 --pretty=format:%H@%aD HEAD } "Cannot execute git log. Ensure that the current directory is a git repository and that git is available on PATH."
return $lastCommitLog
}
Function Get-GitBranchOrTag
{
$revParse = Exec { git rev-parse --abbrev-ref HEAD } "Cannot execute git rev-parse. Ensure that the current directory is a git repository and that git is available on PATH."
if ($revParse -ne "HEAD") {
return $revParse
}
$describeTags = Exec { git describe --tags } "Cannot execute git describe. Ensure that the current directory is a git repository and that git is available on PATH."
return $describeTags
}
Function Patch-AssemblyInfo {
Param(
[Parameter(Mandatory=$true)][string]$assemblyInfoFilePath,
[Parameter(Mandatory=$true)][string]$version,
[Parameter(Mandatory=$true)][string]$fileVersion,
[Parameter(Mandatory=$true)][string]$branch,
[Parameter(Mandatory=$true)][string]$commitHashAndTimestamp,
[Parameter(Mandatory=$true)][string]$productName,
[Parameter(Mandatory=$true)][string]$companyName,
[Parameter()][string]$copyright
)
Process {
$newAssemblyVersion = 'AssemblyVersion("' + $version + '")'
$newAssemblyFileVersion = 'AssemblyFileVersion("' + $fileVersion + '")'
$newAssemblyVersionInformational = 'AssemblyInformationalVersion("' + $version + '.' + $branch + '@' + $commitHashAndTimestamp + '")'
$newAssemblyProductName = 'AssemblyProduct("' + $productName + '")'
$newAssemblyCopyright = 'AssemblyCopyright("'+ $copyright + '")'
$newAssemblyCompany = 'AssemblyCompany("' + $companyName + '")'
$assemblyVersionPattern = 'AssemblyVersion\(".*"\)'
$assemblyFileVersionPattern = 'AssemblyFileVersion\(".*"\)'
$assemblyVersionInformationalPattern = 'AssemblyInformationalVersion\(".*"\)'
$assemblyProductNamePattern = 'AssemblyProduct\(".*"\)'
$assemblyCopyrightPattern = 'AssemblyCopyright\(".*"\)'
$assemblyCompanyPattern = 'AssemblyCompany\(".*"\)'
$edited = (Get-Content $assemblyInfoFilePath) | ForEach-Object {
% {$_ -replace "\/\*+.*\*+\/", "" } |
% {$_ -replace "\/\/+.*$", "" } |
% {$_ -replace "\/\*+.*$", "" } |
% {$_ -replace "^.*\*+\/\b*$", "" } |
% {$_ -replace $assemblyVersionPattern, $newAssemblyVersion } |
% {$_ -replace $assemblyFileVersionPattern, $newAssemblyFileVersion } |
% {$_ -replace $assemblyVersionInformationalPattern, $newAssemblyVersionInformational } |
% {$_ -replace $assemblyProductNamePattern, $newAssemblyProductName } |
% {$_ -replace $assemblyCopyrightPattern, $newAssemblyCopyright } |
% {$_ -replace $assemblyCompanyPattern, $newAssemblyCompany }
}
if (!(($edited -match $assemblyVersionInformationalPattern) -ne "")) {
$edited += "[assembly: $newAssemblyVersionInformational]"
}
Set-Content -Path $assemblyInfoFilePath -Value $edited
}
}