Skip to content

Commit 773797b

Browse files
committed
Work CI-CD
- Remove wrong code in build from commit snippet. - Fix code style in PS1 script.
1 parent 77ea1b5 commit 773797b

File tree

1 file changed

+115
-118
lines changed

1 file changed

+115
-118
lines changed

.pipeline-assets/build-solutions.ps1

+115-118
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,35 @@ $auth = "basic $([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.G
1717

1818
if($env:System_PullRequest_PullRequestId -ne $null)
1919
{
20-
"" | Write-Host -ForegroundColor Yellow
21-
"**********************" | Write-Host -ForegroundColor Yellow
22-
"* Building from a PR *" | Write-host -ForegroundColor Yellow
23-
"**********************" | Write-Host -ForegroundColor Yellow
24-
"" | Write-Host -ForegroundColor Yellow
20+
"" | Write-Host -ForegroundColor Yellow
21+
"**********************" | Write-Host -ForegroundColor Yellow
22+
"* Building from a PR *" | Write-host -ForegroundColor Yellow
23+
"**********************" | Write-Host -ForegroundColor Yellow
24+
"" | Write-Host -ForegroundColor Yellow
2525

26-
# get files changed in PR
27-
$pageCounter = 1
26+
# get files changed in PR
27+
$pageCounter = 1
2828

29-
do
30-
{
31-
"##[debug] INFO: iteration $pageCounter" | Write-Host
32-
33-
34-
$batch = Invoke-RestMethod -Uri "https://api.github.com/repos/nanoframework/Samples/pulls/$env:System_PullRequest_PullRequestNumber/files?per_page=100&page=$pageCounter" -Header @{"Authorization"="$auth"} -ContentType "application/json" -Method GET
29+
do
30+
{
31+
"##[debug] INFO: iteration $pageCounter" | Write-Host
3532

36-
if($null -eq $commit)
37-
{
38-
$commit = $batch
39-
}
40-
else
41-
{
42-
$commit += $batch
43-
}
44-
45-
$pageCounter++
33+
$batch = Invoke-RestMethod -Uri "https://api.github.com/repos/nanoframework/Samples/pulls/$env:System_PullRequest_PullRequestNumber/files?per_page=100&page=$pageCounter" -Header @{"Authorization"="$auth"} -ContentType "application/json" -Method GET
4634

47-
} until ($batch.Count -eq 0)
35+
if($null -eq $commit)
36+
{
37+
$commit = $batch
38+
}
39+
else
40+
{
41+
$commit += $batch
42+
}
43+
44+
$pageCounter++
45+
} until ($batch.Count -eq 0)
4846

49-
# filter removed files
50-
$files = $commit.where{$_.status -ne 'removed'}
47+
# filter removed files
48+
$files = $commit.where{$_.status -ne 'removed'}
5149

5250
}
5351
else
@@ -58,42 +56,39 @@ else
5856
"**************************" | Write-Host -ForegroundColor Yellow
5957
"" | Write-Host -ForegroundColor Yellow
6058

61-
# get files changed in the commit, if this is NOT a PR
62-
$commit = Invoke-RestMethod -Uri "https://api.github.com/repos/nanoframework/Samples/commits/$env:Build_SourceVersion" -Header @{"Authorization"="$auth"} -ContentType "application/json" -Method GET
63-
64-
# get files changed in the commit
65-
$pageCounter = 1
59+
# get files changed in the commit
60+
$pageCounter = 1
6661

