1- # Inspired by https://github.com/AvaloniaUI/avalonia-dotnet-templates/blob/main/tests/build-test.ps1
2- # Enable common parameters e.g. -Verbose
3- [CmdletBinding ()]
4- param ()
5-
6- Set-StrictMode - Version latest
7- $ErrorActionPreference = " Stop"
8-
9- # Taken from psake https://github.com/psake/psake
10- <#
11- . SYNOPSIS
12- This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode
13- to see if an error occcured. If an error is detected then an exception is thrown.
14- This function allows you to run command-line programs without having to
15- explicitly check the $lastexitcode variable.
16- . EXAMPLE
17- exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed"
18- #>
19- function Exec
20- {
21- [CmdletBinding ()]
22- param (
23- [Parameter (Position = 0 , Mandatory = 1 )][scriptblock ]$cmd ,
24- [Parameter (Position = 1 , Mandatory = 0 )][string ]$errorMessage = (" Error executing command {0}" -f $cmd )
25- )
26-
27- # Convert the ScriptBlock to a string and expand the variables
28- $expandedCmdString = $ExecutionContext.InvokeCommand.ExpandString ($cmd.ToString ())
29- Write-Verbose " Executing command: $expandedCmdString "
30-
31- Invoke-Command - ScriptBlock $cmd
32-
33- if ($lastexitcode -ne 0 ) {
34- throw (" Exec: " + $errorMessage )
35- }
36- }
37-
38- function Test-Template {
39- param (
40- [Parameter (Position = 0 , Mandatory = 1 )][string ]$template ,
41- [Parameter (Position = 1 , Mandatory = 1 )][string ]$name ,
42- [Parameter (Position = 2 , Mandatory = 1 )][string ]$lang ,
43- [Parameter (Position = 3 , Mandatory = 1 )][string ]$parameterName ,
44- [Parameter (Position = 4 , Mandatory = 1 )][string ]$value ,
45- [Parameter (Position = 5 , Mandatory = 0 )][string ]$bl
46- )
47-
48- $folderName = $name + $parameterName + $value
49-
50- # Remove dots and - from folderName because in sln it will cause errors when building project
51- $folderName = $folderName -replace " [.-]"
52-
53- # Create the project
54- Exec { dotnet new $template - o output// $lang / $folderName - $parameterName $value - lang $lang }
55-
56- # Build
57- Exec { dotnet build output/ $lang / $folderName - bl:$bl }
58- Exec { dotnet test output/ $lang / $folderName - bl:$bl } # some templates might include unit tests
59- Exec { dotnet publish - c Release - t:PublishContainer output/ $lang / $folderName - bl:$bl }
60- }
61-
62- function Create-And-Build {
63- param (
64- [Parameter (Position = 0 , Mandatory = 1 )][string ]$template ,
65- [Parameter (Position = 1 , Mandatory = 1 )][string ]$name ,
66- [Parameter (Position = 2 , Mandatory = 1 )][string ]$lang ,
67- [Parameter (Position = 3 , Mandatory = 1 )][string ]$parameterName ,
68- [Parameter (Position = 4 , Mandatory = 1 )][string ]$value ,
69- [Parameter (Position = 5 , Mandatory = 0 )][string ]$bl
70- )
71-
72- $folderName = $name + $parameterName + $value
73-
74- # Remove dots and - from folderName because in sln it will cause errors when building project
75- $folderName = $folderName -replace " [.-]"
76-
77- # Create the project
78- Exec { dotnet new $template - o output/ $lang / $folderName - $parameterName $value - lang $lang }
79-
80- # Build
81- Exec { dotnet build output/ $lang / $folderName - bl:$bl }
82- }
83-
84- # Clear file system from possible previous runs
85- Write-Output " Clearing outputs from possible previous runs"
86- if (Test-Path " output" - ErrorAction SilentlyContinue) {
87- Remove-Item - Recurse - Force " output"
88- }
89- $outDir = [IO.Path ]::GetFullPath([IO.Path ]::Combine($pwd , " .." , " output" ))
90- if (Test-Path $outDir - ErrorAction SilentlyContinue) {
91- Remove-Item - Recurse - Force $outDir
92- }
93- $binLogDir = [IO.Path ]::GetFullPath([IO.Path ]::Combine($pwd , " .." , " binlog" ))
94- if (Test-Path $binLogDir - ErrorAction SilentlyContinue) {
95- Remove-Item - Recurse - Force $binLogDir
96- }
97-
98- # Use same log file for all executions
99- $binlog = [IO.Path ]::GetFullPath([IO.Path ]::Combine($pwd , " .." , " binlog" , " test.binlog" ))
100-
101- Create- And- Build " akka.console" " AkkaConsole" " C#" " f" " net9.0" $binlog
102- Create- And- Build " akka.console" " AkkaConsole" " C#" " f" " net8.0" $binlog
103-
104- Create- And- Build " akka.console" " AkkaConsole" " F#" " f" " net9.0" $binlog
105- Create- And- Build " akka.console" " AkkaConsole" " F#" " f" " net8.0" $binlog
106-
107- Create- And- Build " akka.streams" " AkkaStreams" " C#" " f" " net9.0" $binlog
108- Create- And- Build " akka.streams" " AkkaStreams" " C#" " f" " net8.0" $binlog
109-
110- Test-Template " akka.cluster.webapi" " ClusterWebTemplate" " C#" " f" " net9.0" $binlog
111- Test-Template " akka.cluster.webapi" " ClusterWebTemplate" " C#" " f" " net8.0" $binlog
112-
1+ # Inspired by https://github.com/AvaloniaUI/avalonia-dotnet-templates/blob/main/tests/build-test.ps1
2+ # Enable common parameters e.g. -Verbose
3+ [CmdletBinding ()]
4+ param ()
5+
6+ Set-StrictMode - Version latest
7+ $ErrorActionPreference = " Stop"
8+
9+ # Taken from psake https://github.com/psake/psake
10+ <#
11+ . SYNOPSIS
12+ This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode
13+ to see if an error occcured. If an error is detected then an exception is thrown.
14+ This function allows you to run command-line programs without having to
15+ explicitly check the $lastexitcode variable.
16+ . EXAMPLE
17+ exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed"
18+ #>
19+ function Exec
20+ {
21+ [CmdletBinding ()]
22+ param (
23+ [Parameter (Position = 0 , Mandatory = 1 )][scriptblock ]$cmd ,
24+ [Parameter (Position = 1 , Mandatory = 0 )][string ]$errorMessage = (" Error executing command {0}" -f $cmd )
25+ )
26+
27+ # Convert the ScriptBlock to a string and expand the variables
28+ $expandedCmdString = $ExecutionContext.InvokeCommand.ExpandString ($cmd.ToString ())
29+ Write-Verbose " Executing command: $expandedCmdString "
30+
31+ Invoke-Command - ScriptBlock $cmd
32+
33+ if ($lastexitcode -ne 0 ) {
34+ throw (" Exec: " + $errorMessage )
35+ }
36+ }
37+
38+ function Test-Template {
39+ param (
40+ [Parameter (Position = 0 , Mandatory = 1 )][string ]$template ,
41+ [Parameter (Position = 1 , Mandatory = 1 )][string ]$name ,
42+ [Parameter (Position = 2 , Mandatory = 1 )][string ]$lang ,
43+ [Parameter (Position = 3 , Mandatory = 1 )][string ]$parameterName ,
44+ [Parameter (Position = 4 , Mandatory = 1 )][string ]$value ,
45+ [Parameter (Position = 5 , Mandatory = 0 )][string ]$bl
46+ )
47+
48+ $folderName = $name + $parameterName + $value
49+
50+ # Remove dots and - from folderName because in sln it will cause errors when building project
51+ $folderName = $folderName -replace " [.-]"
52+
53+ # Create the project
54+ Exec { dotnet new $template - o output// $lang / $folderName - $parameterName $value - lang $lang }
55+
56+ # Build
57+ Exec { dotnet build output/ $lang / $folderName - bl:$bl }
58+ Exec { dotnet test output/ $lang / $folderName - bl:$bl } # some templates might include unit tests
59+ Exec { dotnet publish - c Release - t:PublishContainer output/ $lang / $folderName - bl:$bl }
60+ }
61+
62+ function Create-And-Build {
63+ param (
64+ [Parameter (Position = 0 , Mandatory = 1 )][string ]$template ,
65+ [Parameter (Position = 1 , Mandatory = 1 )][string ]$name ,
66+ [Parameter (Position = 2 , Mandatory = 1 )][string ]$lang ,
67+ [Parameter (Position = 3 , Mandatory = 1 )][string ]$parameterName ,
68+ [Parameter (Position = 4 , Mandatory = 1 )][string ]$value ,
69+ [Parameter (Position = 5 , Mandatory = 0 )][string ]$bl
70+ )
71+
72+ $folderName = $name + $parameterName + $value
73+
74+ # Remove dots and - from folderName because in sln it will cause errors when building project
75+ $folderName = $folderName -replace " [.-]"
76+
77+ # Create the project
78+ Exec { dotnet new $template - o output/ $lang / $folderName - $parameterName $value - lang $lang }
79+
80+ # Build
81+ Exec { dotnet build output/ $lang / $folderName - bl:$bl }
82+ }
83+
84+ # Clear file system from possible previous runs
85+ Write-Output " Clearing outputs from possible previous runs"
86+ if (Test-Path " output" - ErrorAction SilentlyContinue) {
87+ Remove-Item - Recurse - Force " output"
88+ }
89+ $outDir = [IO.Path ]::GetFullPath([IO.Path ]::Combine($pwd , " .." , " output" ))
90+ if (Test-Path $outDir - ErrorAction SilentlyContinue) {
91+ Remove-Item - Recurse - Force $outDir
92+ }
93+ $binLogDir = [IO.Path ]::GetFullPath([IO.Path ]::Combine($pwd , " .." , " binlog" ))
94+ if (Test-Path $binLogDir - ErrorAction SilentlyContinue) {
95+ Remove-Item - Recurse - Force $binLogDir
96+ }
97+
98+ # Use same log file for all executions
99+ $binlog = [IO.Path ]::GetFullPath([IO.Path ]::Combine($pwd , " .." , " binlog" , " test.binlog" ))
100+
101+ Create- And- Build " akka.console" " AkkaConsole" " C#" " f" " net9.0" $binlog
102+ Create- And- Build " akka.console" " AkkaConsole" " C#" " f" " net8.0" $binlog
103+
104+ Create- And- Build " akka.console" " AkkaConsole" " F#" " f" " net9.0" $binlog
105+ Create- And- Build " akka.console" " AkkaConsole" " F#" " f" " net8.0" $binlog
106+
107+ Create- And- Build " akka.streams" " AkkaStreams" " C#" " f" " net9.0" $binlog
108+ Create- And- Build " akka.streams" " AkkaStreams" " C#" " f" " net8.0" $binlog
109+
110+ Create- And- Build " akka.streams" " AkkaStreams" " F#" " f" " net9.0" $binlog
111+ Create- And- Build " akka.streams" " AkkaStreams" " F#" " f" " net8.0" $binlog
112+
113+ Test-Template " akka.cluster.webapi" " ClusterWebTemplate" " C#" " f" " net9.0" $binlog
114+ Test-Template " akka.cluster.webapi" " ClusterWebTemplate" " C#" " f" " net8.0" $binlog
115+
113116# Ignore errors when files are still used by another process
0 commit comments