diff --git a/.drone.yml b/.drone.yml index 52e51d3..17fcff7 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,7 +1,7 @@ --- kind: pipeline type: docker -name: Linux_PWSH7_Build +name: PWSH_LTS_7.2_Ubuntu-focal platform: os: linux @@ -9,7 +9,7 @@ platform: steps: - name: Environments - image: mcr.microsoft.com/powershell:latest + image: mcr.microsoft.com/powershell:lts-7.2-ubuntu-focal commands: - | pwsh -NonInteractive -c "& { @@ -18,7 +18,7 @@ steps: }" - name: LintTests - image: mcr.microsoft.com/powershell:latest + image: mcr.microsoft.com/powershell:lts-7.2-ubuntu-focal failure: ignore commands: - | @@ -29,7 +29,7 @@ steps: }" - name: UnitTests - image: mcr.microsoft.com/powershell:latest + image: mcr.microsoft.com/powershell:lts-7.2-ubuntu-focal failure: ignore commands: - | @@ -47,61 +47,11 @@ steps: files: - coverage.xml ---- - -kind: pipeline -type: docker -name: PWSH_LTS_7.2_Ubuntu-focal - -platform: - os: linux - arch: amd64 - - -platform: - os: linux - arch: amd64 - -steps: - - name: Environments - image: mcr.microsoft.com/powershell:lts-7.2-ubuntu-focal - commands: - - | - pwsh -NonInteractive -c "& { - Import-Module './tools/DroneIO.psm1' -Verbose; - Invoke-ShowEnv -Verbose - }" - - - name: LintTests - image: mcr.microsoft.com/powershell:lts-7.2-ubuntu-focal - #failure: ignore - commands: - - | - pwsh -NonInteractive -c "& { - Import-Module './tools/DroneIO.psm1'; - Invoke-InstallDependencies; - Invoke-Linter -ErrorAction 'Stop' - }" - - - name: UnitTests - image: mcr.microsoft.com/powershell:lts-7.2-ubuntu-focal - #failure: ignore - commands: - - | - pwsh -NonInteractive -c "& { - Import-Module './tools/DroneIO.psm1'; - Invoke-InstallDependencies; - Invoke-UnitTest -Verbosity 'Detailed' -ErrorAction 'Stop' - }" - - - name: FinalState + - name: SetPipelineState image: mcr.microsoft.com/powershell:lts-7.2-ubuntu-focal commands: - | pwsh -NonInteractive -c "& { Import-Module './tools/DroneIO.psm1'; - Invoke-ShowEnv -Verbose + Invoke-BuildState -ErrorAction 'Stop' }" - depends_on: - - LintTests - - UnitTests diff --git a/STATE.xml b/STATE.xml new file mode 100644 index 0000000..debbefc --- /dev/null +++ b/STATE.xml @@ -0,0 +1,20 @@ + + + + System.Management.Automation.PSCustomObject + System.Object + + + + + System.Object[] + System.Array + System.Object + + + lint + + + + + \ No newline at end of file diff --git a/tools/DroneIO.psm1 b/tools/DroneIO.psm1 index b201ff4..6f333d6 100644 --- a/tools/DroneIO.psm1 +++ b/tools/DroneIO.psm1 @@ -144,6 +144,7 @@ function Invoke-Linter { "RuleName", "Message" ) -AutoSize | Out-String | Write-Verbose -Verbose + Update-BuildStateFile throw 'PS Script Analyzer failed!' } } @@ -203,6 +204,7 @@ function Invoke-UnitTest { $TestResults = Invoke-Pester -Configuration $PesterConf -ErrorAction 'Stop' if ($TestResults.FailedCount -gt 0) { + Update-BuildStateFile throw ('{0} tests failed!' -f $TestResults.FailedCount) } @@ -211,3 +213,38 @@ function Invoke-UnitTest { } } } + +function Update-BuildStateFile { + [CmdletBinding()] + param ( + [Parameter(Mandatory = $false)] + [ValidateNotNullOrEmpty()] + [string]$StepName = $Env:DRONE_FAILED_STEPS + ) + + process { + $StateFilePath = Join-Path -Path $PWD -ChildPath './STATE.xml' + if (Test-Path -Path $StateFilePath) { + $StateContent = Import-Clixml -Path $StateFilePath + $StateContent.Steps += $StepName + } + else { + $StateContent = [PSCustomObject]@{ + Steps = @($StepName) + } + } + Export-Clixml -Path $StateFilePath -InputObject $StateContent -Force -Encoding utf8NoBOM + } +} + +function Invoke-BuildState { + [CmdletBinding()] + param () + + process { + $StateFilePath = Join-Path -Path $PWD -ChildPath './STATE.xml' + if ( Test-Path -Path $StateFilePath ) { + throw 'One one more pipeline steps failed. Marking the pipeline as failed!' + } + } +}