Skip to content

Commit 45a9910

Browse files
authored
Merge pull request #419 from HeyItsGilbert/master
Leverage PowerShellBuild + Migrate to Pester 5 Tests
2 parents 2aaf216 + b883361 commit 45a9910

52 files changed

Lines changed: 1828 additions & 1887 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
# This is a basic workflow to help you get started with Actions
2-
31
name: PesterReports
4-
5-
# Controls when the action will run.
2+
# Controls when the action will run.
63
on:
74
# Triggers the workflow on push or pull request events but only for the master branch
85
push:
@@ -16,12 +13,48 @@ on:
1613
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
1714
jobs:
1815
# This workflow contains a single job called "build"
19-
build:
20-
# The type of runner that the job will run on
21-
runs-on: windows-latest
22-
16+
test:
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
os: [ubuntu-latest, windows-latest, macOS-latest]
2322
# Steps represent a sequence of tasks that will be executed as part of the job
2423
steps:
25-
# Runs pester test reports
26-
- name: pester-tests-report
27-
uses: zyborg/pester-tests-report@v1.5.0
24+
- uses: actions/checkout@v2
25+
# Setup Build Helpers
26+
- name: SetupBuildHelpers
27+
shell: pwsh
28+
run: |
29+
Install-Module BuildHelpers -Scope CurrentUser -Force | Out-Null
30+
Install-Module PowerShellBuild -Scope CurrentUser -Force | Out-Null
31+
Install-Module PSScriptAnalyzer -Scope CurrentUser -Force | Out-Null
32+
Install-Module platyPS -Scope CurrentUser -Force | Out-Null
33+
- name: Test
34+
shell: pwsh
35+
run: |
36+
./build.ps1 -Task Test
37+
- name: Upload Unit Test Results
38+
if: always()
39+
uses: actions/upload-artifact@v2
40+
with:
41+
name: Unit Test Results (OS ${{ matrix.os }})
42+
path: ./tests/Out/testResults.xml
43+
44+
publish-test-results:
45+
name: "Publish Unit Tests Results"
46+
needs: test
47+
runs-on: ubuntu-latest
48+
# the test job might be skipped, we don't need to run this job then
49+
if: success() || failure()
50+
51+
steps:
52+
- name: Download Artifacts
53+
uses: actions/download-artifact@v2
54+
with:
55+
path: artifacts
56+
57+
- name: Publish Unit Test Results
58+
uses: EnricoMi/publish-unit-test-result-action@v1
59+
with:
60+
files: artifacts/**/*.xml

.github/workflows/actions.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

