Fix drone build pipeline #1

Merged
OCram85 merged 9 commits from DroneTest into master 2022-07-13 16:19:34 +02:00
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
}
}
}