From ce03a6c2bee486a758cc137d2064e56953def756 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 27 Oct 2017 11:35:40 -0700 Subject: [PATCH] Make sure web hook gets called (#5249) if something goes wrong during the build, we might exit and not update the badge or fire the webhook. Enable the after_success and after_failure stages of the travis-ci build so we can have a better chance of getting these done. --- .travis.yml | 8 +++++- tools/travis.ps1 | 67 +++++++++++++++++++++++++++++------------------- 2 files changed, 48 insertions(+), 27 deletions(-) diff --git a/.travis.yml b/.travis.yml index ddbdf11f07..888d5404f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,7 +35,7 @@ install: npm install -g markdown-spellcheck@0.11.0; fi - ulimit -n 4096 - - pwsh -File tools/travis.ps1 -Bootstrap + - pwsh -File tools/travis.ps1 -Stage Bootstrap script: - pwsh -File tools/travis.ps1 @@ -43,3 +43,9 @@ script: - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then mdspell '**/*.md' '!powershell/**/*.md' --ignore-numbers --ignore-acronyms --report; fi + +after_failure: + - pwsh -File tools/travis.ps1 -Stage Failure + +after_success: + - pwsh -File tools/travis.ps1 -Stage Success diff --git a/tools/travis.ps1 b/tools/travis.ps1 index fe665737f6..73c3a74808 100644 --- a/tools/travis.ps1 +++ b/tools/travis.ps1 @@ -1,6 +1,8 @@ param( - [switch]$Bootstrap + [ValidateSet('Bootstrap','Build','Failure','Success')] + [String]$Stage = 'Build' ) + Import-Module $PSScriptRoot/../build.psm1 -Force Import-Module $PSScriptRoot/packaging -Force @@ -158,14 +160,14 @@ $isDailyBuild = $env:TRAVIS_EVENT_TYPE -eq 'cron' -or $env:TRAVIS_EVENT_TYPE -eq $cronBuild = $env:TRAVIS_EVENT_TYPE -eq 'cron' $isFullBuild = $isDailyBuild -or $hasFeatureTag -if($Bootstrap.IsPresent) +if($Stage -eq 'Bootstrap') { Write-Host -Foreground Green "Executing travis.ps1 -BootStrap `$isPR='$isPr' - $commitMessage" # Make sure we have all the tags Sync-PSTags -AddRemoteIfMissing Start-PSBootstrap -Package:(-not $isPr) } -else +elseif($Stage -eq 'Build') { $BaseVersion = (Get-PSVersion -OmitCommitId) + '-' Write-Host -Foreground Green "Executing travis.ps1 `$isPR='$isPr' `$isFullBuild='$isFullBuild' - $commitMessage" @@ -269,29 +271,6 @@ else Start-NativeExecution -sb {dotnet nuget push $package --api-key $env:NUGET_KEY --source "$env:NUGET_URL/api/v2/package"} -IgnoreExitcode } } - - # update the badge if you've done a cron build, these are not fatal issues - if ( $cronBuild ) { - try { - $svgData = Get-DailyBadge -result $result - if ( ! $svgData ) { - write-warning "Could not retrieve $result badge" - } - else { - log "Setting status badge to '$result'" - Set-DailyBuildBadge -content $svgData - } - } - catch { - Write-Warning "Could not update status badge: $_" - } - try { - Send-DailyWebHook -result $result - } - catch { - Write-Warning "Could not send webhook: $_" - } - } } # if the tests did not pass, throw the reason why @@ -299,3 +278,39 @@ else Throw $resultError } } +elseif($Stage -in 'Failure', 'Success') +{ + $result = 'PASS' + if($Stage -eq 'Failure') + { + $result = 'FAIL' + } + + if ($cronBuild) { + # update the badge if you've done a cron build, these are not fatal issues + try { + $svgData = Get-DailyBadge -result $result + if ( ! $svgData ) { + write-warning "Could not retrieve $result badge" + } + else { + log "Setting status badge to '$result'" + Set-DailyBuildBadge -content $svgData + } + } + catch { + Write-Warning "Could not update status badge: $_" + } + + try { + Send-DailyWebHook -result $result + } + catch { + Write-Warning "Could not send webhook: $_" + } + } + else { + log 'We only send bagde or webhook update for Cron builds' + } + +}