Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 44 additions & 11 deletions .github/workflows/PesterReports.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# This is a basic workflow to help you get started with Actions

name: PesterReports

# Controls when the action will run.
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
Expand All @@ -16,12 +13,48 @@ on:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: windows-latest

test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Runs pester test reports
- name: pester-tests-report
uses: zyborg/pester-tests-report@v1.5.0
- uses: actions/checkout@v2
# Setup Build Helpers
- name: SetupBuildHelpers
shell: pwsh
run: |
Install-Module BuildHelpers -Scope CurrentUser -Force | Out-Null
Install-Module PowerShellBuild -Scope CurrentUser -Force | Out-Null
Install-Module PSScriptAnalyzer -Scope CurrentUser -Force | Out-Null
Install-Module platyPS -Scope CurrentUser -Force | Out-Null
- name: Test
shell: pwsh
run: |
./build.ps1 -Task Test
- name: Upload Unit Test Results
if: always()
uses: actions/upload-artifact@v2
with:
name: Unit Test Results (OS ${{ matrix.os }})
path: ./tests/Out/testResults.xml

publish-test-results:
name: "Publish Unit Tests Results"
needs: test
runs-on: ubuntu-latest
# the test job might be skipped, we don't need to run this job then
if: success() || failure()

steps:
- name: Download Artifacts
uses: actions/download-artifact@v2
with:
path: artifacts

- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
with:
files: artifacts/**/*.xml
15 changes: 0 additions & 15 deletions .github/workflows/actions.yml

This file was deleted.

