Skip to content

Commit

Permalink
Initial stab at quality gate
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuBuisson committed Sep 12, 2017
1 parent 8f9da75 commit 0a7aede
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
6 changes: 2 additions & 4 deletions PSGithubSearch.BuildSettings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ $Settings = @{
PassThru = $True
}

AnalyzeParams = @{
Path = "$PSScriptRoot\$($env:APPVEYOR_PROJECT_NAME)"
Severity = 'Error'
Recurse = $True
HealthReportParams = @{
Path = (Get-ChildItem -Path '.\PSGithubSearch\PSGithubSearch.psm1').FullName
}

GitHubKey = $env:GitHub_Key
Expand Down
28 changes: 10 additions & 18 deletions PSGithubSearch.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,23 @@ task Test Unit_Tests,
Publish_Unit_Tests_Coverage,
Upload_Test_Results_To_AppVeyor

task Analyze {
task Quality_Gate {
Write-TaskBanner -TaskName $Task.Name

Add-AppveyorTest -Name 'Code Analysis' -Outcome Running
$AnalyzeSettings = $Settings.AnalyzeParams
$Script:AnalyzeFindings = Invoke-ScriptAnalyzer @AnalyzeSettings
Add-AppveyorTest -Name 'Quality Gate' -Outcome Running
$HealthReportSettings = $Settings.HealthReportParams
$Script:HealthReport = Invoke-PSCodeHealth @HealthReportSettings -TestsResult $Script:UnitTestsResult

If ( $AnalyzeFindings ) {
$FindingsString = $AnalyzeFindings | Out-String
Write-Warning $FindingsString
Update-AppveyorTest -Name 'Code Analysis' -Outcome Failed -ErrorMessage $FindingsString
If ( -not($Script:HealthReport) ) {
$ErrorMessage = 'Code health report failed the quality gate. Aborting build'
Update-AppveyorTest -Name 'Quality Gate' -Outcome Failed -ErrorMessage $ErrorMessage
Throw $ErrorMessage
}
Else {
Update-AppveyorTest -Name 'Code Analysis' -Outcome Passed
Update-AppveyorTest -Name 'Quality Gate' -Outcome Passed
}
}

task Fail_If_Analyze_Findings {
Write-TaskBanner -TaskName $Task.Name

$FailureMessage = 'PSScriptAnalyzer found {0} issues. Aborting build' -f $AnalyzeFindings.Count
assert ( -not($AnalyzeFindings) ) $FailureMessage
}

task Set_Module_Version {
Write-TaskBanner -TaskName $Task.Name

Expand Down Expand Up @@ -138,8 +131,7 @@ task Copy_Source_To_Build_Output {
task . Clean,
Install_Dependencies,
Test,
Analyze,
Fail_If_Analyze_Findings,
Quality_Gate,
Set_Module_Version,
Push_Build_Changes_To_Repo,
Copy_Source_To_Build_Output

0 comments on commit 0a7aede

Please sign in to comment.