Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 9e2361a

Browse files
authored
Build/test framework for PSSwagger.LiveTestFramework module (#260)
Build/test framework for PSSwagger.LiveTestFramework module
1 parent f05a05b commit 9e2361a

26 files changed

+1236
-0
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,14 @@ FakesAssemblies/
261261
*.xproj
262262
*.xproj.user
263263
*.suo
264+
265+
# LiveTestFramework default output dir
266+
PSSwagger.LiveTestFramework/out/
267+
268+
# LiveTestFramework Code.ps1 files
269+
PSSwagger.LiveTestFramework/src/PSSwagger.LTF.ConsoleServer/*.Code.ps1
270+
PSSwagger.LiveTestFramework/src/PSSwagger.LTF.Lib/*.Code.ps1
271+
272+
# LiveTestFramework test results
273+
PSSwagger.LiveTestFramework/test/PSSwagger.LTF.Lib.UnitTests/Results/
274+
PSSwagger.LiveTestFramework/test/Pester/PesterResults.xml
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
<#
2+
.DESCRIPTION
3+
Builds the PSSwagger.LiveTestFramework module.
4+
#>
5+
[CmdletBinding()]
6+
param(
7+
[Parameter(Mandatory=$true)]
8+
[string]
9+
$OutputDirectory
10+
)
11+
12+
<#
13+
.DESCRIPTION
14+
Remove the output directory if it exists then create it.
15+
#>
16+
function Prepare-OutputDirectory {
17+
[CmdletBinding()]
18+
param(
19+
[Parameter(Mandatory=$true)]
20+
[string]
21+
$OutputDirectory
22+
)
23+
24+
if (Test-Path -Path $OutputDirectory) {
25+
Write-Verbose -Message "Cleaning module directory"
26+
Remove-Item -Path $OutputDirectory -ErrorAction SilentlyContinue -Recurse -Force
27+
}
28+
29+
Write-Verbose -Message "Creating module directory"
30+
$null = New-Item -Path $OutputDirectory -ItemType Container -Force
31+
}
32+
33+
<#
34+
.DESCRIPTION
35+
Converts all source C# files (.cs) to code files (.Code.ps1).
36+
#>
37+
function Convert-CSharpFiles {
38+
[CmdletBinding()]
39+
param(
40+
[Parameter(Mandatory=$true)]
41+
[string]
42+
$SrcPath
43+
)
44+
45+
Write-Verbose -Message "Converting all C# files to code files"
46+
47+
& $SrcPath\ConvertFrom-CSharpFiles.ps1
48+
}
49+
50+
<#
51+
.DESCRIPTION
52+
Copies PowerShell module files to the output directory (.psd1 and .psm1)
53+
#>
54+
function Copy-PowerShellModuleFiles {
55+
[CmdletBinding()]
56+
param(
57+
[Parameter(Mandatory=$true)]
58+
[string]
59+
$OutputDirectory,
60+
61+
[Parameter(Mandatory=$true)]
62+
[string]
63+
$RepoPath
64+
)
65+
66+
Copy-Item -Path (Join-Path -Path $repoPath -ChildPath 'PSSwagger.LiveTestFramework.psd1') -Destination (Join-Path -Path $OutputDirectory -ChildPath 'PSSwagger.LiveTestFramework.psd1') -Verbose
67+
Copy-Item -Path (Join-Path -Path $repoPath -ChildPath 'PSSwagger.LiveTestFramework.psm1') -Destination (Join-Path -Path $OutputDirectory -ChildPath 'PSSwagger.LiveTestFramework.psm1') -Verbose
68+
}
69+
70+
<#
71+
.DESCRIPTION
72+
Copies all code files in the correct directory structure to the output directory.
73+
#>
74+
function Copy-CodeProject {
75+
[CmdletBinding()]
76+
param(
77+
[Parameter(Mandatory=$true)]
78+
[string]
79+
$OutputDirectory,
80+
81+
[Parameter(Mandatory=$true)]
82+
[string]
83+
$SrcPath,
84+
85+
[Parameter(Mandatory=$true)]
86+
[string]
87+
$Project
88+
)
89+
90+
Get-ChildItem -Path (Join-Path -Path $srcPath -ChildPath $Project | Join-Path -ChildPath '*.Code.ps1') -File | ForEach-Object {
91+
$dir = $_.Directory
92+
$subPath = "\"
93+
while ($dir -and $dir.FullName -ne $srcPath) {
94+
$subPath = Join-Path $dir.Name -ChildPath $dirName
95+
$dir = $dir.Parent
96+
}
97+
$outputDir = Join-Path -Path $OutputDirectory -ChildPath 'src' | Join-Path -ChildPath $subPath
98+
if (-not (Test-Path -Path $outputDir -PathType Container)) {
99+
$null = New-Item -Path $outputDir -ItemType Container -Force
100+
}
101+
$outputFilePath = Join-Path -Path $outputDir -ChildPath $_.Name
102+
103+
Copy-Item -Path $_.FullName -Destination $outputFilePath -Verbose
104+
}
105+
}
106+
107+
<#
108+
.DESCRIPTION
109+
Retrieves the release info file.
110+
#>
111+
function Get-ReleaseInfo {
112+
[CmdletBinding()]
113+
param(
114+
[Parameter(Mandatory=$true)]
115+
[string]
116+
$RepoPath
117+
)
118+
119+
Get-Content -Path (Join-Path -Path $RepoPath -ChildPath 'release.json') | ConvertFrom-Json
120+
}
121+
122+
<#
123+
.DESCRIPTION
124+
Replaces dynamic info in the module manifest, like ModuleVersion.
125+
#>
126+
function Set-ModuleManifestInfo {
127+
[CmdletBinding()]
128+
param(
129+
[Parameter(Mandatory=$true)]
130+
[object]
131+
$Release,
132+
133+
[Parameter(Mandatory=$true)]
134+
[string]
135+
$OutputDirectory
136+
)
137+
138+
$psd1Path = Join-Path -Path $OutputDirectory -ChildPath 'PSSwagger.LiveTestFramework.psd1'
139+
$manifestContent = Get-Content -Path $psd1Path
140+
$manifestContent = $manifestContent.Replace("ModuleVersion = '9.9.9'", "ModuleVersion = '$($Release.version)'")
141+
$manifestContent | Out-File -FilePath $psd1Path
142+
}
143+
144+
$srcPath = Join-Path -Path $PSScriptRoot -ChildPath 'src'
145+
$release = Get-ReleaseInfo -RepoPath $PSScriptRoot
146+
$moduleOutputDirectory = Join-Path -Path $OutputDirectory -ChildPath 'PSSwagger.LiveTestFramework' | Join-Path -ChildPath $release.version
147+
Prepare-OutputDirectory -OutputDirectory $moduleOutputDirectory
148+
Convert-CSharpFiles -SrcPath $srcPath
149+
150+
# Copy PowerShell files
151+
Copy-PowerShellModuleFiles -OutputDirectory $moduleOutputDirectory -RepoPath $PSScriptRoot
152+
153+
# Copy code files
154+
# This should ignore csproj, intermediate cs files
155+
# Currently this is a non-recursive search for *.Code.ps1 files
156+
Copy-CodeProject -OutputDirectory $moduleOutputDirectory -SrcPath $srcPath -Project 'PSSwagger.LTF.Lib'
157+
Copy-CodeProject -OutputDirectory $moduleOutputDirectory -SrcPath $srcPath -Project 'PSSwagger.LTF.ConsoleServer'
158+
159+
Set-ModuleManifestInfo -Release $release -OutputDirectory $moduleOutputDirectory
160+
161+
# This currently only works in some cases.
162+
if (-not $?) {
163+
Write-Host "Module packaging completed with errors." -BackgroundColor DarkRed
164+
} else {
165+
Write-Host "Module packaged successfully." -BackgroundColor DarkGreen
166+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#########################################################################################
2+
#
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
#
5+
# Localized PSSwagger.LiveTestFramework.Resources.psd1
6+
#
7+
#########################################################################################
8+
9+
ConvertFrom-StringData @'
10+
###PSLOC
11+
12+
StartingConsoleServerFromPath=Starting console server from path: {0}
13+
CodeFileSignatureValidationFailed=Failed to validate the signature of file '{0}'.
14+
###PSLOC
15+
'@
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
@{
2+
RootModule = 'PSSwagger.LiveTestFramework.psm1'
3+
ModuleVersion = '9.9.9'
4+
GUID = '026fa119-121b-4816-9556-5a306bebb963'
5+
Author = 'Microsoft Corporation'
6+
CompanyName = 'Microsoft Corporation'
7+
Copyright = '(c) Microsoft Corporation. All rights reserved.'
8+
Description = 'PowerShell module with commands for generating or manipulating PSSwagger.LiveTestFramework binaries.'
9+
PowerShellVersion = '5.0'
10+
FunctionsToExport = @('Start-PSSwaggerLiveTestServer','Add-PSSwaggerLiveTestLibType','Add-PSSwaggerLiveTestServerType')
11+
CmdletsToExport = ''
12+
VariablesToExport = ''
13+
AliasesToExport = ''
14+
RequiredModules = @('PSSwagger.Common.Helpers')
15+
NestedModules = @()
16+
17+
FileList = @(
18+
'PSSwagger.LiveTestFramework.psd1',
19+
'PSSwagger.LiveTestFramework.psm1'
20+
)
21+
22+
PrivateData = @{
23+
PSData = @{
24+
Tags = @('Azure',
25+
'Swagger',
26+
'PSEdition_Desktop',
27+
'PSEdition_Core',
28+
'Linux',
29+
'Mac')
30+
ProjectUri = 'https://github.com/PowerShell/PSSwagger'
31+
LicenseUri = 'https://github.com/PowerShell/PSSwagger/blob/master/LICENSE'
32+
ReleaseNotes = @'
33+
- Initial development release
34+
'@
35+
}
36+
}
37+
38+
}
39+

0 commit comments

Comments
 (0)