24 changes: 24 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Publish Module
on:
push:
branches:
- master
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Pre Install Modules
shell: pwsh
run: |
Install-Module BuildHelpers -Scope CurrentUser -Force | Out-Null
Install-Module PowerShellBuild -Scope CurrentUser -Force | Out-Null
Install-Module psake -Scope CurrentUser -Force | Out-Null
Install-Module PSScriptAnalyzer -Scope CurrentUser -Force | Out-Null
Install-Module platyPS -Scope CurrentUser -Force | Out-Null
- name: Build and publish
env:
NUGET_KEY: ${{ secrets.NUGET_KEY }}
shell: pwsh
run: |
./build.ps1 -Task Publish
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.zip
Release/
Output/
examples/Out/*
test/Out/*
test/TemplateRootTemp/*
tests/Out/*.xml
tests/TemplateRootTemp/*
9 changes: 4 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
{
//-------- Files configuration --------

// When enabled, will trim trailing whitespace when you save a file.
"files.trimTrailingWhitespace": true,

"search.exclude": {
"Release": true
},

//-------- PowerShell Configuration --------

// Use a custom PowerShell Script Analyzer settings file for this workspace.
// Relative paths for this setting are always relative to the workspace root dir.
"powershell.scriptAnalysis.settingsPath": "ScriptAnalyzerSettings.psd1"
"powershell.scriptAnalysis.settingsPath": "ScriptAnalyzerSettings.psd1",
//----------Code Formatting ----------------
"powershell.codeFormatting.preset": "OTBS",
"editor.formatOnSave": true
}
27 changes: 13 additions & 14 deletions src/GetModuleExtension.ps1 → Plaster/GetModuleExtension.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ function Get-ModuleExtension {

[Version]
$ModuleVersion,

[Switch]
$ListAvailable
)

#Only get the latest version of each module
$modules = Get-Module -ListAvailable
$modules = Get-Module -ListAvailable
if (!$ListAvailable) {
$modules = $modules |
Group-Object Name |
Foreach-Object {
$_.group |
Sort-Object Version |
Select-Object -Last 1
}
$modules = $modules |
Group-Object Name |
Foreach-Object {
$_.group |
Sort-Object Version |
Select-Object -Last 1
}
}

Write-Verbose "`nFound $($modules.Length) installed modules to scan for extensions."

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

if ($PSVersionTable.PSEdition -eq "Core") {
$parsedVersion = New-Object -TypeName "System.Management.Automation.SemanticVersion" -ArgumentList $versionString
}
else {
} else {
$parsedVersion = New-Object -TypeName "System.Version" -ArgumentList $versionString
}
}
Expand All @@ -67,10 +66,10 @@ function Get-ModuleExtension {
(!$maximumVersion -or $ModuleVersion -le $maximumVersion)) {
# Return a new object with the extension information
[PSCustomObject]@{
Module = $module
Module = $module
MinimumVersion = $minimumVersion
MaximumVersion = $maximumVersion
Details = $extension.Details
Details = $extension.Details
}
}
}
Expand Down
76 changes: 37 additions & 39 deletions src/GetPlasterTemplate.ps1 → Plaster/GetPlasterTemplate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,46 @@
function Get-PlasterTemplate {
[CmdletBinding()]
param(
[Parameter(Position=0,
ParameterSetName="Path",
HelpMessage="Specifies a path to a folder containing a Plaster template or multiple template folders. Can also be a path to plasterManifest.xml.")]
[Parameter(Position = 0,
ParameterSetName = "Path",
HelpMessage = "Specifies a path to a folder containing a Plaster template or multiple template folders. Can also be a path to plasterManifest.xml.")]
[ValidateNotNullOrEmpty()]
[string]
$Path,

[Parameter(Position=1,
ParameterSetName="Path",
HelpMessage="Will return templates that match the name.")]
[Parameter(Position=1,
ParameterSetName="IncludedTemplates",
HelpMessage="Will return templates that match the name.")]
[Parameter(Position = 1,
ParameterSetName = "Path",
HelpMessage = "Will return templates that match the name.")]
[Parameter(Position = 1,
ParameterSetName = "IncludedTemplates",
HelpMessage = "Will return templates that match the name.")]
[ValidateNotNullOrEmpty()]
[string]
$Name = "*",

[Parameter(ParameterSetName="Path",
HelpMessage="Will return templates that match the tag.")]
[Parameter(ParameterSetName="IncludedTemplates",
HelpMessage="Will return templates that match the tag.")]
[Parameter(ParameterSetName = "Path",
HelpMessage = "Will return templates that match the tag.")]
[Parameter(ParameterSetName = "IncludedTemplates",
HelpMessage = "Will return templates that match the tag.")]
[ValidateNotNullOrEmpty()]
[string]
$Tag = "*",

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

[Parameter(Position=0,
Mandatory=$true,
ParameterSetName="IncludedTemplates",
HelpMessage="Initiates a search for latest version Plaster templates inside of installed modules.")]
[Parameter(Position = 0,
Mandatory = $true,
ParameterSetName = "IncludedTemplates",
HelpMessage = "Initiates a search for latest version Plaster templates inside of installed modules.")]
[switch]
[Alias("IncludeModules")]
$IncludeInstalledModules,
[Parameter(ParameterSetName="IncludedTemplates",
HelpMessage="If specified, searches for Plaster templates inside of all installed module versions.")]

[Parameter(ParameterSetName = "IncludedTemplates",
HelpMessage = "If specified, searches for Plaster templates inside of all installed module versions.")]
[switch]
$ListAvailable
)
Expand All @@ -54,17 +54,17 @@ function Get-PlasterTemplate {
$metadata = $manifestXml["plasterManifest"]["metadata"]

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

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

Expand All @@ -85,34 +85,32 @@ function Get-PlasterTemplate {
# Use Test-PlasterManifest to load the manifest file
Write-Verbose "Attempting to get Plaster template at path: $Path"
CreateTemplateObjectFromManifest $Path $Name $Tag
}
else {
} else {
Write-Verbose "Attempting to get Plaster templates recursively under path: $Path"
GetManifestsUnderPath $Path $Recurse.IsPresent $Name $Tag
}
}
else {
} else {
# Return all templates included with Plaster
GetManifestsUnderPath "$PSScriptRoot\Templates" $true $Name $Tag

if ($IncludeInstalledModules.IsPresent) {
# Search for templates in module path
$GetModuleExtensionParams = @{
ModuleName = "Plaster"
ModuleName = "Plaster"
ModuleVersion = $PlasterVersion
ListAvailable = $ListAvailable
}

$extensions = Get-ModuleExtension @GetModuleExtensionParams

foreach ($extension in $extensions) {
# Scan all module paths registered in the module
foreach ($templatePath in $extension.Details.TemplatePaths) {
$expandedTemplatePath =
[System.IO.Path]::Combine(
$extension.Module.ModuleBase,
$templatePath,
"plasterManifest.xml")
[System.IO.Path]::Combine(
$extension.Module.ModuleBase,
$templatePath,
"plasterManifest.xml")

CreateTemplateObjectFromManifest $expandedTemplatePath $Name $Tag -ErrorAction SilentlyContinue
}
Expand Down
4 changes: 2 additions & 2 deletions src/InvokePlaster.ps1 → Plaster/InvokePlaster.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function Invoke-Plaster {
return
}

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

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

if (Test-Path -LiteralPath $manifestPath -PathType Leaf) {
$manifest = Plaster\Test-PlasterManifest -Path $manifestPath -ErrorAction Stop 3>$null
$manifest = Test-PlasterManifest -Path $manifestPath -ErrorAction Stop 3>$null
$PSCmdlet.WriteDebug("In begin, loading manifest file '$manifestPath'")
}
else {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
44 changes: 42 additions & 2 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,44 @@
#Requires -Modules psake
[cmdletbinding(DefaultParameterSetName = 'Task')]
param(
# Build task(s) to execute
[parameter(ParameterSetName = 'task', position = 0)]
[string[]]$Task = 'default',

# Builds the module by invoking psake on the build.psake.ps1 script.
Invoke-PSake $PSScriptRoot\build.psake.ps1 -taskList Build
# Bootstrap dependencies
[switch]$Bootstrap,

# List available build tasks
[parameter(ParameterSetName = 'Help')]
[switch]$Help,

# Optional properties to pass to psake
[hashtable]$Properties,

# Optional parameters to pass to psake
[hashtable]$Parameters
)

$ErrorActionPreference = 'Stop'

# Execute psake task(s)
$psakeFile = "$PSScriptRoot\psakeFile.ps1"
if ($PSCmdlet.ParameterSetName -eq 'Help') {
Get-PSakeScriptTasks -buildFile $psakeFile |
Format-Table -Property Name, Description, Alias, DependsOn
} else {
Set-BuildEnvironment -Force
$parameters = @{}
if ($PSGalleryApiKey) {
$parameters['galleryApiKey'] = $PSGalleryApiKey
}
$psake_splat = @{
buildFile = $psakeFile
taskList = $Task
nologo = $True
properties = $Properties
parameters = $Parameters
}
Invoke-PSake @psake_splat
exit ([int](-not $psake.build_success))
}
Loading