From 7606d2d7a9ba4a394c9fec3ec4e91ec06a77766b Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 31 Dec 2017 19:36:51 +0000 Subject: [PATCH] Change Gitlab CI build --- .gitlab-ci.yml | 32 ++++++---------- SnipeitPS/Public/Get-Supplier.ps1 | 39 +++++++++++++++++++ SnipeitPS/SnipeItPS.psd1 | Bin 8482 -> 8524 bytes build.ps1 | 61 ++++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+), 20 deletions(-) create mode 100644 SnipeitPS/Public/Get-Supplier.ps1 create mode 100644 build.ps1 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bc7a59d..0a5aaf4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,29 +1,21 @@ -variables: - GIT_SSL_NO_VERIFY: "true" - -before_script: - - Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null - - Install-Module InvokeBuild, BuildHelpers, PSScriptAnalyzer -force -Scope CurrentUser - - Install-Module Pester -Force -SkipPublisherCheck -Scope CurrentUser - - Import-Module PSScriptAnalyzer -Scope CurrentUser - stages: - test # - release -ps_scriptanalyzer: - stage: test - script: - - $res = (Invoke-ScriptAnalyzer -Path . -Severity Error).count - - if ($res -gt 0) { throw "$($res) Analytics failed."} - tags: - - powershell +variables: + GIT_SSL_NO_VERIFY: "true" + ErrorActionPreference: STOP + +Test: + stage: test + script: + - .\build.ps1 -Tasks 'analyze','test' + except: + - master -# except: -# - master #Release: # stage: release -# script: +# script: # - .\build.ps1 -Tasks 'analyze','test','release' # only: -# - master \ No newline at end of file +# - master diff --git a/SnipeitPS/Public/Get-Supplier.ps1 b/SnipeitPS/Public/Get-Supplier.ps1 new file mode 100644 index 0000000..8c8a0c4 --- /dev/null +++ b/SnipeitPS/Public/Get-Supplier.ps1 @@ -0,0 +1,39 @@ +<# +.SYNOPSIS +# Gets a list of Snipe-it Suppliers + +.PARAMETER url +URL of Snipeit system, can be set using Set-Info command + +.PARAMETER apiKey +Users API Key for Snipeit, can be set using Set-Info command + +.EXAMPLE +Get-Supplier -url "https://assets.example.com" -token "token..." + +.EXAMPLE +Get-Supplier -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "MySupplier" } + +#> + +function Get-Supplier() +{ + Param( + [parameter(mandatory=$true)] + [string]$url, + + [parameter(mandatory=$true)] + [string]$apiKey + ) + + $Parameters = @{ + Uri = "$url/api/v1/suppliers" + Method = 'Get' + Token = $apiKey + } + + $result = Invoke-SnipeitMethod @Parameters + + $result +} + diff --git a/SnipeitPS/SnipeItPS.psd1 b/SnipeitPS/SnipeItPS.psd1 index 76d510ddf8c2c61d91dd66af56b8bc3b92fbf3ae..3b16a4eb52d4db127170a5560f145a1963689ac3 100644 GIT binary patch delta 28 icmZ4FbjE4J9+AmEge16w8A=%nfG~$4bMsb_Tpj?N!3m`R delta 12 TcmX@(w8&}09+Az@MACQwC|?DV diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..89afefb --- /dev/null +++ b/build.ps1 @@ -0,0 +1,61 @@ +param( + [string[]]$Tasks +) + +function Install-Dependency([string] $Name) +{ + $policy = Get-PSRepository -Name "PSGallery" | Select-Object -ExpandProperty "InstallationPolicy" + if($policy -ne "Trusted") { + Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted + } + + if (!(Get-Module -Name $Name -ListAvailable)) { + Install-Module -Name $Name -Scope CurrentUser + } +} + +function Analyze-Scripts +{ + param( + [string]$Path = "$PSScriptRoot\SnipeitPS\" + ) + $result = Invoke-ScriptAnalyzer -Path $Path -Severity @('Error', 'Warning') -Recurse + if ($result) { + $result | Format-Table + Write-Error -Message "$($result.SuggestedCorrections.Count) linting errors or warnings were found. The build cannot continue." + EXIT 1 + } +} + +function Run-Tests +{ + param( + [string]$Path = "$PSScriptRoot\SnipeitPS" + ) + + $results = Invoke-Pester -Path $Path -PassThru + if($results.FailedCount -gt 0) { + Write-Output " > $($results.FailedCount) tests failed. The build cannot continue." + foreach($result in $($results.TestResult | Where {$_.Passed -eq $false} | Select-Object -Property Describe,Context,Name,Passed,Time)){ + Write-Output " > $result" + } + + EXIT 1 + } +} + +foreach($task in $Tasks){ + switch($task) + { + "analyze" { + Install-Dependency -Name "PSScriptAnalyzer" + Write-Output "Analyzing Scripts..." + Analyze-Scripts + } + "test" { + Install-Dependency -Name "Pester" + Write-Output "Running Pester Tests..." + Run-Tests + } + } +}