From 802520181d6a9a6e7644466e7473fa3d0eba8b61 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 24 Jan 2025 15:19:11 +0100 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=AA=B2=20[Fix]:=20Fix=20an=20issue=20?= =?UTF-8?q?with=20padding=20the=20prerelease=20number=20(#42)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This pull request includes a small change to the `Publish-PSModule` function in the `scripts/helpers/Publish-PSModule.ps1` file. The change modifies the way the `latestPrereleaseNumber` is padded with zeros. * [`scripts/helpers/Publish-PSModule.ps1`](diffhunk://#diff-780715ac24c6bbe21b54f3d268778136b79f21a62275bbd494dfa857b4ba40d9L278-R278): Changed the `latestPrereleaseNumber` variable to be explicitly cast to a string before padding it with zeros. ## Type of change - [ ] 📖 [Docs] - [x] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas --- scripts/helpers/Publish-PSModule.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/helpers/Publish-PSModule.ps1 b/scripts/helpers/Publish-PSModule.ps1 index af69253..ea962cd 100644 --- a/scripts/helpers/Publish-PSModule.ps1 +++ b/scripts/helpers/Publish-PSModule.ps1 @@ -275,7 +275,7 @@ function Publish-PSModule { $latestPrereleaseNumber = [Math]::Max($latestPSGalleryPrerelease, $latestGHPrereleases) $latestPrereleaseNumber++ - $latestPrereleaseNumber = $latestPrereleaseNumber.PadLeft(3,'0') + $latestPrereleaseNumber = ([string]$latestPrereleaseNumber).PadLeft(3, '0') $newVersion.Prerelease += $latestPrereleaseNumber } } From 12425f85ac74915196bc9a1e88e182c60cd2e016 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 24 Jan 2025 17:26:38 +0100 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20more=20logg?= =?UTF-8?q?ing=20(#43)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This pull request includes several changes to the `Publish-PSModule` script and the `action.yml` configuration file to improve logging. ### Improvements to the `Publish-PSModule` script: * Added new module dependencies (`Retry`, `GitHub`) to the `#Requires` statement in `scripts/helpers/Publish-PSModule.ps1`. * Added `[OutputType([void])]` attribute to the `Publish-PSModule` function to specify the output type. * Replaced `Write-Verbose` with `Write-Output` for better visibility of key process steps and outputs. [[1]](diffhunk://#diff-780715ac24c6bbe21b54f3d268778136b79f21a62275bbd494dfa857b4ba40d9L162-R192) [[2]](diffhunk://#diff-780715ac24c6bbe21b54f3d268778136b79f21a62275bbd494dfa857b4ba40d9L199-R221) [[3]](diffhunk://#diff-780715ac24c6bbe21b54f3d268778136b79f21a62275bbd494dfa857b4ba40d9L240-R246) [[4]](diffhunk://#diff-780715ac24c6bbe21b54f3d268778136b79f21a62275bbd494dfa857b4ba40d9L282-R301) [[5]](diffhunk://#diff-780715ac24c6bbe21b54f3d268778136b79f21a62275bbd494dfa857b4ba40d9L308-R323) [[6]](diffhunk://#diff-780715ac24c6bbe21b54f3d268778136b79f21a62275bbd494dfa857b4ba40d9L332-R345) [[7]](diffhunk://#diff-780715ac24c6bbe21b54f3d268778136b79f21a62275bbd494dfa857b4ba40d9L363-R376) * Introduced retry logic using the `Retry` module when fetching the latest version from PSGallery to handle transient errors. ### Changes to the `action.yml` configuration file: * Updated the step name from `Run Build-PSModule` to `Run Publish-PSModule`. * Simplified the script path reference by removing unnecessary dot notation. ## Type of change - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas --- action.yml | 4 +- scripts/helpers/Publish-PSModule.ps1 | 97 ++++++++++++++++------------ 2 files changed, 57 insertions(+), 44 deletions(-) diff --git a/action.yml b/action.yml index 2dd87a9..1f4bb6c 100644 --- a/action.yml +++ b/action.yml @@ -79,7 +79,7 @@ inputs: runs: using: composite steps: - - name: Run Build-PSModule + - name: Run Publish-PSModule uses: PSModule/GitHub-Script@v1 env: GITHUB_ACTION_INPUT_Name: ${{ inputs.Name }} @@ -103,4 +103,4 @@ runs: Version: ${{ inputs.Version }} Script: | # Publish-PSModule - . "${{ github.action_path }}\scripts\main.ps1" + ${{ github.action_path }}\scripts\main.ps1 diff --git a/scripts/helpers/Publish-PSModule.ps1 b/scripts/helpers/Publish-PSModule.ps1 index ea962cd..0023a2b 100644 --- a/scripts/helpers/Publish-PSModule.ps1 +++ b/scripts/helpers/Publish-PSModule.ps1 @@ -1,4 +1,4 @@ -#REQUIRES -Modules Utilities, PowerShellGet, Microsoft.PowerShell.PSResourceGet +#Requires -Modules Utilities, PowerShellGet, Microsoft.PowerShell.PSResourceGet, Retry, GitHub function Publish-PSModule { <# @@ -11,6 +11,7 @@ function Publish-PSModule { .EXAMPLE Publish-PSModule -Name 'PSModule.FX' -APIKey $env:PSGALLERY_API_KEY #> + [OutputType([void])] [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSReviewUnusedParameter', '', Scope = 'Function', @@ -159,31 +160,36 @@ function Publish-PSModule { Write-Warning 'Could not find the latest release version. Using ''0.0.0'' as the version.' $ghReleaseVersion = New-PSSemVer -Version '0.0.0' } - Write-Verbose '-------------------------------------------------' - Write-Verbose 'GitHub version:' - Write-Verbose ($ghReleaseVersion | Format-Table | Out-String) - Write-Verbose $ghReleaseVersion.ToString() - Write-Verbose '-------------------------------------------------' + Write-Output '-------------------------------------------------' + Write-Output 'GitHub version:' + Write-Output ($ghReleaseVersion | Format-Table | Out-String) + Write-Output $ghReleaseVersion.ToString() + Write-Output '-------------------------------------------------' } LogGroup 'Get latest version - PSGallery' { try { - $psGalleryVersion = New-PSSemVer -Version (Find-PSResource -Name $Name -Repository PSGallery -Verbose:$false).Version + Retry -Count 5 -Delay 10 { + $latest = Find-PSResource -Name $Name -Repository PSGallery -Verbose:$false + } -Catch { + Write-Output $_ + } + $psGalleryVersion = New-PSSemVer -Version $latest.Version } catch { Write-Warning 'Could not find module online. Using ''0.0.0'' as the version.' $psGalleryVersion = New-PSSemVer -Version '0.0.0' } - Write-Verbose '-------------------------------------------------' - Write-Verbose 'PSGallery version:' - Write-Verbose ($psGalleryVersion | Format-Table | Out-String) - Write-Verbose $psGalleryVersion.ToString() - Write-Verbose '-------------------------------------------------' + Write-Output '-------------------------------------------------' + Write-Output 'PSGallery version:' + Write-Output ($psGalleryVersion | Format-Table | Out-String) + Write-Output $psGalleryVersion.ToString() + Write-Output '-------------------------------------------------' } LogGroup 'Get latest version - Manifest' { Add-PSModulePath -Path (Split-Path -Path $ModulePath -Parent) $manifestFilePath = Join-Path $ModulePath "$Name.psd1" - Write-Verbose "Module manifest file path: [$manifestFilePath]" + Write-Output "Module manifest file path: [$manifestFilePath]" if (-not (Test-Path -Path $manifestFilePath)) { Write-Error "Module manifest file not found at [$manifestFilePath]" return @@ -196,23 +202,23 @@ function Publish-PSModule { $manifestVersion = New-PSSemVer -Version '0.0.0' } } - Write-Verbose '-------------------------------------------------' - Write-Verbose 'Manifest version:' - Write-Verbose ($manifestVersion | Format-Table | Out-String) - Write-Verbose $manifestVersion.ToString() - Write-Verbose '-------------------------------------------------' + Write-Output '-------------------------------------------------' + Write-Output 'Manifest version:' + Write-Output ($manifestVersion | Format-Table | Out-String) + Write-Output $manifestVersion.ToString() + Write-Output '-------------------------------------------------' } LogGroup 'Get latest version' { - Write-Verbose "GitHub: [$($ghReleaseVersion.ToString())]" - Write-Verbose "PSGallery: [$($psGalleryVersion.ToString())]" - Write-Verbose "Manifest: [$($manifestVersion.ToString())] (ignored)" + Write-Output "GitHub: [$($ghReleaseVersion.ToString())]" + Write-Output "PSGallery: [$($psGalleryVersion.ToString())]" + Write-Output "Manifest: [$($manifestVersion.ToString())] (ignored)" $latestVersion = New-PSSemVer -Version ($psGalleryVersion, $ghReleaseVersion | Sort-Object -Descending | Select-Object -First 1) - Write-Verbose '-------------------------------------------------' - Write-Verbose 'Latest version:' - Write-Verbose ($latestVersion | Format-Table | Out-String) - Write-Verbose $latestVersion.ToString() - Write-Verbose '-------------------------------------------------' + Write-Output '-------------------------------------------------' + Write-Output 'Latest version:' + Write-Output ($latestVersion | Format-Table | Out-String) + Write-Output $latestVersion.ToString() + Write-Output '-------------------------------------------------' } LogGroup 'Calculate new version' { @@ -237,7 +243,7 @@ function Publish-PSModule { if ($createPrerelease) { Write-Output "Adding a prerelease tag to the version using the branch name [$prereleaseName]." - Write-Verbose ($releases | Where-Object { $_.tagName -like "*$prereleaseName*" } | + Write-Output ($releases | Where-Object { $_.tagName -like "*$prereleaseName*" } | Select-Object -Property name, isPrerelease, isLatest, publishedAt | Format-Table -AutoSize | Out-String) $newVersion.Prerelease = $prereleaseName @@ -279,20 +285,20 @@ function Publish-PSModule { $newVersion.Prerelease += $latestPrereleaseNumber } } - Write-Verbose '-------------------------------------------------' - Write-Verbose 'New version:' - Write-Verbose ($newVersion | Format-Table | Out-String) - Write-Verbose $newVersion.ToString() - Write-Verbose '-------------------------------------------------' + Write-Output '-------------------------------------------------' + Write-Output 'New version:' + Write-Output ($newVersion | Format-Table | Out-String) + Write-Output $newVersion.ToString() + Write-Output '-------------------------------------------------' } - Write-Verbose "New version is [$($newVersion.ToString())]" + Write-Output "New version is [$($newVersion.ToString())]" LogGroup 'Update module manifest' { - Write-Verbose 'Bump module version -> module metadata: Update-ModuleMetadata' + Write-Output 'Bump module version -> module metadata: Update-ModuleMetadata' $manifestNewVersion = "$($newVersion.Major).$($newVersion.Minor).$($newVersion.Patch)" Set-ModuleManifest -Path $manifestFilePath -ModuleVersion $manifestNewVersion -Verbose:$false if ($createPrerelease) { - Write-Verbose "Prerelease is: [$($newVersion.Prerelease)]" + Write-Output "Prerelease is: [$($newVersion.Prerelease)]" Set-ModuleManifest -Path $manifestFilePath -Prerelease $($newVersion.Prerelease) -Verbose:$false } @@ -305,9 +311,16 @@ function Publish-PSModule { if ($createPrerelease -or $createRelease -or $whatIf) { LogGroup 'Publish-ToPSGallery' { - Write-Verbose "Publish module to PowerShell Gallery using [$APIKey]" + if ($createPrerelease) { + $publishPSVersion = "$($newVersion.Major).$($newVersion.Minor).$($newVersion.Patch)-$($newVersion.Prerelease)" + $psGalleryReleaseLink = "https://www.powershellgallery.com/packages/$Name/$publishPSVersion" + } else { + $publishPSVersion = $newVersion.ToString() + $psGalleryReleaseLink = "https://www.powershellgallery.com/packages/$Name/$($newVersion.ToString())" + } + Write-Output "Publish module to PowerShell Gallery using [$APIKey]" if ($whatIf) { - Write-Verbose "Publish-PSResource -Path $ModulePath -Repository PSGallery -ApiKey $APIKey -Verbose" + Write-Output "Publish-PSResource -Path $ModulePath -Repository PSGallery -ApiKey $APIKey" } else { try { Publish-PSResource -Path $ModulePath -Repository PSGallery -ApiKey $APIKey @@ -317,10 +330,10 @@ function Publish-PSModule { } } if ($whatIf) { - Write-Output "gh pr comment $($pull_request.number) -b 'Published to the PowerShell Gallery [$newVersion]($releaseURL) has been created.'" + Write-Output "gh pr comment $($pull_request.number) -b 'Published to the PowerShell Gallery [$publishPSVersion]($psGalleryReleaseLink) has been created.'" } else { - Write-Output "::notice::Module [$Name - $newVersion] published to the PowerShell Gallery." - gh pr comment $pull_request.number -b "Module [$Name - $newVersion] published to the PowerShell Gallery." + Write-GithubNotice "Module [$Name - $publishPSVersion] published to the PowerShell Gallery." + gh pr comment $pull_request.number -b "Module [$Name - $publishPSVersion]($psGalleryReleaseLink) published to the PowerShell Gallery." if ($LASTEXITCODE -ne 0) { Write-Error 'Failed to comment on the pull request.' exit $LASTEXITCODE @@ -329,7 +342,7 @@ function Publish-PSModule { } LogGroup 'New-GitHubRelease' { - Write-Verbose 'Create new GitHub release' + Write-Output 'Create new GitHub release' if ($createPrerelease) { if ($whatIf) { Write-Output "WhatIf: gh release create $newVersion --title $newVersion --target $prHeadRef --generate-notes --prerelease" @@ -360,7 +373,7 @@ function Publish-PSModule { exit $LASTEXITCODE } } - Write-Output "::notice::Release created: [$newVersion]" + Write-GithubNotice "Release created: [$newVersion]" } } From d2a9021211615184a35006bfe904ded67d16a8b6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 24 Jan 2025 22:46:13 +0100 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Require=20`PSSemV?= =?UTF-8?q?er`=20and=20improve=20logging=20(#44)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This pull request includes several updates and improvements to the `Publish-PSModule` function in the `scripts/helpers/Publish-PSModule.ps1` file. The changes focus on enhancing logging, error handling, and parameter management for PowerShell Gallery operations. Enhancements to logging and error handling: * Added `Write-Output` statements to log the process of finding modules and prerelease versions in the PowerShell Gallery. [[1]](diffhunk://#diff-780715ac24c6bbe21b54f3d268778136b79f21a62275bbd494dfa857b4ba40d9R173-R177) [[2]](diffhunk://#diff-780715ac24c6bbe21b54f3d268778136b79f21a62275bbd494dfa857b4ba40d9L263-R275) * Replaced `Write-Output $_` with `throw $_` to improve error handling during retries. Parameter management improvements: * Introduced a hashtable `$params` to manage parameters for the `Find-PSResource` cmdlet, improving code readability and maintainability. Minor corrections: * Corrected the casing of `Write-GitHubNotice` from `Write-GithubNotice` to ensure consistent function naming. [[1]](diffhunk://#diff-780715ac24c6bbe21b54f3d268778136b79f21a62275bbd494dfa857b4ba40d9L335-R347) [[2]](diffhunk://#diff-780715ac24c6bbe21b54f3d268778136b79f21a62275bbd494dfa857b4ba40d9L376-R388) Module dependencies: * Added `PSSemVer` to the list of required modules in the script header. ## Type of change - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas --- scripts/helpers/Publish-PSModule.ps1 | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/scripts/helpers/Publish-PSModule.ps1 b/scripts/helpers/Publish-PSModule.ps1 index 0023a2b..c0c1b5f 100644 --- a/scripts/helpers/Publish-PSModule.ps1 +++ b/scripts/helpers/Publish-PSModule.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules Utilities, PowerShellGet, Microsoft.PowerShell.PSResourceGet, Retry, GitHub +#Requires -Modules Utilities, PowerShellGet, Microsoft.PowerShell.PSResourceGet, Retry, GitHub, PSSemVer function Publish-PSModule { <# @@ -170,9 +170,11 @@ function Publish-PSModule { LogGroup 'Get latest version - PSGallery' { try { Retry -Count 5 -Delay 10 { + Write-Output "Finding module [$Name] in the PowerShell Gallery." $latest = Find-PSResource -Name $Name -Repository PSGallery -Verbose:$false + Write-Output ($latest | Format-Table | Out-String) } -Catch { - Write-Output $_ + throw $_ } $psGalleryVersion = New-PSSemVer -Version $latest.Version } catch { @@ -260,7 +262,17 @@ function Publish-PSModule { $newVersionString = "$($newVersion.Major).$($newVersion.Minor).$($newVersion.Patch)" # PowerShell Gallery - $psGalleryPrereleases = Find-PSResource -Name $Name -Repository PSGallery -Verbose:$false -Version * -Prerelease + $params = @{ + Name = $Name + Version = '*' + Prerelease = $true + Repository = 'PSGallery' + Verbose = $false + ErrorAction = 'SilentlyContinue' + } + Write-Output 'Finding the latest prerelease version in the PowerShell Gallery.' + Write-Output ($params | Format-Table | Out-String) + $psGalleryPrereleases = Find-PSResource @params $psGalleryPrereleases = $psGalleryPrereleases | Where-Object { $_.Version -like "$newVersionString" } $psGalleryPrereleases = $psGalleryPrereleases | Where-Object { $_.Prerelease -like "$prereleaseName*" } $latestPSGalleryPrerelease = $psGalleryPrereleases.Prerelease | ForEach-Object { @@ -332,7 +344,7 @@ function Publish-PSModule { if ($whatIf) { Write-Output "gh pr comment $($pull_request.number) -b 'Published to the PowerShell Gallery [$publishPSVersion]($psGalleryReleaseLink) has been created.'" } else { - Write-GithubNotice "Module [$Name - $publishPSVersion] published to the PowerShell Gallery." + Write-GitHubNotice "Module [$Name - $publishPSVersion] published to the PowerShell Gallery." gh pr comment $pull_request.number -b "Module [$Name - $publishPSVersion]($psGalleryReleaseLink) published to the PowerShell Gallery." if ($LASTEXITCODE -ne 0) { Write-Error 'Failed to comment on the pull request.' @@ -373,7 +385,7 @@ function Publish-PSModule { exit $LASTEXITCODE } } - Write-GithubNotice "Release created: [$newVersion]" + Write-GitHubNotice "Release created: [$newVersion]" } } From 2fa2eb62c8f6cb65d60ecd9be5c2b16216624ea8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 16 Feb 2025 17:38:27 +0100 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20linter?= =?UTF-8?q?=20and=20git=20configuration=20(#47)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This pull request includes updates to the configuration files for various linters and a minor update to the LICENSE file. The most important changes include the addition of a new configuration file for JSCPD, updates to the PowerShell PSScriptAnalyzer settings, and a modification to the GitHub workflow for super-linter. Linter configuration updates: * [`.github/linters/.jscpd.json`](diffhunk://#diff-557094e283c00b23265c1c75872f41c6b1a524a00f0d99dd68ebd22cb63bfdd6R1-R10): Added a new configuration file for JSCPD to set the threshold to 0, specify reporters, and ignore test files. * [`.github/linters/.powershell-psscriptanalyzer.psd1`](diffhunk://#diff-aae69c9d6774628ed181eacf53aee0f38eb6c2f53492cf3a5b7f7bdb6ef43b6aL1-L16): Updated the PSScriptAnalyzer settings to enable specific rules and configure their parameters, while also excluding certain rules. GitHub workflow update: * [`.github/workflows/Linter.yml`](diffhunk://#diff-482e65806ed9e4a7320f14964764086b91fed4a28d12e4efde1776472e147e79R30): Disabled JSON Prettier validation in the super-linter GitHub workflow. Minor update: * [`LICENSE`](diffhunk://#diff-c693279643b8cd5d248172d9c22cb7cf4ed163a3c98c8a3f69c2717edd3eacb7L3-R3): Updated the copyright year from 2024 to 2025. ## Type of change - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas --- .github/linters/.jscpd.json | 10 + .../linters/.powershell-psscriptanalyzer.psd1 | 67 ++- .github/linters/.textlintrc | 513 ++++++++++++++++++ .github/workflows/Linter.yml | 1 + .gitignore | 11 +- LICENSE | 2 +- scripts/helpers/Publish-PSModule.ps1 | 68 ++- 7 files changed, 630 insertions(+), 42 deletions(-) create mode 100644 .github/linters/.jscpd.json create mode 100644 .github/linters/.textlintrc diff --git a/.github/linters/.jscpd.json b/.github/linters/.jscpd.json new file mode 100644 index 0000000..23970e8 --- /dev/null +++ b/.github/linters/.jscpd.json @@ -0,0 +1,10 @@ +{ + "threshold": 0, + "reporters": [ + "consoleFull" + ], + "ignore": [ + "**/tests/**" + ], + "absolute": true +} diff --git a/.github/linters/.powershell-psscriptanalyzer.psd1 b/.github/linters/.powershell-psscriptanalyzer.psd1 index 6779d06..09cc3d0 100644 --- a/.github/linters/.powershell-psscriptanalyzer.psd1 +++ b/.github/linters/.powershell-psscriptanalyzer.psd1 @@ -1,17 +1,56 @@ -#Documentation: https://github.com/PowerShell/PSScriptAnalyzer/blob/master/docs/Cmdlets/Invoke-ScriptAnalyzer.md#-settings -@{ - #CustomRulePath='path\to\CustomRuleModule.psm1' - #RecurseCustomRulePath='path\of\customrules' - #Severity = @( - # 'Error' - # 'Warning' - #) - #IncludeDefaultRules=${true} +@{ + Rules = @{ + PSAlignAssignmentStatement = @{ + Enable = $true + CheckHashtable = $true + } + PSAvoidLongLines = @{ + Enable = $true + MaximumLineLength = 150 + } + PSAvoidSemicolonsAsLineTerminators = @{ + Enable = $true + } + PSPlaceCloseBrace = @{ + Enable = $true + NewLineAfter = $false + IgnoreOneLineBlock = $true + NoEmptyLineBefore = $false + } + PSPlaceOpenBrace = @{ + Enable = $true + OnSameLine = $true + NewLineAfter = $true + IgnoreOneLineBlock = $true + } + PSProvideCommentHelp = @{ + Enable = $true + ExportedOnly = $false + BlockComment = $true + VSCodeSnippetCorrection = $false + Placement = 'begin' + } + PSUseConsistentIndentation = @{ + Enable = $true + IndentationSize = 4 + PipelineIndentation = 'IncreaseIndentationForFirstPipeline' + Kind = 'space' + } + PSUseConsistentWhitespace = @{ + Enable = $true + CheckInnerBrace = $true + CheckOpenBrace = $true + CheckOpenParen = $true + CheckOperator = $true + CheckPipe = $true + CheckPipeForRedundantWhitespace = $true + CheckSeparator = $true + CheckParameter = $true + IgnoreAssignmentOperatorInsideHashTable = $true + } + } ExcludeRules = @( - 'PSAvoidUsingWriteHost' + 'PSMissingModuleManifestField', # This rule is not applicable until the module is built. + 'PSUseToExportFieldsInManifest' ) - #IncludeRules = @( - # 'PSAvoidUsingWriteHost', - # 'MyCustomRuleName' - #) } diff --git a/.github/linters/.textlintrc b/.github/linters/.textlintrc new file mode 100644 index 0000000..db48de8 --- /dev/null +++ b/.github/linters/.textlintrc @@ -0,0 +1,513 @@ +{ + "filters": { + "comments": true + }, + "rules": { + "terminology": { + "defaultTerms": false, + "terms": [ + "Airbnb", + "Android", + "AppleScript", + "AppVeyor", + "AVA", + "BrowserStack", + "Browsersync", + "Codecov", + "CodePen", + "CodeSandbox", + "DefinitelyTyped", + "EditorConfig", + "ESLint", + "GitHub", + "GraphQL", + "GraphiQL", + "iOS", + "JavaScript", + "JetBrains", + "jQuery", + "LinkedIn", + "Lodash", + "MacBook", + "Markdown", + "OpenType", + "PayPal", + "PhpStorm", + "PowerShell", + "PlayStation", + "RubyMine", + "Sass", + "SemVer", + "TypeScript", + "UglifyJS", + "Wasm", + "WebAssembly", + "WebStorm", + "WordPress", + "YouTube", + [ + "Common[ .]js", + "CommonJS" + ], + [ + "JSDocs?", + "JSDoc" + ], + [ + "Node[ .]js", + "Node.js" + ], + [ + "React[ .]js", + "React" + ], + [ + "SauceLabs", + "Sauce Labs" + ], + [ + "StackOverflow", + "Stack Overflow" + ], + [ + "styled ?components", + "styled-components" + ], + [ + "HTTP[ /]2(?:\\.0)?", + "HTTP/2" + ], + [ + "OS X", + "macOS" + ], + [ + "Mac ?OS", + "macOS" + ], + [ + "a npm", + "an npm" + ], + "ECMAScript", + [ + "ES2015", + "ES6" + ], + [ + "ES7", + "ES2016" + ], + "3D", + [ + "3-D", + "3D" + ], + "Ajax", + "API", + "APIs", + "API's", + [ + "(? [OutputType([void])] [CmdletBinding()] + #Requires -Modules Utilities, PowerShellGet, Microsoft.PowerShell.PSResourceGet, Retry, GitHub, PSSemVer [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSReviewUnusedParameter', '', Scope = 'Function', Justification = 'LogGroup - Scoping affects the variables line of sight.' @@ -43,17 +42,37 @@ function Publish-PSModule { $configuration = ConvertFrom-Yaml -Yaml (Get-Content $env:GITHUB_ACTION_INPUT_ConfigurationFile -Raw) } - $autoCleanup = ($configuration.AutoCleanup | IsNotNullOrEmpty) ? $configuration.AutoCleanup -eq 'true' : $env:GITHUB_ACTION_INPUT_AutoCleanup -eq 'true' - $autoPatching = ($configuration.AutoPatching | IsNotNullOrEmpty) ? $configuration.AutoPatching -eq 'true' : $env:GITHUB_ACTION_INPUT_AutoPatching -eq 'true' - $datePrereleaseFormat = ($configuration.DatePrereleaseFormat | IsNotNullOrEmpty) ? $configuration.DatePrereleaseFormat : $env:GITHUB_ACTION_INPUT_DatePrereleaseFormat - $incrementalPrerelease = ($configuration.IncrementalPrerelease | IsNotNullOrEmpty) ? $configuration.IncrementalPrerelease -eq 'true' : $env:GITHUB_ACTION_INPUT_IncrementalPrerelease -eq 'true' - $versionPrefix = ($configuration.VersionPrefix | IsNotNullOrEmpty) ? $configuration.VersionPrefix : $env:GITHUB_ACTION_INPUT_VersionPrefix - $whatIf = ($configuration.WhatIf | IsNotNullOrEmpty) ? $configuration.WhatIf -eq 'true' : $env:GITHUB_ACTION_INPUT_WhatIf -eq 'true' - - $ignoreLabels = (($configuration.IgnoreLabels | IsNotNullOrEmpty) ? $configuration.IgnoreLabels : $env:GITHUB_ACTION_INPUT_IgnoreLabels) -split ',' | ForEach-Object { $_.Trim() } - $majorLabels = (($configuration.MajorLabels | IsNotNullOrEmpty) ? $configuration.MajorLabels : $env:GITHUB_ACTION_INPUT_MajorLabels) -split ',' | ForEach-Object { $_.Trim() } - $minorLabels = (($configuration.MinorLabels | IsNotNullOrEmpty) ? $configuration.MinorLabels : $env:GITHUB_ACTION_INPUT_MinorLabels) -split ',' | ForEach-Object { $_.Trim() } - $patchLabels = (($configuration.PatchLabels | IsNotNullOrEmpty) ? $configuration.PatchLabels : $env:GITHUB_ACTION_INPUT_PatchLabels) -split ',' | ForEach-Object { $_.Trim() } + $autoCleanup = ($configuration.AutoCleanup | IsNotNullOrEmpty) ? + $configuration.AutoCleanup -eq 'true' : + $env:GITHUB_ACTION_INPUT_AutoCleanup -eq 'true' + $autoPatching = ($configuration.AutoPatching | IsNotNullOrEmpty) ? + $configuration.AutoPatching -eq 'true' : + $env:GITHUB_ACTION_INPUT_AutoPatching -eq 'true' + $datePrereleaseFormat = ($configuration.DatePrereleaseFormat | IsNotNullOrEmpty) ? + $configuration.DatePrereleaseFormat : + $env:GITHUB_ACTION_INPUT_DatePrereleaseFormat + $incrementalPrerelease = ($configuration.IncrementalPrerelease | IsNotNullOrEmpty) ? + $configuration.IncrementalPrerelease -eq 'true' : + $env:GITHUB_ACTION_INPUT_IncrementalPrerelease -eq 'true' + $versionPrefix = ($configuration.VersionPrefix | IsNotNullOrEmpty) ? + $configuration.VersionPrefix : + $env:GITHUB_ACTION_INPUT_VersionPrefix + $whatIf = ($configuration.WhatIf | IsNotNullOrEmpty) ? + $configuration.WhatIf -eq 'true' : + $env:GITHUB_ACTION_INPUT_WhatIf -eq 'true' + + $ignoreLabels = (($configuration.IgnoreLabels | IsNotNullOrEmpty) ? + $configuration.IgnoreLabels : + $env:GITHUB_ACTION_INPUT_IgnoreLabels) -split ',' | ForEach-Object { $_.Trim() } + $majorLabels = (($configuration.MajorLabels | IsNotNullOrEmpty) ? + $configuration.MajorLabels : + $env:GITHUB_ACTION_INPUT_MajorLabels) -split ',' | ForEach-Object { $_.Trim() } + $minorLabels = (($configuration.MinorLabels | IsNotNullOrEmpty) ? + $configuration.MinorLabels : + $env:GITHUB_ACTION_INPUT_MinorLabels) -split ',' | ForEach-Object { $_.Trim() } + $patchLabels = (($configuration.PatchLabels | IsNotNullOrEmpty) ? + $configuration.PatchLabels : + $env:GITHUB_ACTION_INPUT_PatchLabels) -split ',' | ForEach-Object { $_.Trim() } Write-Output '-------------------------------------------------' Write-Output "Auto cleanup enabled: [$autoCleanup]" @@ -131,7 +150,9 @@ function Publish-PSModule { $majorRelease = ($labels | Where-Object { $majorLabels -contains $_ }).Count -gt 0 $minorRelease = ($labels | Where-Object { $minorLabels -contains $_ }).Count -gt 0 -and -not $majorRelease - $patchRelease = (($labels | Where-Object { $patchLabels -contains $_ }).Count -gt 0 -or $autoPatching) -and -not $majorRelease -and -not $minorRelease + $patchRelease = ( + ($labels | Where-Object { $patchLabels -contains $_ } + ).Count -gt 0 -or $autoPatching) -and -not $majorRelease -and -not $minorRelease Write-Output '-------------------------------------------------' Write-Output "Create a release: [$createRelease]" @@ -342,7 +363,10 @@ function Publish-PSModule { } } if ($whatIf) { - Write-Output "gh pr comment $($pull_request.number) -b 'Published to the PowerShell Gallery [$publishPSVersion]($psGalleryReleaseLink) has been created.'" + Write-Output ( + "gh pr comment $($pull_request.number) -b 'Published to the" + + " PowerShell Gallery [$publishPSVersion]($psGalleryReleaseLink) has been created.'" + ) } else { Write-GitHubNotice "Module [$Name - $publishPSVersion] published to the PowerShell Gallery." gh pr comment $pull_request.number -b "Module [$Name - $publishPSVersion]($psGalleryReleaseLink) published to the PowerShell Gallery."