67-
do
68-
{
69-
"##[command] Get API file change page: $pageCounter" | Write-Host
62+
do
63+
{
64+
"##[command] Get API file change page: $pageCounter" | Write-Host
7065

71-
$batch = Invoke-RestMethod -Uri "https://api.github.com/repos/nanoframework/Samples/commits/$env:Build_SourceVersion`?per_page=100&page=$pageCounter" -Header @{"Authorization"="$auth"} -ContentType "application/json" -Method GET
66+
$batch = Invoke-RestMethod -Uri "https://api.github.com/repos/nanoframework/Samples/commits/$env:Build_SourceVersion`?per_page=100&page=$pageCounter" -Header @{"Authorization"="$auth"} -ContentType "application/json" -Method GET
7267

73-
if($null -eq $commit)
74-
{
75-
$commit = $batch.files
76-
}
77-
else
78-
{
79-
$commit += $batch.files
80-
}
81-
82-
$pageCounter++
68+
if($null -eq $commit)
69+
{
70+
$commit = $batch.files
71+
}
72+
else
73+
{
74+
$commit += $batch.files
75+
}
76+
77+
$pageCounter++
8378

84-
} until ($batch.files.Count -eq 0)
79+
} until ($batch.files.Count -eq 0)
8580

86-
# filter removed files
87-
$files = $commit.where{$_.status -ne 'removed' -and $_.filename -match '(devices)'}
81+
# filter removed files
82+
$files = $commit.where{$_.status -ne 'removed' -and $_.filename -match '(devices)'}
8883
}
8984

9085
# get file names only
9186
$files1 = $files | % {$_.filename} | Where-Object {$_ -match 'samples/*'}
9287

9388
if($null -eq $files1)
9489
{
95-
Write-host "No 'samples' found to build"
96-
exit
90+
Write-host "No 'samples' found to build"
91+
exit
9792
}
9893

9994
Write-host "##[group] Files changed:"
@@ -115,81 +110,83 @@ write-host "##[section] Processing samples..."
115110

