From e82a212fe5e60626f8bf1c0ebe5f4b3aa4724ca9 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Thu, 14 Jul 2022 13:51:01 +0200 Subject: [PATCH 1/8] adds DroneHelper --- .drone.yml | 159 ++++++++++++++++++------ resources/PSScriptAnalyzerSettings.psd1 | 139 +++++++++++++++++++++ 2 files changed, 262 insertions(+), 36 deletions(-) create mode 100644 resources/PSScriptAnalyzerSettings.psd1 diff --git a/.drone.yml b/.drone.yml index 86f4979..3517be9 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,64 +1,151 @@ --- kind: pipeline type: docker -name: PWSH_LTS_7.2_Ubuntu-focal +name: "Build Pipeline" -platform: - os: linux - arch: amd64 +trigger: + branch: + exclude: + - droneDocs/* steps: - - name: Environments - image: mcr.microsoft.com/powershell:lts-7.2-ubuntu-focal + - name: "Pwsh FileLinter" + image: mcr.microsoft.com/dotnet/sdk:6.0-focal + failure: ignore + environment: + EXCLUDE: "(.exe|.dll|.ico|.gitkeep)" commands: + - | + apt-get update + apt-get install -y file + - | pwsh -NonInteractive -c "& { - Import-Module './tools/DroneIO.psm1' -Verbose; - Invoke-ShowEnv -Verbose + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop'; + Import-Module 'DroneHelper' -ErrorAction 'Stop'; + Invoke-FileLinter }" - - name: LintTests - image: mcr.microsoft.com/powershell:lts-7.2-ubuntu-focal + - name: "ScriptAnalyzer" + image: mcr.microsoft.com/dotnet/sdk:6.0-focal failure: ignore commands: - | pwsh -NonInteractive -c "& { - Import-Module './tools/DroneIO.psm1'; - Invoke-InstallDependencies; - Invoke-Linter -ErrorAction 'Stop' + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop'; + Import-Module -Name 'DroneHelper' -ErrorAction 'Stop'; + Install-ModuleDependency; + Invoke-Linter }" - - name: UnitTests - image: mcr.microsoft.com/powershell:lts-7.2-ubuntu-focal + - name: "Pester" + image: mcr.microsoft.com/dotnet/sdk:6.0-focal failure: ignore commands: + - | + apt-get update + apt-get install -y file + - | pwsh -NonInteractive -c "& { - Import-Module './tools/DroneIO.psm1'; - Invoke-InstallDependencies; - Invoke-UnitTest -Verbosity 'Normal' -ExcludeTag @( 'Integration', 'Disabled') -ErrorAction 'Stop' + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop'; + Import-Module -Name 'DroneHelper' -ErrorAction 'Stop'; + Install-ModuleDependency; + Invoke-UnitTest -Verbosity 'Detailed' -ExcludeTag 'Integration' }" - # Disable Codecov for self hosted git - #- name: Coverage - # image: plugins/codecov - # settings: - # token: - # from_secret: CodeCovToken - # files: - # - coverage.xml - # depends_on: - # - UnitTests - - - name: SetPipelineState - image: mcr.microsoft.com/powershell:lts-7.2-ubuntu-focal + - name: "PRComment" + image: mcr.microsoft.com/dotnet/sdk:6.0-focal + failure: ignore + environment: + GITEA_TOKEN: + from_secret: GITEA_TOKEN + CUSTOM_PIPELINE_STATE: true + LOG_FILES: "build/*.log" commands: - | pwsh -NonInteractive -c "& { - Import-Module './tools/DroneIO.psm1'; - Invoke-BuildState -ErrorAction 'Stop' + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop'; + Import-Module -Name 'DroneHelper' -ErrorAction 'Stop'; + Send-PRComment + }" + when: + event: + include: + - pull_request + depends_on: + - "Pwsh FileLinter" + - "ScriptAnalyzer" + - "Pester" + + - name: "buildState" + image: mcr.microsoft.com/dotnet/sdk:6.0-focal + commands: + - | + pwsh -NonInteractive -c "& { + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop'; + Import-Module -Name 'DroneHelper' -ErrorAction 'Stop'; + Install-ModuleDependency; + Invoke-BuildState }" depends_on: - - LintTests - - UnitTests - #- Coverage + - "PRComment" + +--- +kind: pipeline +type: docker +name: "Publish Pipeline" + +depends_on: + - "Build Pipeline" + +trigger: + event: + - tag + +steps: + - name: BuildArtifacts + image: mcr.microsoft.com/dotnet/sdk:6.0-focal + #failure: ignore + commands: + - | + pwsh -NonInteractive -c "& { + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop'; + Import-Module -Name 'DroneHelper' -ErrorAction 'Stop'; + Install-ModuleDependency; + Update-ModuleMeta -Verbose + }" + - | + pwsh -NonInteractive -c "& { + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop'; + Import-Module -Name 'DroneHelper' -ErrorAction 'Stop'; + Install-ModuleDependency; + New-BuildPackage -Verbose + }" + + - name: GiteaRelease + image: plugins/gitea-release + settings: + api_key: + from_secret: GITEA_TOKEN + base_url: https://gitea.ocram85.com + files: + - "bin/${DRONE_REPO_NAME}.zip" + - "bin/PSModule.zip" + title: "${DRONE_TAG}" + note: CHANGELOG.md + + - name: "PublishModule" + image: mcr.microsoft.com/dotnet/sdk:6.0-focal + #failure: ignore + environment: + NuGetToken: + from_secret: PSGallery + commands: + - | + pwsh -NonInteractive -c "& { + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop'; + Import-Module -Name 'DroneHelper' -ErrorAction 'Stop'; + Install-ModuleDependency; + Invoke-Publish -Verbose + }" diff --git a/resources/PSScriptAnalyzerSettings.psd1 b/resources/PSScriptAnalyzerSettings.psd1 new file mode 100644 index 0000000..cbdde9a --- /dev/null +++ b/resources/PSScriptAnalyzerSettings.psd1 @@ -0,0 +1,139 @@ +@{ + Severity = 'Error', 'Warning', 'Information' + + IncludeRules = @( + 'PSAlignAssignmentStatement', + 'PSAvoidAssignmentToAutomaticVariable', + 'AvoidDefaultValueForMandatoryParameter', + 'PSAvoidDefaultValueSwitchParameter', + 'PSAvoidGlobalAliases', + 'ÜSAvoidGlobalFunctions', + 'PSAvoidGlobalVars', + 'PSAvoidInvokingEmptyMembers', + 'PSAvoidLongLines', + 'PSAvoidNullOrEmptyHelpMessageAttribute', + 'PSAvoidOverwritingBuiltInCmdlets', + 'PSAvoidShouldContinueWithoutForce', + 'PSAvoidTrailingWhitespace', + 'PSAvoidUsingCmdletAliases', + 'PSAvoidUsingComputerNameHardcoded', + 'PSAvoidUsingConvertToSecureStringWithPlainText', + 'PSAvoidUsingDeprecatedManifestFields', + 'PSAvoidUsingDoubleQuotesForConstantString', + 'PSAvoidUsingEmptyCatchBlock', + 'PSAvoidUsingInvokeExpression', + 'PSAvoidUsingPlainTextForPassword', + 'PSAvoidUsingPositionalParameters', + 'PSAvoidUsingUsernameAndPasswordParams', + 'PSAvoidUsingWMICmdlet', + 'PSAvoidUsingWriteHost', + 'PSMisleadingBacktick', + 'PSMissingModuleManifestField', + 'PSPlaceCloseBrace', + 'PSPlaceOpenBrace', + 'PSPossibleIncorrectComparisonWithNull', + 'PSPossibleIncorrectUsageOfAssignmentOperator', + 'PSPossibleIncorrectUsageOfRedirectionOperator', + 'PSProvideCommentHelp', + 'PSReservedCmdletChar', + 'PSReservedParams', + 'PSReviewUnusedParameter', + 'PSShouldProcess', + 'PSUseApprovedVerbs', + 'PSUseBOMForUnicodeEncodedFile', + 'PSUseCmdletCorrectly', + 'PSUseCompatibleCmdlets', + #'PSUseCompatibleCommands', + 'PSUseCompatibleSyntax', + #'PSUseCompatibleTypes', + 'PSUseConsistentIndentation', + 'PSUseConsistentWhitespace', + 'PSUseCorrectCasing', + 'PSUseDeclaredVarsMoreThanAssignments', + 'PSUseLiteralInitializerForHashtable', + 'PSUseOutputTypeCorrectly', + 'PSUsePSCredentialType', + 'PSUseProcessBlockForPipelineCommand', + 'PSUseShouldProcessForStateChangingFunctions', + 'PSUseSingularNouns', + 'PSUseSupportsShouldProcess', + 'PSUseToExportFieldsInManifest', + 'PSUseUTF8EncodingForHelpFile', + 'PSUseUsingScopeModifierInNewRunspaces' + ) + + Rules = @{ + + PSAvoidLongLines = @{ + Enable = $true + MaximumLineLength = 116 + } + + PSPlaceOpenBrace = @{ + Enable = $true + OnSameLine = $true + NewLineAfter = $true + IgnoreOneLineBlock = $true + } + + PSPlaceCloseBrace = @{ + Enable = $true + NewLineAfter = $true + IgnoreOneLineBlock = $true + NoEmptyLineBefore = $false + } + + PSProvideCommentHelp = @{ + Enable = $true + ExportedOnly = $false + BlockComment = $true + VSCodeSnippetCorrection = $false + Placement = "begin" + } + + PSUseCompatibleCmdlets = @{ + compatibility = @( + "desktop-5.1.14393.206-windows", + "core-6.1.0-windows" + ) + } + + PSUseCompatibleSyntax = @{ + Enable = $true + TargetVersions = @( + "7.0", + "5.1" + ) + } + + PSUseConsistentIndentation = @{ + Enable = $true + Kind = 'space' + PipelineIndentation = 'IncreaseIndentationForFirstPipeline' + IndentationSize = 4 + } + + PSUseConsistentWhitespace = @{ + Enable = $true + CheckInnerBrace = $true + CheckOpenBrace = $true + CheckOpenParen = $true + CheckOperator = $true + CheckPipe = $true + CheckPipeForRedundantWhitespace = $false + CheckSeparator = $true + CheckParameter = $false + IgnoreAssignmentOperatorInsideHashTable = $true + } + + PSAlignAssignmentStatement = @{ + Enable = $true + CheckHashtable = $false + } + + PSUseCorrectCasing = @{ + Enable = $true + } + } + +} -- 2.40.1 From e84f550aad2ff99d0ac357faccd2353dda447ed4 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Thu, 14 Jul 2022 13:54:13 +0200 Subject: [PATCH 2/8] use preRelease --- .drone.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.drone.yml b/.drone.yml index 3517be9..486dee6 100644 --- a/.drone.yml +++ b/.drone.yml @@ -21,7 +21,7 @@ steps: - | pwsh -NonInteractive -c "& { - Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop'; + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease; Import-Module 'DroneHelper' -ErrorAction 'Stop'; Invoke-FileLinter }" @@ -32,7 +32,7 @@ steps: commands: - | pwsh -NonInteractive -c "& { - Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop'; + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease; Import-Module -Name 'DroneHelper' -ErrorAction 'Stop'; Install-ModuleDependency; Invoke-Linter @@ -48,7 +48,7 @@ steps: - | pwsh -NonInteractive -c "& { - Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop'; + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease; Import-Module -Name 'DroneHelper' -ErrorAction 'Stop'; Install-ModuleDependency; Invoke-UnitTest -Verbosity 'Detailed' -ExcludeTag 'Integration' @@ -65,7 +65,7 @@ steps: commands: - | pwsh -NonInteractive -c "& { - Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop'; + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease; Import-Module -Name 'DroneHelper' -ErrorAction 'Stop'; Send-PRComment }" @@ -83,7 +83,7 @@ steps: commands: - | pwsh -NonInteractive -c "& { - Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop'; + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease; Import-Module -Name 'DroneHelper' -ErrorAction 'Stop'; Install-ModuleDependency; Invoke-BuildState @@ -110,14 +110,14 @@ steps: commands: - | pwsh -NonInteractive -c "& { - Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop'; + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease; Import-Module -Name 'DroneHelper' -ErrorAction 'Stop'; Install-ModuleDependency; Update-ModuleMeta -Verbose }" - | pwsh -NonInteractive -c "& { - Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop'; + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease; Import-Module -Name 'DroneHelper' -ErrorAction 'Stop'; Install-ModuleDependency; New-BuildPackage -Verbose @@ -144,7 +144,7 @@ steps: commands: - | pwsh -NonInteractive -c "& { - Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop'; + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease; Import-Module -Name 'DroneHelper' -ErrorAction 'Stop'; Install-ModuleDependency; Invoke-Publish -Verbose -- 2.40.1 From e219b513f409003a4918ccf0ab837e3d10aa2aee Mon Sep 17 00:00:00 2001 From: OCram85 Date: Thu, 14 Jul 2022 13:56:08 +0200 Subject: [PATCH 3/8] force module installation --- .drone.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.drone.yml b/.drone.yml index 486dee6..12bad7a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -21,7 +21,7 @@ steps: - | pwsh -NonInteractive -c "& { - Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease; + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease -Force; Import-Module 'DroneHelper' -ErrorAction 'Stop'; Invoke-FileLinter }" @@ -32,7 +32,7 @@ steps: commands: - | pwsh -NonInteractive -c "& { - Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease; + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease -Force; Import-Module -Name 'DroneHelper' -ErrorAction 'Stop'; Install-ModuleDependency; Invoke-Linter @@ -48,7 +48,7 @@ steps: - | pwsh -NonInteractive -c "& { - Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease; + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease -Force; Import-Module -Name 'DroneHelper' -ErrorAction 'Stop'; Install-ModuleDependency; Invoke-UnitTest -Verbosity 'Detailed' -ExcludeTag 'Integration' @@ -65,7 +65,7 @@ steps: commands: - | pwsh -NonInteractive -c "& { - Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease; + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease -Force; Import-Module -Name 'DroneHelper' -ErrorAction 'Stop'; Send-PRComment }" @@ -83,7 +83,7 @@ steps: commands: - | pwsh -NonInteractive -c "& { - Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease; + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease -Force; Import-Module -Name 'DroneHelper' -ErrorAction 'Stop'; Install-ModuleDependency; Invoke-BuildState @@ -110,14 +110,14 @@ steps: commands: - | pwsh -NonInteractive -c "& { - Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease; + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease -Force; Import-Module -Name 'DroneHelper' -ErrorAction 'Stop'; Install-ModuleDependency; Update-ModuleMeta -Verbose }" - | pwsh -NonInteractive -c "& { - Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease; + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease -Force; Import-Module -Name 'DroneHelper' -ErrorAction 'Stop'; Install-ModuleDependency; New-BuildPackage -Verbose @@ -144,7 +144,7 @@ steps: commands: - | pwsh -NonInteractive -c "& { - Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease; + Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease -Force; Import-Module -Name 'DroneHelper' -ErrorAction 'Stop'; Install-ModuleDependency; Invoke-Publish -Verbose -- 2.40.1 From e63194f4886774bbcdca770681e19a7740c4f562 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Thu, 14 Jul 2022 14:33:16 +0200 Subject: [PATCH 4/8] add build dir --- build/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 build/.gitkeep diff --git a/build/.gitkeep b/build/.gitkeep new file mode 100644 index 0000000..e69de29 -- 2.40.1 From 96d8cdae1acf4ab453416ddd46b091ba07a88071 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Fri, 15 Jul 2022 07:20:14 +0200 Subject: [PATCH 5/8] Exclude vendor files from FileLinter --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 12bad7a..527c674 100644 --- a/.drone.yml +++ b/.drone.yml @@ -13,7 +13,7 @@ steps: image: mcr.microsoft.com/dotnet/sdk:6.0-focal failure: ignore environment: - EXCLUDE: "(.exe|.dll|.ico|.gitkeep)" + EXCLUDE: "(.exe|.dll|.ico|.gitkeep|Vendor)" commands: - | apt-get update -- 2.40.1 From 6f135b438bb7ed789d84b37875265fb65440a5fb Mon Sep 17 00:00:00 2001 From: OCram85 Date: Fri, 15 Jul 2022 07:36:50 +0200 Subject: [PATCH 6/8] fix encoding --- src/Item/New-CredentialStoreItem.Tests.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Item/New-CredentialStoreItem.Tests.ps1 b/src/Item/New-CredentialStoreItem.Tests.ps1 index 02d1188..4bc582e 100644 --- a/src/Item/New-CredentialStoreItem.Tests.ps1 +++ b/src/Item/New-CredentialStoreItem.Tests.ps1 @@ -142,5 +142,4 @@ Describe "New-CredentialStoreItem" { $writtenItem.GetNetworkCredential().Password | Should -Be 'mypasswd' } } - } -- 2.40.1 From 9c83df15438215b2559e2515e0af9d38faa554b8 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Fri, 15 Jul 2022 08:14:48 +0200 Subject: [PATCH 7/8] Debug FileLinter output --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 527c674..e4135b4 100644 --- a/.drone.yml +++ b/.drone.yml @@ -23,7 +23,7 @@ steps: pwsh -NonInteractive -c "& { Install-Module -Name 'DroneHelper' -Repository 'PSGallery' -ErrorAction 'Stop' -AllowPrerelease -Force; Import-Module 'DroneHelper' -ErrorAction 'Stop'; - Invoke-FileLinter + Invoke-FileLinter -Verbose -Debug }" - name: "ScriptAnalyzer" -- 2.40.1 From 2671cff0f558c177964e370d40fc31e67057c8ea Mon Sep 17 00:00:00 2001 From: OCram85 Date: Fri, 15 Jul 2022 08:25:38 +0200 Subject: [PATCH 8/8] exclude tests file --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index e4135b4..b40edd5 100644 --- a/.drone.yml +++ b/.drone.yml @@ -13,7 +13,7 @@ steps: image: mcr.microsoft.com/dotnet/sdk:6.0-focal failure: ignore environment: - EXCLUDE: "(.exe|.dll|.ico|.gitkeep|Vendor)" + EXCLUDE: "(.exe|.dll|.ico|.gitkeep|Vendor|.Tests.ps1)" commands: - | apt-get update -- 2.40.1