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: environment:
EXCLUDE: "(.exe|.dll|.ico|.gitkeep)" EXCLUDE: "(.exe|.dll|.ico|.gitkeep)"
commands: commands:
- |
apt-get update
apt-get install -y file
- | - |
pwsh -NonInteractive -c "& { 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 Invoke-FileLinter
}" }"
@ -27,7 +33,9 @@ steps:
commands: commands:
- | - |
pwsh -NonInteractive -c "& { 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 Invoke-Linter
}" }"
@ -35,9 +43,15 @@ steps:
image: mcr.microsoft.com/dotnet/sdk:6.0-focal image: mcr.microsoft.com/dotnet/sdk:6.0-focal
failure: ignore failure: ignore
commands: commands:
- |
apt-get update
apt-get install -y file
- | - |
pwsh -NonInteractive -c "& { 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' Invoke-UnitTest -ExcludeTag 'Integration'
}" }"
@ -52,22 +66,32 @@ steps:
commands: commands:
- | - |
pwsh -NonInteractive -c "& { 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 Send-PRComment
}" }"
when: when:
event: event:
include: include:
- pull_request - pull_request
depends_on:
- "Pwsh FileLinter"
- "ScriptAnalyzer"
- "Pester"
- name: "buildState" - name: "buildState"
image: mcr.microsoft.com/dotnet/sdk:6.0-focal image: mcr.microsoft.com/dotnet/sdk:6.0-focal
commands: commands:
- | - |
pwsh -NonInteractive -c "& { 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 Invoke-BuildState
}" }"
depends_on:
- "PRComment"
--- ---
kind: pipeline kind: pipeline
@ -88,12 +112,16 @@ steps:
commands: commands:
- | - |
pwsh -NonInteractive -c "& { 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 Update-ModuleMeta -Verbose
}" }"
- | - |
pwsh -NonInteractive -c "& { 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 New-BuildPackage -AdditionalPath './src/Rules' -Verbose
}" }"
@ -112,11 +140,13 @@ steps:
image: mcr.microsoft.com/dotnet/sdk:6.0-focal image: mcr.microsoft.com/dotnet/sdk:6.0-focal
#failure: ignore #failure: ignore
environment: environment:
NexusToken: NuGetToken:
from_secret: NexusToken from_secret: PSGallery
commands: commands:
- | - |
pwsh -NonInteractive -c "& { 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 Invoke-Publish -Verbose
}" }"

View File

@ -143,8 +143,8 @@ steps:
image: mcr.microsoft.com/dotnet/sdk:6.0-focal image: mcr.microsoft.com/dotnet/sdk:6.0-focal
#failure: ignore #failure: ignore
environment: environment:
NexusToken: NuGetToken:
from_secret: NexusToken from_secret: PSGallery
commands: commands:
- | - |
pwsh -NonInteractive -c "& { pwsh -NonInteractive -c "& {

View File

@ -35,9 +35,9 @@ function Invoke-Publish {
Expand-Archive @ExpandParams Expand-Archive @ExpandParams
$PublishParams = @{ $PublishParams = @{
Repository = 'Nexus' Repository = 'PSGallery'
Path = $Repo.Bin.ExpandPath Path = $Repo.Bin.ExpandPath
NuGetApiKey = $Env:NexusToken NuGetApiKey = $Env:NuGetToken
Verbose = $VerbosePreference Verbose = $VerbosePreference
ErrorAction = 'Stop' ErrorAction = 'Stop'
} }

View File

@ -48,7 +48,7 @@ function Invoke-InstallDependency {
$PoshParams = @{ $PoshParams = @{
Name = 'posh-git' Name = 'posh-git'
Scope = 'CurrentUser' Scope = 'CurrentUser'
RequiredVersion = '1.0.0' RequiredVersion = '1.1.0'
Force = $true Force = $true
SkipPublisherCheck = $true SkipPublisherCheck = $true
AllowClobber = $true AllowClobber = $true

View File

@ -29,10 +29,17 @@ function Send-PRComment {
param ( param (
[Parameter(Mandatory = $false, HelpMessage = 'HelpMessage')] [Parameter(Mandatory = $false, HelpMessage = 'HelpMessage')]
[ValidateSet('Add', 'Edit', 'Renew')] [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 { begin {
# workaround for false positive PSReviewUnusedParameter
$null = $GiteaUser
} }
process { process {
@ -89,7 +96,7 @@ function Send-PRComment {
if ($Mode -eq 'Renew') { if ($Mode -eq 'Renew') {
$Comments = Invoke-RestMethod -Method 'Get' -Headers $APIHeaders -Uri $CommentAPICall $Comments = Invoke-RestMethod -Method 'Get' -Headers $APIHeaders -Uri $CommentAPICall
$DroneComments = $Comments | Where-Object { $DroneComments = $Comments | Where-Object {
$_.user.login -eq 'drone' $_.user.login -eq $GiteaUser
} | Select-Object -ExpandProperty 'id' } | Select-Object -ExpandProperty 'id'
Write-Debug -Message ('Found Drone comments: {0}.' -f ($DroneComments -join ', ')) Write-Debug -Message ('Found Drone comments: {0}.' -f ($DroneComments -join ', '))
foreach ($id in $DroneComments) { 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
}
}
}