Fix drone build pipeline (#1)
Some checks reported errors
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build was killed

#### 📖 Summary

- fixes dependency for loading the module itself
- adds gitea user as parameter -> deletes old PR comments.

#### 📑 Test Plan

> 💡 Select your test plan for the code changes.

- [x] Tested via Drone.io pipeline
- [ ] Custom test
- [ ] No test plan

##### Details / Justification

<!-- Add your test details or justification for missing tests here. -->

#### 📚 Additional Notes

<!-- A place for additional detail notes. -->

Co-authored-by: OCram85 <marco.blessing@googlemail.com>
Reviewed-on: #1
This commit is contained in:
OCram85 2022-07-13 16:19:33 +02:00
parent 8fd180b776
commit 5559445d7e
7 changed files with 118 additions and 17 deletions

View File

@ -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
}"

View File

@ -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 "& {

View File

@ -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'
}

View File

@ -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

View File

@ -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) {

64
tools/DevDependency.psm1 Normal file
View File

@ -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
}
}
}