From ff675cc0218ea407c89621c658503505a9043e36 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 13 Jul 2022 14:40:24 +0200 Subject: [PATCH 1/9] update refs Signed-off-by: OCram85 --- src/Deps/Invoke-InstallDependency.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Deps/Invoke-InstallDependency.ps1 b/src/Deps/Invoke-InstallDependency.ps1 index ca685d2..6c451e3 100644 --- a/src/Deps/Invoke-InstallDependency.ps1 +++ b/src/Deps/Invoke-InstallDependency.ps1 @@ -48,7 +48,7 @@ function Invoke-InstallDependency { $PoshParams = @{ Name = 'posh-git' Scope = 'CurrentUser' - RequiredVersion = '1.0.0' + RequiredVersion = '1.1.0' Force = $true SkipPublisherCheck = $true AllowClobber = $true -- 2.40.1 From c76b78de01f22337565d0d01f2783cbfebea6b4a Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 13 Jul 2022 14:45:23 +0200 Subject: [PATCH 2/9] stop pwsh build command on error --- .drone.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.drone.yml b/.drone.yml index 54c292a..6978384 100644 --- a/.drone.yml +++ b/.drone.yml @@ -17,7 +17,7 @@ steps: commands: - | pwsh -NonInteractive -c "& { - Import-Module './src/DroneHelper.psd1'; + Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; Invoke-FileLinter }" @@ -27,7 +27,7 @@ steps: commands: - | pwsh -NonInteractive -c "& { - Import-Module './src/DroneHelper.psd1'; + Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; Invoke-Linter }" @@ -37,7 +37,7 @@ steps: commands: - | pwsh -NonInteractive -c "& { - Import-Module './src/DroneHelper.psd1'; + Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; Invoke-UnitTest -ExcludeTag 'Integration' }" @@ -52,7 +52,7 @@ steps: commands: - | pwsh -NonInteractive -c "& { - Import-Module './src/DroneHelper.psd1'; + Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; Send-PRComment }" when: @@ -65,7 +65,7 @@ steps: commands: - | pwsh -NonInteractive -c "& { - Import-Module './src/DroneHelper.psd1'; + Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; Invoke-BuildState }" @@ -88,12 +88,12 @@ steps: commands: - | pwsh -NonInteractive -c "& { - Import-Module './src/DroneHelper.psd1'; + Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; Update-ModuleMeta -Verbose }" - | pwsh -NonInteractive -c "& { - Import-Module './src/DroneHelper.psd1'; + Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; New-BuildPackage -AdditionalPath './src/Rules' -Verbose }" @@ -117,6 +117,6 @@ steps: commands: - | pwsh -NonInteractive -c "& { - Import-Module './src/DroneHelper.psd1'; + Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; Invoke-Publish -Verbose }" -- 2.40.1 From 68b1e61b697421e62db3b5ae8032450577119de7 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 13 Jul 2022 15:09:01 +0200 Subject: [PATCH 3/9] add workaround helper for dev dependencies --- .drone.yml | 16 ++++++++++ tools/DevDependency.psm1 | 64 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 tools/DevDependency.psm1 diff --git a/.drone.yml b/.drone.yml index 6978384..0a0d422 100644 --- a/.drone.yml +++ b/.drone.yml @@ -17,6 +17,8 @@ steps: commands: - | pwsh -NonInteractive -c "& { + Import-Module './tools/DevDependency.psm1' -ErrorAction 'Stop'; + Invoke-FixDevDependency; Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; Invoke-FileLinter }" @@ -27,6 +29,8 @@ steps: commands: - | pwsh -NonInteractive -c "& { + Import-Module './tools/DevDependency.psm1' -ErrorAction 'Stop'; + Invoke-FixDevDependency; Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; Invoke-Linter }" @@ -37,6 +41,8 @@ steps: commands: - | pwsh -NonInteractive -c "& { + Import-Module './tools/DevDependency.psm1' -ErrorAction 'Stop'; + Invoke-FixDevDependency; Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; Invoke-UnitTest -ExcludeTag 'Integration' }" @@ -52,6 +58,8 @@ steps: commands: - | pwsh -NonInteractive -c "& { + Import-Module './tools/DevDependency.psm1' -ErrorAction 'Stop'; + Invoke-FixDevDependency; Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; Send-PRComment }" @@ -65,6 +73,8 @@ steps: commands: - | pwsh -NonInteractive -c "& { + Import-Module './tools/DevDependency.psm1' -ErrorAction 'Stop'; + Invoke-FixDevDependency; Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; Invoke-BuildState }" @@ -88,11 +98,15 @@ steps: commands: - | pwsh -NonInteractive -c "& { + Import-Module './tools/DevDependency.psm1' -ErrorAction 'Stop'; + Invoke-FixDevDependency; Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; Update-ModuleMeta -Verbose }" - | pwsh -NonInteractive -c "& { + Import-Module './tools/DevDependency.psm1' -ErrorAction 'Stop'; + Invoke-FixDevDependency; Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; New-BuildPackage -AdditionalPath './src/Rules' -Verbose }" @@ -117,6 +131,8 @@ steps: commands: - | pwsh -NonInteractive -c "& { + Import-Module './tools/DevDependency.psm1' -ErrorAction 'Stop'; + Invoke-FixDevDependency; Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; Invoke-Publish -Verbose }" diff --git a/tools/DevDependency.psm1 b/tools/DevDependency.psm1 new file mode 100644 index 0000000..58542ab --- /dev/null +++ b/tools/DevDependency.psm1 @@ -0,0 +1,64 @@ +function Invoke-FixDevDependency { + <# + .SYNOPSIS + Installs dev dependencies. + + .DESCRIPTION + Invoke-FixDevDependency acts as workaround to load the dependencies needed to load the pwsh module. + This is just standalone version of the embedded `Invoke-InstallDependency` which can't be called + by the DroneHelper build pipeline itself. + #> + + [CmdletBinding()] + param () + + process { + try { + $PSScriptParams = @{ + Name = 'PSScriptAnalyzer' + Scope = 'CurrentUser' + RequiredVersion = '1.20.0' + Force = $true + SkipPublisherCheck = $true + AllowClobber = $true + Verbose = $VerbosePreference + ErrorAction = 'Stop' + } + Install-Module @PSScriptParams + + $PesterParams = @{ + Name = 'Pester' + Scope = 'CurrentUser' + RequiredVersion = '5.3.1' + Force = $true + SkipPublisherCheck = $true + AllowClobber = $true + Verbose = $VerbosePreference + ErrorAction = 'Stop' + } + Install-Module @PesterParams + + $PoshParams = @{ + Name = 'posh-git' + Scope = 'CurrentUser' + RequiredVersion = '1.1.0' + Force = $true + SkipPublisherCheck = $true + AllowClobber = $true + Verbose = $VerbosePreference + ErrorAction = 'Stop' + } + Install-Module @PoshParams + } + catch { + $ExecParams = @{ + Exception = [System.Exception]::new( + 'Could not install required build dependencies!', + $PSItem.Exception + ) + ErrorAction = 'Stop' + } + Write-Error @ExecParams + } + } +} -- 2.40.1 From a3cb5a9eff94367fbb687fcc2520d4e657af3122 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 13 Jul 2022 15:11:46 +0200 Subject: [PATCH 4/9] install missing file command --- .drone.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.drone.yml b/.drone.yml index 0a0d422..fe09e7f 100644 --- a/.drone.yml +++ b/.drone.yml @@ -15,6 +15,10 @@ steps: environment: EXCLUDE: "(.exe|.dll|.ico|.gitkeep)" commands: + - | + apt-get update + apt-get install -y file + - | pwsh -NonInteractive -c "& { Import-Module './tools/DevDependency.psm1' -ErrorAction 'Stop'; @@ -39,6 +43,10 @@ steps: 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/DevDependency.psm1' -ErrorAction 'Stop'; -- 2.40.1 From 94404f62cc8c5b6ddfff9b6be8e515f49e1e229c Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 13 Jul 2022 15:47:05 +0200 Subject: [PATCH 5/9] fix changelog location --- src/CHANGELOG.md => CHANGELOG.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/CHANGELOG.md => CHANGELOG.md (100%) diff --git a/src/CHANGELOG.md b/CHANGELOG.md similarity index 100% rename from src/CHANGELOG.md rename to CHANGELOG.md -- 2.40.1 From 96ae14041402bf8fde1094529368a3925f04751f Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 13 Jul 2022 16:01:46 +0200 Subject: [PATCH 6/9] fix NuGet token lookup --- .drone.yml | 4 ++-- README.md | 4 ++-- src/Deploy/Invoke-Publish.ps1 | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.drone.yml b/.drone.yml index fe09e7f..07ca93d 100644 --- a/.drone.yml +++ b/.drone.yml @@ -134,8 +134,8 @@ steps: image: mcr.microsoft.com/dotnet/sdk:6.0-focal #failure: ignore environment: - NexusToken: - from_secret: NexusToken + NuGetToken: + from_secret: PSGallery commands: - | pwsh -NonInteractive -c "& { diff --git a/README.md b/README.md index d30f772..c0aa816 100644 --- a/README.md +++ b/README.md @@ -143,8 +143,8 @@ steps: image: mcr.microsoft.com/dotnet/sdk:6.0-focal #failure: ignore environment: - NexusToken: - from_secret: NexusToken + NuGetToken: + from_secret: PSGallery commands: - | pwsh -NonInteractive -c "& { diff --git a/src/Deploy/Invoke-Publish.ps1 b/src/Deploy/Invoke-Publish.ps1 index f57c3c8..958db5d 100644 --- a/src/Deploy/Invoke-Publish.ps1 +++ b/src/Deploy/Invoke-Publish.ps1 @@ -35,9 +35,9 @@ function Invoke-Publish { Expand-Archive @ExpandParams $PublishParams = @{ - Repository = 'Nexus' + Repository = 'PSGallery' Path = $Repo.Bin.ExpandPath - NuGetApiKey = $Env:NexusToken + NuGetApiKey = $Env:NuGetToken Verbose = $VerbosePreference ErrorAction = 'Stop' } -- 2.40.1 From 9b21febd7e64d336884d142410ce2d2b9b08c3ec Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 13 Jul 2022 16:08:38 +0200 Subject: [PATCH 7/9] add parameter for custom gitea user --- src/PRComment/Send-PRComment.ps1 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/PRComment/Send-PRComment.ps1 b/src/PRComment/Send-PRComment.ps1 index fe5a906..474af59 100644 --- a/src/PRComment/Send-PRComment.ps1 +++ b/src/PRComment/Send-PRComment.ps1 @@ -29,7 +29,12 @@ function Send-PRComment { param ( [Parameter(Mandatory = $false, HelpMessage = 'HelpMessage')] [ValidateSet('Add', 'Edit', 'Renew')] - [string]$Mode = 'Renew' + [string]$Mode = 'Renew', + + [Parameter(Mandatory = $false, HelpMessage = 'Gitea user for drone bot')] + [ValidateNotNullOrEmpty()] + [string]$GiteaUser= 'drone-bot' + ) begin { @@ -89,7 +94,7 @@ function Send-PRComment { if ($Mode -eq 'Renew') { $Comments = Invoke-RestMethod -Method 'Get' -Headers $APIHeaders -Uri $CommentAPICall $DroneComments = $Comments | Where-Object { - $_.user.login -eq 'drone' + $_.user.login -eq $GiteaUser } | Select-Object -ExpandProperty 'id' Write-Debug -Message ('Found Drone comments: {0}.' -f ($DroneComments -join ', ')) foreach ($id in $DroneComments) { -- 2.40.1 From f343fdd365593f7c21b76e14d7fb302ec1bd2f6f Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 13 Jul 2022 16:11:10 +0200 Subject: [PATCH 8/9] run test steps parallel --- .drone.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.drone.yml b/.drone.yml index 07ca93d..00afd91 100644 --- a/.drone.yml +++ b/.drone.yml @@ -75,6 +75,10 @@ steps: event: include: - pull_request + depends_on: + - "Pwsh FileLinter" + - "ScriptAnalyzer" + - "Pester" - name: "buildState" image: mcr.microsoft.com/dotnet/sdk:6.0-focal @@ -86,6 +90,8 @@ steps: Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; Invoke-BuildState }" + depends_on: + - "PRComment" --- kind: pipeline -- 2.40.1 From c56f238cdf1f45e5df81ea3d8c4f1c80303dd36b Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 13 Jul 2022 16:14:08 +0200 Subject: [PATCH 9/9] fix lint issue --- src/PRComment/Send-PRComment.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PRComment/Send-PRComment.ps1 b/src/PRComment/Send-PRComment.ps1 index 474af59..5b712da 100644 --- a/src/PRComment/Send-PRComment.ps1 +++ b/src/PRComment/Send-PRComment.ps1 @@ -33,11 +33,13 @@ function Send-PRComment { [Parameter(Mandatory = $false, HelpMessage = 'Gitea user for drone bot')] [ValidateNotNullOrEmpty()] - [string]$GiteaUser= 'drone-bot' + [string]$GiteaUser = 'drone-bot' ) begin { + # workaround for false positive PSReviewUnusedParameter + $null = $GiteaUser } process { -- 2.40.1