From 7aaef7b00394f0c340152edea838674ffc068b66 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 11 Jan 2025 14:15:27 +0100 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20Retry=20on?= =?UTF-8?q?=20Install-Module=20(#88)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This pull request introduces changes to the `Resolve-PSModuleDependency.ps1` script to improve module installation reliability by adding retry logic. Enhancements to module installation: * [`scripts/helpers/Resolve-PSModuleDependency.ps1`](diffhunk://#diff-48557b471e7d62a89be3627235334ab8a39eb6119174abb61714b92d844508e2L1-R3): Added a `#Requires -Modules Retry` directive to ensure the `Retry` module is available. * [`scripts/helpers/Resolve-PSModuleDependency.ps1`](diffhunk://#diff-48557b471e7d62a89be3627235334ab8a39eb6119174abb61714b92d844508e2R52-R54): Wrapped the `Install-Module` command with retry logic, attempting the installation up to 5 times with a 10-second delay between attempts. ## 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/Resolve-PSModuleDependency.ps1 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/helpers/Resolve-PSModuleDependency.ps1 b/scripts/helpers/Resolve-PSModuleDependency.ps1 index 65980b82..8a6ddca8 100644 --- a/scripts/helpers/Resolve-PSModuleDependency.ps1 +++ b/scripts/helpers/Resolve-PSModuleDependency.ps1 @@ -1,4 +1,6 @@ -ο»Ώfunction Resolve-PSModuleDependency { +ο»Ώ#Requires -Modules Retry + +function Resolve-PSModuleDependency { <# .SYNOPSIS Resolve dependencies for a module based on the manifest file. @@ -47,7 +49,9 @@ Write-Host "[$($installParams.Name)] - Installing module" $VerbosePreferenceOriginal = $VerbosePreference $VerbosePreference = 'SilentlyContinue' - Install-Module @installParams -AllowPrerelease:$false + Retry -Count 5 -Delay 10 { + Install-Module @installParams -AllowPrerelease:$false + } $VerbosePreference = $VerbosePreferenceOriginal Write-Host "[$($installParams.Name)] - Importing module" $VerbosePreferenceOriginal = $VerbosePreference From e96fb1569b3dace7e292c5bb36537f9c17ff75aa Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 30 Jan 2025 22:36:26 +0100 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=AA=B2=20[Fix]:=20Fix=20script=20path?= =?UTF-8?q?=20and=20improve=20test=20result=20handling=20(#91)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This pull request includes changes to the GitHub Actions workflow and the PowerShell script used for testing. The most important changes include updating the script path in the action configuration and modifying the handling of test results in the PowerShell script. ### Workflow Updates: * [`action.yml`](diffhunk://#diff-1243c5424efaaa19bd8e813c5e6f6da46316e63761421b3e5f5c8ced9a36e6b6L72-R72): Updated the script path in the `runs:` section to use a more straightforward syntax. ### Script Enhancements: * [`scripts/main.ps1`](diffhunk://#diff-dc2e5a659836b1b73abb03421c567f5018c2755677c4a0aa764cb26117b68011R53-R63): Improved the handling of test results by setting GitHub output values for passed tests and using a return variable to determine the exit code. ## 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 --- action.yml | 2 +- scripts/main.ps1 | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index bb2b7b4c..03e4bdd5 100644 --- a/action.yml +++ b/action.yml @@ -69,7 +69,7 @@ runs: ShowOutput: true Script: | # Test-PSModule - . (Join-Path -Path '${{ github.action_path }}' -ChildPath 'scripts\main.ps1') + ${{ github.action_path }}/scripts/main.ps1 - name: Upload test results uses: actions/upload-artifact@v4 diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 116f6886..a8cf4df6 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -50,11 +50,14 @@ $failedTests = [int]$testResults.FailedCount if (($failedTests -gt 0) -or ($testResults.Result -ne 'Passed')) { Write-GitHubError "❌ Some [$failedTests] tests failed." + Set-GitHubOutput -Name 'passed' -Value $false + $return = 1 } if ($failedTests -eq 0) { Write-GitHubNotice 'βœ… All tests passed.' + Set-GitHubOutput -Name 'passed' -Value $true + $return = 0 } -Set-GitHubOutput -Name 'passed' -Value ($failedTests -eq 0) Write-Host '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━' -exit $failedTests +exit $return From 49dd4d7279ac3046cf0b5325cdf05b70725a3fc5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 30 Jan 2025 22:50:54 +0100 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=AA=B2=20[Fix]:=20Fix=20conditional?= =?UTF-8?q?=20logic=20for=20test=20result=20handling=20(#92)?= 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 `scripts/main.ps1` file. The change modifies the conditional logic to use an `elseif` statement instead of a separate `if` statement, ensuring that the script correctly handles the cases where tests have failed or all tests have passed. * [`scripts/main.ps1`](diffhunk://#diff-dc2e5a659836b1b73abb03421c567f5018c2755677c4a0aa764cb26117b68011L55-R55): Changed the conditional logic from a separate `if` statement to an `elseif` statement to handle test results more accurately. ## 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/main.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index a8cf4df6..39d0bfda 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -52,8 +52,7 @@ if (($failedTests -gt 0) -or ($testResults.Result -ne 'Passed')) { Write-GitHubError "❌ Some [$failedTests] tests failed." Set-GitHubOutput -Name 'passed' -Value $false $return = 1 -} -if ($failedTests -eq 0) { +} elseif ($failedTests -eq 0) { Write-GitHubNotice 'βœ… All tests passed.' Set-GitHubOutput -Name 'passed' -Value $true $return = 0 From 1fd648f023fd7282cc7831587ff3b7d3a163daf6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 16 Feb 2025 18:16:58 +0100 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20linter?= =?UTF-8?q?=20and=20git=20configuration=20(#97)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This pull request includes several updates to configuration files and scripts, primarily focusing on code quality and compliance improvements. The most significant changes include updating linter configurations, modifying PowerShell script settings, and updating the license year. ### Linter Configuration Updates: * Added a new `.jscpd.json` configuration file to set up code duplication detection with specific thresholds and ignore patterns. * Updated `.powershell-psscriptanalyzer.psd1` to enable specific rules and adjust settings for PowerShell script analysis. * Updated `.github/workflows/Linter.yml` to disable JSON Prettier validation. ### PowerShell Script Updates: * Added `SuppressMessageAttribute` to suppress specific PSScriptAnalyzer rules in `Resolve-PSModuleDependency.ps1` and `Test-PSModule.ps1`. [[1]](diffhunk://#diff-48557b471e7d62a89be3627235334ab8a39eb6119174abb61714b92d844508e2R21-R25) [[2]](diffhunk://#diff-2100eb52126417766eeb5b98f9c6a0da1dd10302b3b7c05d476295e3bd76ce76R12-R15) * Added `SuppressMessageAttribute` to the main script `main.ps1` to suppress the `PSAvoidUsingWriteHost` rule. ### License Update: * Updated the license year in the `LICENSE` file 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 | 11 + .../linters/.powershell-psscriptanalyzer.psd1 | 68 ++- .github/linters/.textlintrc | 513 ++++++++++++++++++ .github/workflows/Linter.yml | 2 +- .gitignore | 11 +- LICENSE | 2 +- .../helpers/Resolve-PSModuleDependency.ps1 | 8 +- scripts/helpers/Test-PSModule.ps1 | 4 + scripts/main.ps1 | 6 +- 9 files changed, 600 insertions(+), 25 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 00000000..2c6f7c64 --- /dev/null +++ b/.github/linters/.jscpd.json @@ -0,0 +1,11 @@ +{ + "threshold": 0, + "reporters": [ + "consoleFull" + ], + "ignore": [ + "**/tests/**", + "**/.github/workflows/Action-Test*" + ], + "absolute": true +} diff --git a/.github/linters/.powershell-psscriptanalyzer.psd1 b/.github/linters/.powershell-psscriptanalyzer.psd1 index 40d11d60..09cc3d0c 100644 --- a/.github/linters/.powershell-psscriptanalyzer.psd1 +++ b/.github/linters/.powershell-psscriptanalyzer.psd1 @@ -1,18 +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 = @( - 'PSMissingModuleManifestField' - '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 00000000..db48de80 --- /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", + [ + "(? [Alias('Resolve-PSModuleDependencies')] + #Requires -Modules Retry + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingWriteHost', '', Scope = 'Function', + Justification = 'Want to just write to the console, not the pipeline.' + )] [CmdletBinding()] param( # The path to the manifest file. diff --git a/scripts/helpers/Test-PSModule.ps1 b/scripts/helpers/Test-PSModule.ps1 index 27d0e094..bed29ef6 100644 --- a/scripts/helpers/Test-PSModule.ps1 +++ b/scripts/helpers/Test-PSModule.ps1 @@ -9,6 +9,10 @@ 'PSReviewUnusedParameter', '', Scope = 'Function', Justification = 'Parameters are used in nested ScriptBlocks' )] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingWriteHost', '', Scope = 'Function', + Justification = 'Want to just write to the console, not the pipeline.' + )] param( # Path to the folder where the code to test is located. [Parameter(Mandatory)] diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 39d0bfda..575a4ef4 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -1,4 +1,8 @@ -ο»Ώ[CmdletBinding()] +ο»Ώ[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingWriteHost', '', + Justification = 'Want to just write to the console, not the pipeline.' +)] +[CmdletBinding()] param() $path = (Join-Path -Path $PSScriptRoot -ChildPath 'helpers')