From 5559445d7ea554e76ae86adcaf3352c235db5b98 Mon Sep 17 00:00:00 2001 From: Marco Blessing Date: Wed, 13 Jul 2022 16:19:33 +0200 Subject: [PATCH] Fix drone build pipeline (#1) #### :book: Summary - fixes dependency for loading the module itself - adds gitea user as parameter -> deletes old PR comments. #### :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 Co-authored-by: OCram85 Reviewed-on: https://gitea.ocram85.com/OCram85/DroneHelper/pulls/1 --- .drone.yml | 50 ++++++++++++++++----- src/CHANGELOG.md => CHANGELOG.md | 0 README.md | 4 +- src/Deploy/Invoke-Publish.ps1 | 4 +- src/Deps/Invoke-InstallDependency.ps1 | 2 +- src/PRComment/Send-PRComment.ps1 | 11 ++++- tools/DevDependency.psm1 | 64 +++++++++++++++++++++++++++ 7 files changed, 118 insertions(+), 17 deletions(-) rename src/CHANGELOG.md => CHANGELOG.md (100%) create mode 100644 tools/DevDependency.psm1 diff --git a/.drone.yml b/.drone.yml index 54c292a..00afd91 100644 --- a/.drone.yml +++ b/.drone.yml @@ -15,9 +15,15 @@ steps: environment: EXCLUDE: "(.exe|.dll|.ico|.gitkeep)" commands: + - | + apt-get update + apt-get install -y file + - | pwsh -NonInteractive -c "& { - Import-Module './src/DroneHelper.psd1'; + Import-Module './tools/DevDependency.psm1' -ErrorAction 'Stop'; + Invoke-FixDevDependency; + Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; Invoke-FileLinter }" @@ -27,7 +33,9 @@ steps: commands: - | pwsh -NonInteractive -c "& { - Import-Module './src/DroneHelper.psd1'; + Import-Module './tools/DevDependency.psm1' -ErrorAction 'Stop'; + Invoke-FixDevDependency; + Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; Invoke-Linter }" @@ -35,9 +43,15 @@ 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 './src/DroneHelper.psd1'; + Import-Module './tools/DevDependency.psm1' -ErrorAction 'Stop'; + Invoke-FixDevDependency; + Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; Invoke-UnitTest -ExcludeTag 'Integration' }" @@ -52,22 +66,32 @@ steps: commands: - | pwsh -NonInteractive -c "& { - Import-Module './src/DroneHelper.psd1'; + Import-Module './tools/DevDependency.psm1' -ErrorAction 'Stop'; + Invoke-FixDevDependency; + Import-Module './src/DroneHelper.psd1' -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 "& { - Import-Module './src/DroneHelper.psd1'; + Import-Module './tools/DevDependency.psm1' -ErrorAction 'Stop'; + Invoke-FixDevDependency; + Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; Invoke-BuildState }" + depends_on: + - "PRComment" --- kind: pipeline @@ -88,12 +112,16 @@ steps: commands: - | pwsh -NonInteractive -c "& { - Import-Module './src/DroneHelper.psd1'; + Import-Module './tools/DevDependency.psm1' -ErrorAction 'Stop'; + Invoke-FixDevDependency; + Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; Update-ModuleMeta -Verbose }" - | pwsh -NonInteractive -c "& { - Import-Module './src/DroneHelper.psd1'; + Import-Module './tools/DevDependency.psm1' -ErrorAction 'Stop'; + Invoke-FixDevDependency; + Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; New-BuildPackage -AdditionalPath './src/Rules' -Verbose }" @@ -112,11 +140,13 @@ 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 "& { - Import-Module './src/DroneHelper.psd1'; + Import-Module './tools/DevDependency.psm1' -ErrorAction 'Stop'; + Invoke-FixDevDependency; + Import-Module './src/DroneHelper.psd1' -ErrorAction 'Stop'; Invoke-Publish -Verbose }" diff --git a/src/CHANGELOG.md b/CHANGELOG.md similarity index 100% rename from src/CHANGELOG.md rename to CHANGELOG.md 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' } 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 diff --git a/src/PRComment/Send-PRComment.ps1 b/src/PRComment/Send-PRComment.ps1 index fe5a906..5b712da 100644 --- a/src/PRComment/Send-PRComment.ps1 +++ b/src/PRComment/Send-PRComment.ps1 @@ -29,10 +29,17 @@ 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 { + # workaround for false positive PSReviewUnusedParameter + $null = $GiteaUser } process { @@ -89,7 +96,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) { 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 + } + } +}