Skip to content

Commit

Permalink
update for #71
Browse files Browse the repository at this point in the history
  • Loading branch information
techthoughts2 committed Jan 18, 2024
1 parent 53c2f7c commit e0590ae
Show file tree
Hide file tree
Showing 15 changed files with 333 additions and 11 deletions.
5 changes: 4 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.2]
## [2.2.0]

- Catesta template module changes
- Added `MarkdownRepair.ps1` and added Markdown repair logic to InvokeBuild script. This is to account for an issue in PowerShell `7.4.0`+ where a new parameter was introduced that platyPS can not handle during help creation. Ref: [platyPS issue]([text](https://github.com/PowerShell/platyPS/issues/595)).
- If a build is run and the build environment is `7.4.0`+ the Markdown repair will run to account for the new parameter and repair markdown for help creation.
- CI/CD Changes:
- Azure:
- Updated `testRunner` alias reference to `testResultsFormat`
- Plaster bumped from `1.1.3` to `1.1.4`
- Pester bumped from `5.4.0` to `5.5.0`
- InvokeBuild bumped from `5.10.2` to `5.10.4`
- Catesta primary module changes
- Added `MarkdownRepair.ps1` and added Markdown repair logic to InvokeBuild script.
- Plaster bumped from `1.1.3` to `1.1.4`
- Pester bumped from `5.4.0` to `5.5.0`
- InvokeBuild bumped from `5.10.2` to `5.10.4`
Expand Down
1 change: 0 additions & 1 deletion docs/Catesta-ModuleSchema.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ Help = 'Yes'
Pester = '5'
}
New-ModuleProject -ModuleParameters $moduleParameters -DestinationPath .
```
1 change: 0 additions & 1 deletion docs/Catesta-VaultSchema.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ CodingStyle = 'Stroustrup'
Pester = '5'
}
New-ModuleProject -ModuleParameters $vaultParameters -DestinationPath .
```
2 changes: 1 addition & 1 deletion docs/Catesta.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Module Name: Catesta
Module Guid: 6796b193-9013-468a-b022-837749af2d06
Download Help Link: NA
Help Version: 2.0.2
Help Version: 2.2.0
Locale: en-US
---

Expand Down
3 changes: 1 addition & 2 deletions docs/New-ModuleProject.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -Verbose, -WarningAction, -WarningVariable, and -ProgressAction.
For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
Expand All @@ -382,4 +382,3 @@ Read the manifest schemas to understand how to properly craft a ModuleParameters
[https://www.catesta.dev/en/latest/New-ModuleProject/](https://www.catesta.dev/en/latest/New-ModuleProject/)
[https://docs.microsoft.com/powershell/scripting/developer/module/writing-a-windows-powershell-module](https://docs.microsoft.com/powershell/scripting/developer/module/writing-a-windows-powershell-module)
3 changes: 1 addition & 2 deletions docs/New-VaultProject.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -Verbose, -WarningAction, -WarningVariable, and -ProgressAction.
For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
Expand All @@ -369,4 +369,3 @@ Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/
[https://www.catesta.dev/en/latest/Catesta-Vault-Extension/](https://www.catesta.dev/en/latest/Catesta-Vault-Extension/)
[https://github.com/PowerShell/SecretManagement](https://github.com/PowerShell/SecretManagement)
11 changes: 11 additions & 0 deletions src/Catesta.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,17 @@ Add-BuildTask CreateMarkdownHelp -After CreateHelpStart {
throw 'Missing GUID. Please review and rebuild.'
}

Write-Build Gray ' Evaluating if running 7.4.0 or higher...'
# https://github.com/PowerShell/platyPS/issues/595
if ($PSVersionTable.PSVersion -ge [version]'7.4.0') {
Write-Build Gray ' Performing Markdown repair'
# dot source markdown repair
. $BuildRoot\MarkdownRepair.ps1
$OutputDir | Get-ChildItem -File | ForEach-Object {
Repair-PlatyPSMarkdown -Path $_.FullName
}
}

Write-Build Gray ' Checking for missing documentation in md files...'
$MissingDocumentation = Select-String -Path "$script:ArtifactsPath\docs\*.md" -Pattern "({{.*}})"
if ($MissingDocumentation.Count -gt 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/Catesta/Catesta.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'Catesta.psm1'

# Version number of this module.
ModuleVersion = '2.0.2'
ModuleVersion = '2.2.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
3 changes: 2 additions & 1 deletion src/Catesta/Resources/Module/plasterManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<metadata>
<name>Catesta</name>
<id>258a61ba-566b-4c3a-8230-c2b6861a1a8d</id>
<version>2.0.2</version>
<version>2.2.0</version>
<title>Catesta</title>
<description>Scaffolds a new PowerShell module project</description>
<author>Jake Morrison</author>
Expand Down Expand Up @@ -179,6 +179,7 @@
<templateFile source='..\Module\src\PSModule.build.ps1' destination='src\${PLASTER_PARAM_ModuleName}.build.ps1'/>
<file source='..\Module\src\PSModule.Settings.ps1' destination='src\${PLASTER_PARAM_ModuleName}.Settings.ps1'/>
<file source='..\Module\src\PSScriptAnalyzerSettings.psd1' destination='src\PSScriptAnalyzerSettings.psd1'/>
<file condition="$PLASTER_PARAM_Help -eq 'Yes'" source='..\Module\src\MarkdownRepair.ps1' destination='src\MarkdownRepair.ps1' />

<!-- VSCode files -->
<templateFile source='..\Editor\VSCode\tasks.json' destination='.vscode\tasks.json' />
Expand Down
135 changes: 135 additions & 0 deletions src/Catesta/Resources/Module/src/MarkdownRepair.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<#
.SYNOPSIS
Repair PlatyPS generated markdown files.
.NOTES
This file is temporarily required to handle platyPS help generation.
https://github.com/PowerShell/platyPS/issues/595
This is a result of a breaking change introduced in PowerShell 7.4.0:
https://learn.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-74?view=powershell-7.4
Breaking Changes: Added the ProgressAction parameter to the Common Parameters
modified from source: https://github.com/PowerShell/platyPS/issues/595#issuecomment-1820971702
#>

function Remove-CommonParameterFromMarkdown {
<#
.SYNOPSIS
Remove a PlatyPS generated parameter block.
.DESCRIPTION
Removes parameter block for the provided parameter name from the markdown file provided.
#>
param(
[Parameter(Mandatory)]
[string[]]
$Path,

[Parameter(Mandatory = $false)]
[string[]]
$ParameterName = @('ProgressAction')
)
$ErrorActionPreference = 'Stop'
foreach ($p in $Path) {
$content = (Get-Content -Path $p -Raw).TrimEnd()
$updateFile = $false
foreach ($param in $ParameterName) {
if (-not ($Param.StartsWith('-'))) {
$param = "-$($param)"
}
# Remove the parameter block
$pattern = "(?m)^### $param\r?\n[\S\s]*?(?=#{2,3}?)"
$newContent = $content -replace $pattern, ''
# Remove the parameter from the syntax block
$pattern = " \[$param\s?.*?]"
$newContent = $newContent -replace $pattern, ''
if ($null -ne (Compare-Object -ReferenceObject $content -DifferenceObject $newContent)) {
Write-Verbose "Added $param to $p"
# Update file content
$content = $newContent
$updateFile = $true
}
}
# Save file if content has changed
if ($updateFile) {
$newContent | Out-File -Encoding utf8 -FilePath $p
Write-Verbose "Updated file: $p"
}
}
return
}

function Add-MissingCommonParameterToMarkdown {
param(
[Parameter(Mandatory)]
[string[]]
$Path,

[Parameter(Mandatory = $false)]
[string[]]
$ParameterName = @('ProgressAction')
)
$ErrorActionPreference = 'Stop'
foreach ($p in $Path) {
$content = (Get-Content -Path $p -Raw).TrimEnd()
$updateFile = $false
foreach ($NewParameter in $ParameterName) {
if (-not ($NewParameter.StartsWith('-'))) {
$NewParameter = "-$($NewParameter)"
}
$pattern = '(?m)^This cmdlet supports the common parameters:(.+?)\.'
$replacement = {
$Params = $_.Groups[1].Captures[0].ToString() -split ' '
$CommonParameters = @()
foreach ($CommonParameter in $Params) {
if ($CommonParameter.StartsWith('-')) {
if ($CommonParameter.EndsWith(',')) {
$CleanParam = $CommonParameter.Substring(0, $CommonParameter.Length - 1)
}
elseif ($p.EndsWith('.')) {
$CleanParam = $CommonParameter.Substring(0, $CommonParameter.Length - 1)
}
else {
$CleanParam = $CommonParameter
}
$CommonParameters += $CleanParam
}
}
if ($NewParameter -notin $CommonParameters) {
$CommonParameters += $NewParameter
}
$CommonParameters[-1] = "and $($CommonParameters[-1]). "
return "This cmdlet supports the common parameters: " + (($CommonParameters | Sort-Object) -join ', ')
}
$newContent = $content -replace $pattern, $replacement
if ($null -ne (Compare-Object -ReferenceObject $content -DifferenceObject $newContent)) {
Write-Verbose "Added $NewParameter to $p"
$updateFile = $true
$content = $newContent
}
}
# Save file if content has changed
if ($updateFile) {
$newContent | Out-File -Encoding utf8 -FilePath $p
Write-Verbose "Updated file: $p"
}
}
return
}

function Repair-PlatyPSMarkdown {
param(
[Parameter(Mandatory)]
[string[]]
$Path,

[Parameter()]
[string[]]
$ParameterName = @('ProgressAction')
)
$ErrorActionPreference = 'Stop'
$Parameters = @{
Path = $Path
ParameterName = $ParameterName
}
$null = Remove-CommonParameterFromMarkdown @Parameters
$null = Add-MissingCommonParameterToMarkdown @Parameters
return
}
11 changes: 11 additions & 0 deletions src/Catesta/Resources/Module/src/PSModule.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,17 @@ Add-BuildTask CreateMarkdownHelp -After CreateHelpStart {
throw 'Missing GUID. Please review and rebuild.'
}

Write-Build Gray ' Evaluating if running 7.4.0 or higher...'
# https://github.com/PowerShell/platyPS/issues/595
if ($PSVersionTable.PSVersion -ge [version]'7.4.0') {
Write-Build Gray ' Performing Markdown repair'
# dot source markdown repair
. $BuildRoot\MarkdownRepair.ps1
$OutputDir | Get-ChildItem -File | ForEach-Object {
Repair-PlatyPSMarkdown -Path $_.FullName
}
}

Write-Build Gray ' Checking for missing documentation in md files...'
$MissingDocumentation = Select-String -Path "$script:ArtifactsPath\docs\*.md" -Pattern "({{.*}})"
if ($MissingDocumentation.Count -gt 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/Catesta/Resources/Vault/plasterManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<metadata>
<name>Catesta</name>
<id>d531e058-52b8-4dd2-8162-01c95d1eb8f7</id>
<version>2.0.2</version>
<version>2.2.0</version>
<title>Catesta</title>
<description>Scaffolds a new PowerShell SecretManagement extension vault module project</description>
<author>Jake Morrison</author>
Expand Down
Loading

0 comments on commit e0590ae

Please sign in to comment.