116111
foreach ($folder in $sampleFolders)
117112
{
118-
"" | Write-Host -ForegroundColor Yellow
119-
"***********************" | Write-Host -ForegroundColor Yellow
120-
"##[group] Processing sample '$folder'..." | Write-Host -ForegroundColor Yellow
121-
"***********************" | Write-Host -ForegroundColor Yellow
122-
"" | Write-Host -ForegroundColor Yellow
123-
124-
try
113+
"" | Write-Host -ForegroundColor Yellow
114+
"***********************" | Write-Host -ForegroundColor Yellow
115+
"##[group] Processing sample '$folder'..." | Write-Host -ForegroundColor Yellow
116+
"***********************" | Write-Host -ForegroundColor Yellow
117+
"" | Write-Host -ForegroundColor Yellow
118+
119+
try
120+
{
121+
# try to find all solution files
122+
$solutionFiles = Get-ChildItem -Path "samples\$folder\" -Include "*.sln" -Recurse
123+
124+
if($null -eq $solutionFiles)
125125
{
126-
# try to find all solution files
127-
$solutionFiles = Get-ChildItem -Path "samples\$folder\" -Include "*.sln" -Recurse
128-
129-
if($null -eq $solutionFiles)
130-
{
131-
"" | Write-Host -ForegroundColor Red
132-
"*****************************************" | Write-Host -ForegroundColor Red
133-
"##[error] >>>ERROR: Couldn't find any solution files!" | Write-Host -ForegroundColor Red
134-
throw "Couldn't find any solution file inside '$folder'..."
135-
}
136-
else
137-
{
138-
foreach ($slnFile in $solutionFiles)
139-
{
140-
"" | Write-Host -ForegroundColor Yellow
141-
"##[command] INFO: Building solution: '$slnFile'" | Write-Host -ForegroundColor Yellow
142-
"" | Write-Host -ForegroundColor Yellow
143-
144-
# need to restore NuGets first
145-
write-host "##[command] Performing nuget restore for '$slnFile'."
146-
nuget restore $slnFile
147-
if (-not $?)
148-
{
149-
"" | Write-Host -ForegroundColor Red
150-
"*****************************************" | Write-Host -ForegroundColor Red
151-
"##[error] >>>ERROR: Couldn't restore solution: '$slnFile'!" | Write-Host -ForegroundColor Red
152-
# set flag
153-
$buildFailed = $true
154-
}
155-
156-
# build solution
157-
write-host "##[command] Running msbuild."
158-
& "$msbuild" "$slnFile" /verbosity:normal /p:Configuration=Release
159-
if (-not $?) {
160-
"" | Write-Host -ForegroundColor Red
161-
"*****************************************" | Write-Host -ForegroundColor Red
162-
"##[error] >>>ERROR: Failed building solution: '$slnFile'!" | Write-Host -ForegroundColor Red
163-
# set flag
164-
$buildFailed = $true
165-
}
166-
}
167-
}
126+
"" | Write-Host -ForegroundColor Red
127+
"*****************************************" | Write-Host -ForegroundColor Red
128+
"##[error] >>>ERROR: Couldn't find any solution files!" | Write-Host -ForegroundColor Red
129+
throw "Couldn't find any solution file inside '$folder'..."
168130
}
169-
catch
131+
else
170132
{
171-
"" | Write-Host -ForegroundColor Red
172-
"*****************************************" | Write-Host -ForegroundColor Red
173-
"##[error] >>>ERROR: build failed, check output <<<" | Write-Host -ForegroundColor Red
174-
"*****************************************" | Write-Host -ForegroundColor Red
175-
"" | Write-Host -ForegroundColor Red
176-
177-
"" | Write-Host -ForegroundColor Red
178-
"Exception was: $_" | Write-Host -ForegroundColor Red
179-
"" | Write-Host -ForegroundColor Red
180-
181-
# set flag
182-
$buildFailed = $true
183-
}
133+
foreach ($slnFile in $solutionFiles)
134+
{
135+
"" | Write-Host -ForegroundColor Yellow
136+
"##[command] INFO: Building solution: '$slnFile'" | Write-Host -ForegroundColor Yellow
137+
"" | Write-Host -ForegroundColor Yellow
138+
139+
# need to restore NuGets first
140+
write-host "##[command] Performing nuget restore for '$slnFile'."
141+
nuget restore $slnFile
142+
143+
if (-not $?)
144+
{
145+
"" | Write-Host -ForegroundColor Red
146+
"*****************************************" | Write-Host -ForegroundColor Red
147+
"##[error] >>>ERROR: Couldn't restore solution: '$slnFile'!" | Write-Host -ForegroundColor Red
148+
# set flag
149+
$buildFailed = $true
150+
}
184151

185-
write-host "##[endgroup]"
152+
# build solution
153+
write-host "##[command] Running msbuild."
154+
& "$msbuild" "$slnFile" /verbosity:normal /p:Configuration=Release
155+
156+
if (-not $?) {
157+
"" | Write-Host -ForegroundColor Red
158+
"*****************************************" | Write-Host -ForegroundColor Red
159+
"##[error] >>>ERROR: Failed building solution: '$slnFile'!" | Write-Host -ForegroundColor Red
160+
# set flag
161+
$buildFailed = $true
162+
}
163+
}
164+
}
165+
}
166+
catch
167+
{
168+
"" | Write-Host -ForegroundColor Red
169+
"*****************************************" | Write-Host -ForegroundColor Red
170+
"##[error] >>>ERROR: build failed, check output <<<" | Write-Host -ForegroundColor Red
171+
"*****************************************" | Write-Host -ForegroundColor Red
172+
"" | Write-Host -ForegroundColor Red
173+
174+
"" | Write-Host -ForegroundColor Red
175+
"Exception was: $_" | Write-Host -ForegroundColor Red
176+
"" | Write-Host -ForegroundColor Red
177+
178+
# set flag
179+
$buildFailed = $true
180+
}
181+
182+
write-host "##[endgroup]"
186183
}
187184

188185
if($buildFailed)
189186
{
190-
"********************************" | Write-Host -ForegroundColor Red
191-
"##[error] Check >>>ERROR<<< messages above" | Write-Host -ForegroundColor Red
192-
"********************************" | Write-Host -ForegroundColor Red
187+
"********************************" | Write-Host -ForegroundColor Red
188+
"##[error] Check >>>ERROR<<< messages above" | Write-Host -ForegroundColor Red
189+
"********************************" | Write-Host -ForegroundColor Red
193190

194-
exit 1
191+
exit 1
195192
}

0 commit comments

Comments
 (0)