-
Notifications
You must be signed in to change notification settings - Fork 3
/
fdb_custom.ps1
215 lines (191 loc) · 7.68 KB
/
fdb_custom.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
param(
[Parameter(Mandatory = $true)][string]$RunId,
[Parameter(Mandatory = $true)][string]$SlackPath,
[Parameter(Mandatory = $true)][string]$PullRequest
)
class PullRequest{
[string]$Id
[string]$Title
}
function LogTime {
$(Get-Date -Format "HH:mm:ss")
}
function TraceLine {
param(
[Parameter(Mandatory = $true)][string]$Line
)
Write-Output "$(LogTime) $Line" >> $LogFile
}
function Run {
param(
[switch]$SkipErrors = $false,
[Parameter(Mandatory = $true)][string]$Command
)
TraceLine "Runnning command: $Command"
Invoke-Expression -Command "$Command" 2>&1 | Out-File -Append -FilePath $LogFile
if($LASTEXITCODE -ne 0){
TraceLine "Command failed with code: $LASTEXITCODE"
$global:SubcommandFailed = $true
if($SkipErrors){
TraceLine "Command failure ignored"
}else {
throw "Command failed with code: $LASTEXITCODE"
}
}
}
function RunPS {
param(
[Parameter(Mandatory = $true)][string]$Command
)
TraceLine "Runnning command: $Command"
Invoke-Expression -Command "$Command 2>&1 | Out-File -Append -FilePath $LogFile"
if(!$?){
TraceLine "PS Command failed"
$global:SubcommandFailed = $true
throw "PS Command failed"
}
}
function BuildMainBranch{
param(
[Parameter(Mandatory = $true)][string]$Branch
)
RunPS -Command "Set-Location $BuildDir"
RunPS -Command "Remove-Item "".\foundationdb"" -Recurse -Force -Confirm:`$false -ErrorAction Ignore"
Run -Command "git clone https://github.com/apple/foundationdb/"
$LogFileName = "fdb-windows-build.$Branch.$(Get-Date -Format "yyyy-MM-dd").log"
RunPS -Command "Set-Location $SourceDir"
Run -Command "git switch $Branch"
Run -Command "git pull"
$CommitId = git log --format="%H" -n 1
$SubCommitId = $CommitId.Substring(0,6)
TraceLine "Commit id: $CommitId"
$global:BranchLogFile = "$global:LogDir\$LogFileName"
try{
Build
$global:MainSlackText = "$global:MainSlackText\u2714 $Branch (``<$CommitPath/$CommitId|$SubCommitId>``): *SUCCEEDED*\n"
}
catch{
$global:MainSlackText = "$global:MainSlackText\u274C $Branch (``<$CommitPath/$CommitId|$SubCommitId>``): *FAILED*\n"
}
$global:LogFile = $global:MainLogFile
}
function BuildPRs{
param(
[Parameter(Mandatory = $true)][PullRequest]$PR
)
RunPS -Command "Set-Location $BuildDir"
RunPS -Command "Remove-Item $SourceDir -Recurse -Force -Confirm:`$false -ErrorAction Ignore"
$LogFileName = "fdb-windows-build.pr$($PR.Id).$(Get-Date -Format "yyyy-MM-dd").log"
Run -Command "git clone $FDBRepos"
RunPS -Command "Set-Location $SourceDir"
try{
Run -Command "gh pr checkout $($PR.Id)"
Run -Command "git pull"
}
catch{
TraceLine "Cannot checkout the pull request #$($PR.Id)"
return
}
#gh pr checkout $PR.Id
$CommitId = git log --format="%H" -n 1
$SubCommitId = $CommitId.Substring(0,6)
TraceLine "Commit id: $CommitId"
$global:BranchLogFile = "$global:LogDir\$LogFileName"
try{
Build
$global:PRsSlackText = "$global:PRsSlackText\u2714 <$PRPath/$($PR.Id)|#$($PR.Id)> (``<$CommitPath/$CommitId|$SubCommitId>``): $($PR.Title)\n"
}
catch{
$global:PRsSlackText = "$global:PRsSlackText\u274C <$PRPath/$($PR.Id)|#$($PR.Id)> (``<$CommitPath/$CommitId|$SubCommitId>``): $($PR.Title)\n"
}
$global:LogFile = $global:MainLogFile
}
function Build{
RunPS -Command "Remove-Item $SolutionDir -Recurse -Force -Confirm:`$false -ErrorAction Ignore"
RunPS -Command "New-Item -ItemType ""directory"" -Path $SolutionDir -ErrorAction Ignore"
RunPS -Command "Set-Location $SolutionDir"
$global:LogFile = $global:BranchLogFile
Run -Command "cmake -G ""Visual Studio 16 2019"" -A x64 -T ClangCL -DBOOST_ROOT=$BuildDir\boost_1_76_0 $SourceDir"
Run -Command "msbuild /p:CL_MPCount=32 /p:UseMultiToolTask=true /p:Configuration=Release foundationdb.sln"
}
$global:BuildDir = Get-Location
$global:SourceDir = "$BuildDir\foundationdb"
$global:SolutionDir = "$BuildDir\build"
$global:LogDir = "$BuildDir\build_logs"
$global:FDBRepos = "https://github.com/apple/foundationdb/"
$global:CommitPath = "https://github.com/apple/foundationdb/commit"
$global:PRPath = "https://github.com/apple/foundationdb/pull"
$global:LogPath = "https://github.com/Doxense/foundationdb-windows-build/actions/runs/$RunId"
$global:MainLogFile = "$BuildDir\..\build_history\fdb-nightlies-build.$(Get-Date -Format "yyyy-MM-dd").log"
$global:BranchLogFile
$global:LogFile = $global:MainLogFile
$global:MainSlackText = ""
$global:PrsSLackText = ""
$global:SubcommandFailed
# Prepare build environment
New-Item -ItemType "directory" -Path $BuildDir\..\build_history -ErrorAction Ignore
RunPS -Command "Set-Location $BuildDir"
RunPS -Command "Remove-Item $global:LogDir -Recurse -Force -Confirm:`$false -ErrorAction Ignore"
RunPS -Command "New-Item -ItemType ""directory"" -Path $global:LogDir -ErrorAction Ignore"
# Download boost
RunPS -Command "Set-Location $BuildDir"
RunPS -Command "Invoke-WebRequest ""https://boostorg.jfrog.io/ui/api/v1/download?repoKey=main&path=release%252F1.76.0%252Fsource%252Fboost_1_76_0.7z"" -OutFile $BuildDir\boost_1_76_0.7z"
If ((Get-FileHash $BuildDir\boost_1_76_0.7z).Hash -ne "88782714F8701B6965F3FCE087A66A1262601DD5CCD5B2E5305021BEB53042A1") {
Write-Output "boost hash does not match the expected value!"
exit 1
}
Run -Command "7z x -y $BuildDir\boost_1_76_0.7z"
# Build main branches
# BuildMainBranch -Branch master
# BuildMainBranch -Branch release-7.0
# BuildMainBranch -Branch release-6.3
# Build pull requests
RunPS -Command "Set-Location $global:BuildDir"
RunPS -Command "Remove-Item $global:SourceDir -Recurse -Force -Confirm:`$false -ErrorAction Ignore"
Run -Command "git clone $FDBRepos"
RunPS -Command "Set-Location $SourceDir"
$PullRequests = New-Object Collections.Generic.List[PullRequest]
$PRsList = (gh pr list -s open --limit 1000)
foreach($PR in $PRsList){
$SplittedPR = ConvertFrom-String $PR -Delimiter "`t"
$PRObj = [PullRequest]::new()
$PRObj.Id = $SplittedPR.P1
$PRObj.Title = $SplittedPR.P2
if($PRObj.Title.Length -gt 36){
$Subtitle = $PRObj.Title.Substring(0, 32).Trim()
$PRObj.Title = "$Subtitle ..."
}
$PullRequests.Add($PRObj)
}
$RecentPRs = New-Object Collections.Generic.List[PullRequest]
foreach($PR in $PullRequests) {
if($PR.Id -eq $PullRequest){
$RecentPRs.Add($PR)
}
}
TraceLine "Building the folowing pull requests"
foreach($PR in $RecentPRs){
TraceLine "$($PR.Id): $($PR.Title)"
}
foreach($PR in $RecentPRs){
BuildPRs $PR
}
if($global:PRsSlackText.Length -eq 0){
$global:PRsSlackText = "\u2714 No new pull request to build"
}
$SlackMessageTemplate = "$BuildDir\sources\skack_message_template.json"
$SlackMessage = Get-Content $SlackMessageTemplate
$global:MainSlackText = $global:MainSlackText -replace "master", "master "
$SlackMessage = $SlackMessage -replace "main-text", $global:MainSlackText
$SlackMessage = $SlackMessage -replace "pr-text", $global:PRsSlackText
$SlackMessage = $SlackMessage -replace "log-text", "Build logs available <$global:LogPath|here> for 90 days"
Write-Output [string]$SlackMessage
# Post build results to Slack
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
#RunPS -Command "Invoke-RestMethod `$SlackPath -Method 'POST' -Headers `$headers -Body `$SlackMessage"
RunPS -Command "Set-Location ""$BuildDir"""
if($SubcommandFailed){
Write-Output "Nightlies process completed, but one or several builds failed"
exit 1
}