.github/workflows/publish.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Publish Module
2+
on:
3+
push:
4+
branches:
5+
- master
6+
jobs:
7+
build:
8+
runs-on: windows-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- name: Pre Install Modules
12+
shell: pwsh
13+
run: |
14+
Install-Module BuildHelpers -Scope CurrentUser -Force | Out-Null
15+
Install-Module PowerShellBuild -Scope CurrentUser -Force | Out-Null
16+
Install-Module psake -Scope CurrentUser -Force | Out-Null
17+
Install-Module PSScriptAnalyzer -Scope CurrentUser -Force | Out-Null
18+
Install-Module platyPS -Scope CurrentUser -Force | Out-Null
19+
- name: Build and publish
20+
env:
21+
NUGET_KEY: ${{ secrets.NUGET_KEY }}
22+
shell: pwsh
23+
run: |
24+
./build.ps1 -Task Publish

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*.zip
22
Release/
3+
Output/
34
examples/Out/*
4-
test/Out/*
5-
test/TemplateRootTemp/*
5+
tests/Out/*.xml
6+
tests/TemplateRootTemp/*

.vscode/settings.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
{
22
//-------- Files configuration --------
3-
43
// When enabled, will trim trailing whitespace when you save a file.
54
"files.trimTrailingWhitespace": true,
6-
75
"search.exclude": {
86
"Release": true
97
},
10-
118
//-------- PowerShell Configuration --------
12-
139
// Use a custom PowerShell Script Analyzer settings file for this workspace.
1410
// Relative paths for this setting are always relative to the workspace root dir.
15-
"powershell.scriptAnalysis.settingsPath": "ScriptAnalyzerSettings.psd1"
11+
"powershell.scriptAnalysis.settingsPath": "ScriptAnalyzerSettings.psd1",
12+
//----------Code Formatting ----------------
13+
"powershell.codeFormatting.preset": "OTBS",
14+
"editor.formatOnSave": true
1615
}
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ function Get-ModuleExtension {
66

77
[Version]
88
$ModuleVersion,
9-
9+
1010
[Switch]
1111
$ListAvailable
1212
)
1313

1414
#Only get the latest version of each module
15-
$modules = Get-Module -ListAvailable
15+
$modules = Get-Module -ListAvailable
1616
if (!$ListAvailable) {
17-
$modules = $modules |
18-
Group-Object Name |
19-
Foreach-Object {
20-
$_.group |
21-
Sort-Object Version |
22-
Select-Object -Last 1
23-
}
17+
$modules = $modules |
18+
Group-Object Name |
19+
Foreach-Object {
20+
$_.group |
21+
Sort-Object Version |
22+
Select-Object -Last 1
23+
}
2424
}
25-
25+
2626
Write-Verbose "`nFound $($modules.Length) installed modules to scan for extensions."
2727

2828
function ParseVersion($versionString) {
@@ -39,8 +39,7 @@ function Get-ModuleExtension {
3939

4040
if ($PSVersionTable.PSEdition -eq "Core") {
4141
$parsedVersion = New-Object -TypeName "System.Management.Automation.SemanticVersion" -ArgumentList $versionString
42-
}
43-
else {
42+
} else {
4443
$parsedVersion = New-Object -TypeName "System.Version" -ArgumentList $versionString
4544
}
4645
}
@@ -67,10 +66,10 @@ function Get-ModuleExtension {
6766
(!$maximumVersion -or $ModuleVersion -le $maximumVersion)) {
6867
# Return a new object with the extension information
6968
[PSCustomObject]@{
70-
Module = $module
69+
Module = $module
7170
MinimumVersion = $minimumVersion
7271
MaximumVersion = $maximumVersion
73-
Details = $extension.Details
72+
Details = $extension.Details
7473
}
7574
}
7675
}
Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,46 @@
33
function Get-PlasterTemplate {
44
[CmdletBinding()]
55
param(
6-
[Parameter(Position=0,
7-
ParameterSetName="Path",
8-
HelpMessage="Specifies a path to a folder containing a Plaster template or multiple template folders. Can also be a path to plasterManifest.xml.")]
6+
[Parameter(Position = 0,
7+
ParameterSetName = "Path",
8+
HelpMessage = "Specifies a path to a folder containing a Plaster template or multiple template folders. Can also be a path to plasterManifest.xml.")]
99
[ValidateNotNullOrEmpty()]
1010
[string]
1111
$Path,
1212

13-
[Parameter(Position=1,
14-
ParameterSetName="Path",
15-
HelpMessage="Will return templates that match the name.")]
16-
[Parameter(Position=1,
17-
ParameterSetName="IncludedTemplates",
18-
HelpMessage="Will return templates that match the name.")]
13+
[Parameter(Position = 1,
14+
ParameterSetName = "Path",
15+
HelpMessage = "Will return templates that match the name.")]
16+
[Parameter(Position = 1,
17+
ParameterSetName = "IncludedTemplates",
18+
HelpMessage = "Will return templates that match the name.")]
1919
[ValidateNotNullOrEmpty()]
2020
[string]
2121
$Name = "*",
2222

23-
[Parameter(ParameterSetName="Path",
24-
HelpMessage="Will return templates that match the tag.")]
25-
[Parameter(ParameterSetName="IncludedTemplates",
26-
HelpMessage="Will return templates that match the tag.")]
23+
[Parameter(ParameterSetName = "Path",
24+
HelpMessage = "Will return templates that match the tag.")]
25+
[Parameter(ParameterSetName = "IncludedTemplates",
26+
HelpMessage = "Will return templates that match the tag.")]
2727
[ValidateNotNullOrEmpty()]
2828
[string]
2929
$Tag = "*",
3030

31-
[Parameter(ParameterSetName="Path",
32-
HelpMessage="Indicates that this cmdlet gets the items in the specified locations and in all child items of the locations.")]
31+
[Parameter(ParameterSetName = "Path",
32+
HelpMessage = "Indicates that this cmdlet gets the items in the specified locations and in all child items of the locations.")]
3333
[switch]
3434
$Recurse,
3535

36-
[Parameter(Position=0,
37-
Mandatory=$true,
38-
ParameterSetName="IncludedTemplates",
39-
HelpMessage="Initiates a search for latest version Plaster templates inside of installed modules.")]
36+
[Parameter(Position = 0,
37+
Mandatory = $true,
38+
ParameterSetName = "IncludedTemplates",
39+
HelpMessage = "Initiates a search for latest version Plaster templates inside of installed modules.")]
4040
[switch]
4141
[Alias("IncludeModules")]
4242
$IncludeInstalledModules,
43-
44-
[Parameter(ParameterSetName="IncludedTemplates",
45-
HelpMessage="If specified, searches for Plaster templates inside of all installed module versions.")]
43+
44+
[Parameter(ParameterSetName = "IncludedTemplates",
45+
HelpMessage = "If specified, searches for Plaster templates inside of all installed module versions.")]
4646
[switch]
4747
$ListAvailable
4848
)
@@ -54,17 +54,17 @@ function Get-PlasterTemplate {
5454
$metadata = $manifestXml["plasterManifest"]["metadata"]
5555

5656
$manifestObj = [PSCustomObject]@{
57-
Name = $metadata["name"].InnerText
58-
Title = $metadata["title"].InnerText
59-
Author = $metadata["author"].InnerText
60-
Version = New-Object -TypeName "System.Version" -ArgumentList $metadata["version"].InnerText
61-
Description = $metadata["description"].InnerText
62-
Tags = $metadata["tags"].InnerText.split(",") | % { $_.Trim() }
57+
Name = $metadata["name"].InnerText
58+
Title = $metadata["title"].InnerText
59+
Author = $metadata["author"].InnerText
60+
Version = New-Object -TypeName "System.Version" -ArgumentList $metadata["version"].InnerText
61+
Description = $metadata["description"].InnerText
62+
Tags = $metadata["tags"].InnerText.split(",") | ForEach-Object { $_.Trim() }
6363
TemplatePath = $manifestPath.Directory.FullName
6464
}
6565

6666
$manifestObj.PSTypeNames.Insert(0, "Microsoft.PowerShell.Plaster.PlasterTemplate")
67-
Add-Member -MemberType ScriptMethod -InputObject $manifestObj -Name "InvokePlaster" -Value {Invoke-Plaster -TemplatePath $this.TemplatePath}
67+
Add-Member -MemberType ScriptMethod -InputObject $manifestObj -Name "InvokePlaster" -Value { Invoke-Plaster -TemplatePath $this.TemplatePath }
6868
return $manifestObj | Where-Object Name -like $name | Where-Object Tags -like $tag
6969
}
7070

@@ -85,34 +85,32 @@ function Get-PlasterTemplate {
8585
# Use Test-PlasterManifest to load the manifest file
8686
Write-Verbose "Attempting to get Plaster template at path: $Path"
8787
CreateTemplateObjectFromManifest $Path $Name $Tag
88-
}
89-
else {
88+
} else {
9089
Write-Verbose "Attempting to get Plaster templates recursively under path: $Path"
9190
GetManifestsUnderPath $Path $Recurse.IsPresent $Name $Tag
9291
}
93-
}
94-
else {
92+
} else {
9593
# Return all templates included with Plaster
9694
GetManifestsUnderPath "$PSScriptRoot\Templates" $true $Name $Tag
9795

9896
if ($IncludeInstalledModules.IsPresent) {
9997
# Search for templates in module path
10098
$GetModuleExtensionParams = @{
101-
ModuleName = "Plaster"
99+
ModuleName = "Plaster"
102100
ModuleVersion = $PlasterVersion
103101
ListAvailable = $ListAvailable
104102
}
105-
103+
106104
$extensions = Get-ModuleExtension @GetModuleExtensionParams
107105

108106
foreach ($extension in $extensions) {
109107
# Scan all module paths registered in the module
110108
foreach ($templatePath in $extension.Details.TemplatePaths) {
111109
$expandedTemplatePath =
112-
[System.IO.Path]::Combine(
113-
$extension.Module.ModuleBase,
114-
$templatePath,
115-
"plasterManifest.xml")
110+
[System.IO.Path]::Combine(
111+
$extension.Module.ModuleBase,
112+
$templatePath,
113+
"plasterManifest.xml")
116114

117115
CreateTemplateObjectFromManifest $expandedTemplatePath $Name $Tag -ErrorAction SilentlyContinue
118116
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function Invoke-Plaster {
7979
return
8080
}
8181

82-
$manifest = Plaster\Test-PlasterManifest -Path $manifestPath -ErrorAction Stop 3>$null
82+
$manifest = Test-PlasterManifest -Path $manifestPath -ErrorAction Stop 3>$null
8383

8484
# The user-defined parameters in the Plaster manifest are converted to dynamic parameters
8585
# which allows the user to provide the parameters via the command line.
@@ -179,7 +179,7 @@ function Invoke-Plaster {
179179
}
180180

181181
if (Test-Path -LiteralPath $manifestPath -PathType Leaf) {
182-
$manifest = Plaster\Test-PlasterManifest -Path $manifestPath -ErrorAction Stop 3>$null
182+
$manifest = Test-PlasterManifest -Path $manifestPath -ErrorAction Stop 3>$null
183183
$PSCmdlet.WriteDebug("In begin, loading manifest file '$manifestPath'")
184184
}
185185
else {
File renamed without changes.

0 commit comments

Comments
 (0)