From d0b7e53c80e623589e995a5aa58c2fec4aa1690a Mon Sep 17 00:00:00 2001 From: Marco Blessing Date: Fri, 15 Jul 2022 08:28:21 +0200 Subject: [PATCH] adds DroneHelper (#61) #### :book: Summary - adds DroneHelper for build pipeline #### :bookmark_tabs: Test Plan > :bulb: Select your test plan for the code changes. - [x] Tested via Drone.io pipeline - [ ] Custom test - [ ] No test plan ##### Details / Justification #### :books: Additional Notes - FileLint / Lint & Pester issues will be fixed in next PR Co-authored-by: OCram85 Reviewed-on: https://gitea.ocram85.com/OCram85/PSCredentialStore/pulls/61 --- .drone.yml | 159 ++++++++++++++++----- build/.gitkeep | 0 resources/PSScriptAnalyzerSettings.psd1 | 139 ++++++++++++++++++ src/Item/New-CredentialStoreItem.Tests.ps1 | 1 - 4 files changed, 262 insertions(+), 37 deletions(-) create mode 100644 build/.gitkeep create mode 100644 resources/PSScriptAnalyzerSettings.psd1 diff --git a/.drone.yml b/.drone.yml index 86f4979..b40edd5 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|Vendor|.Tests.ps1)" 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' -AllowPrerelease -Force; + Import-Module 'DroneHelper' -ErrorAction 'Stop'; + Invoke-FileLinter -Verbose -Debug }" - - 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' -AllowPrerelease -Force; + 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' -AllowPrerelease -Force; + 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' -AllowPrerelease -Force; + 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' -AllowPrerelease -Force; + 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' -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 -Force; + 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' -AllowPrerelease -Force; + Import-Module -Name 'DroneHelper' -ErrorAction 'Stop'; + Install-ModuleDependency; + Invoke-Publish -Verbose + }" diff --git a/build/.gitkeep b/build/.gitkeep new file mode 100644 index 0000000..e69de29 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 + } + } + +} 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' } } - }