2017-07-14 06:21:32 +02:00
|
|
|
param(
|
|
|
|
[switch]$Bootstrap
|
|
|
|
)
|
2016-11-19 01:17:59 +01:00
|
|
|
Import-Module $PSScriptRoot/../build.psm1 -Force
|
2017-07-23 21:29:33 +02:00
|
|
|
Import-Module $PSScriptRoot/packaging -Force
|
2016-11-19 01:17:59 +01:00
|
|
|
|
2017-02-02 00:53:30 +01:00
|
|
|
# This function retrieves the appropriate svg to be used when presenting
|
|
|
|
# the daily test run badge
|
|
|
|
# the location in azure is public readonly
|
|
|
|
function Get-DailyBadge
|
|
|
|
{
|
|
|
|
param (
|
|
|
|
[Parameter(Mandatory=$true,Position=0)][ValidateSet("Pass","Fail")]$result
|
|
|
|
)
|
|
|
|
$PASS = "https://jimtru1979.blob.core.windows.net/badges/DailyBuild.Pass.svg"
|
|
|
|
$FAIL = "https://jimtru1979.blob.core.windows.net/badges/DailyBuild.Fail.svg"
|
|
|
|
|
|
|
|
if ( $result -eq "Pass" ) { $BadgeUrl = $PASS } else { $BadgeUrl = $FAIL }
|
|
|
|
$response = Invoke-WebRequest -Uri $BadgeUrl
|
|
|
|
if ( $response.StatusCode -ne 200 ) { throw "Could not read badge '$BadgeUrl'" }
|
|
|
|
$response.Content
|
|
|
|
}
|
|
|
|
|
|
|
|
# This function uses Azure REST api to update the daily test pass results
|
|
|
|
# it relies on writing a specific SVG into a constant location so the
|
|
|
|
# README.MD can report on the status of the daily test pass
|
|
|
|
# it also relies on two environment variables which need to be set in the
|
|
|
|
# Travis-CI config which is the account name and key for the azure blob location
|
|
|
|
#
|
|
|
|
# the best way to do this would be if travis-ci supported a webcall to get
|
|
|
|
# the status of cron_job builds, but it doesn't, so we have this
|
2017-09-07 19:34:40 +02:00
|
|
|
# also, since we can have a build on Linux which succeeds and one on macOS which
|
2017-09-05 20:11:47 +02:00
|
|
|
# doesn't we'll set the appropriate badge so the the README can pick it up
|
2017-02-02 00:53:30 +01:00
|
|
|
function Set-DailyBuildBadge
|
|
|
|
{
|
|
|
|
[CmdletBinding(SupportsShouldProcess=$true)]
|
|
|
|
param ( [Parameter(Mandatory=$true,Position=0)]$content )
|
|
|
|
$method = "PUT"
|
|
|
|
$headerDate = '2015-12-11'
|
|
|
|
|
|
|
|
$storageAccountName = $Env:TestResultAccountName
|
|
|
|
$storageAccountKey = $Env:TestResultAccountKey
|
|
|
|
|
|
|
|
# this is the url referenced in README.MD which displays the badge
|
2017-09-07 19:34:40 +02:00
|
|
|
$platform = if ( $IsLinux ) { "Linux" } else { "OSX" }
|
2017-09-05 20:11:47 +02:00
|
|
|
$Url = "https://jimtru1979.blob.core.windows.net/badges/DailyBuildStatus.${platform}.svg"
|
2017-02-02 00:53:30 +01:00
|
|
|
|
|
|
|
$body = $content
|
|
|
|
$bytes = ([System.Text.Encoding]::UTF8.GetBytes($body))
|
|
|
|
$contentLength = $bytes.length
|
|
|
|
|
2017-03-29 07:15:52 +02:00
|
|
|
$now = [datetime]::UtcNow.ToString("R", [System.Globalization.CultureInfo]::InvariantCulture)
|
2017-02-02 00:53:30 +01:00
|
|
|
$headers = @{
|
2017-03-29 07:15:52 +02:00
|
|
|
"x-ms-date" = $now
|
|
|
|
"cache-control" = "no-cache"
|
2017-02-02 00:53:30 +01:00
|
|
|
"x-ms-blob-type" = "BlockBlob"
|
|
|
|
"x-ms-version" = "$headerDate"
|
|
|
|
}
|
|
|
|
|
|
|
|
$contentType = "image/svg+xml"
|
|
|
|
# more info: https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/put-blob
|
|
|
|
$sb = [text.stringbuilder]::new()
|
|
|
|
# can't use AppendLine because the `r`n causes the command to fail, it must be `n and only `n
|
|
|
|
$null = $sb.Append("$method`n")
|
|
|
|
$null = $sb.Append("`n")
|
|
|
|
$null = $sb.Append("`n")
|
|
|
|
$null = $sb.Append("$contentLength`n")
|
|
|
|
$null = $sb.Append("`n")
|
|
|
|
$null = $sb.Append("$contentType`n")
|
|
|
|
$null = $sb.Append("`n")
|
|
|
|
$null = $sb.Append("`n")
|
|
|
|
$null = $sb.Append("`n")
|
|
|
|
$null = $sb.Append("`n")
|
|
|
|
$null = $sb.Append("`n")
|
|
|
|
$null = $sb.Append("`n")
|
|
|
|
|
|
|
|
$null = $sb.Append("x-ms-blob-type:" + $headers["x-ms-blob-type"] + "`n")
|
|
|
|
$null = $sb.Append("x-ms-date:" + $headers["x-ms-date"] + "`n")
|
|
|
|
$null = $sb.Append("x-ms-version:" + $headers["x-ms-version"] + "`n")
|
|
|
|
$null = $sb.Append("/" + $storageAccountName + ([System.Uri]::new($url).AbsolutePath))
|
|
|
|
|
|
|
|
$dataToMac = [System.Text.Encoding]::UTF8.GetBytes($sb.ToString())
|
|
|
|
$accountKeyBytes = [System.Convert]::FromBase64String($storageAccountKey)
|
|
|
|
$hmac = [System.Security.Cryptography.HMACSHA256]::new($accountKeyBytes)
|
|
|
|
$signature = [System.Convert]::ToBase64String($hmac.ComputeHash($dataToMac))
|
|
|
|
|
|
|
|
$headers["Authorization"] = "SharedKey " + $storageAccountName + ":" + $signature
|
|
|
|
|
|
|
|
if ( $PSCmdlet.ShouldProcess("$signaturestring"))
|
|
|
|
{
|
|
|
|
# if this fails, it will throw, you can't check the response for a success code
|
|
|
|
$response = Invoke-RestMethod -Uri $Url -Method $method -headers $headers -Body $body -ContentType "image/svg+xml"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-21 18:48:41 +01:00
|
|
|
# https://docs.travis-ci.com/user/environment-variables/
|
|
|
|
# TRAVIS_EVENT_TYPE: Indicates how the build was triggered.
|
|
|
|
# One of push, pull_request, api, cron.
|
|
|
|
$isPR = $env:TRAVIS_EVENT_TYPE -eq 'pull_request'
|
2017-07-19 19:33:58 +02:00
|
|
|
|
2017-07-23 00:34:03 +02:00
|
|
|
# For PRs, Travis-ci strips out [ and ] so read the message directly from git
|
|
|
|
if($env:TRAVIS_EVENT_TYPE -eq 'pull_request')
|
|
|
|
{
|
|
|
|
# Get the second log entry body
|
|
|
|
# The first log is a merge for a PR
|
|
|
|
$commitMessage = git log --format=%B -n 1 --skip=1
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$commitMessage = $env:TRAVIS_COMMIT_MESSAGE
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-19 19:33:58 +02:00
|
|
|
# Run a full build if the build was trigger via cron, api or the commit message contains `[Feature]`
|
2017-08-09 23:01:52 +02:00
|
|
|
$hasFeatureTag = $commitMessage -match '\[feature\]'
|
2017-09-13 23:14:08 +02:00
|
|
|
$hasRunFailingTestTag = $commitMessage -match '\[includeFailingTest\]'
|
2017-08-09 23:01:52 +02:00
|
|
|
$isDailyBuild = $env:TRAVIS_EVENT_TYPE -eq 'cron' -or $env:TRAVIS_EVENT_TYPE -eq 'api'
|
2017-09-05 20:11:47 +02:00
|
|
|
# only update the build badge for the cron job
|
|
|
|
$cronBuild = $env:TRAVIS_EVENT_TYPE -eq 'cron'
|
2017-08-09 23:01:52 +02:00
|
|
|
$isFullBuild = $isDailyBuild -or $hasFeatureTag
|
2016-11-21 18:48:41 +01:00
|
|
|
|
2017-07-14 06:21:32 +02:00
|
|
|
if($Bootstrap.IsPresent)
|
|
|
|
{
|
2017-07-23 00:34:03 +02:00
|
|
|
Write-Host -Foreground Green "Executing travis.ps1 -BootStrap `$isPR='$isPr' - $commitMessage"
|
2017-08-01 23:35:50 +02:00
|
|
|
# Make sure we have all the tags
|
|
|
|
Sync-PSTags -AddRemoteIfMissing
|
2017-07-14 06:21:32 +02:00
|
|
|
Start-PSBootstrap -Package:(-not $isPr)
|
2017-07-12 07:07:31 +02:00
|
|
|
}
|
2017-07-14 06:21:32 +02:00
|
|
|
else
|
|
|
|
{
|
2017-08-01 23:35:50 +02:00
|
|
|
$BaseVersion = (Get-PSVersion -OmitCommitId) + '-'
|
2017-07-23 00:34:03 +02:00
|
|
|
Write-Host -Foreground Green "Executing travis.ps1 `$isPR='$isPr' `$isFullBuild='$isFullBuild' - $commitMessage"
|
2017-07-14 06:21:32 +02:00
|
|
|
$output = Split-Path -Parent (Get-PSOutput -Options (New-PSOptions))
|
|
|
|
|
|
|
|
# CrossGen'ed assemblies cause a hang to happen intermittently when running powershell class
|
2017-09-07 19:34:40 +02:00
|
|
|
# basic parsing tests in Linux/macOS. The hang seems to happen when generating dynamic assemblies.
|
2017-07-14 06:21:32 +02:00
|
|
|
# This issue has been reported to CoreCLR team. We need to work around it for now because
|
|
|
|
# the Travis CI build failures caused by this is draining our builder resource and severely
|
|
|
|
# affect our daily work. The workaround is:
|
|
|
|
# 1. For pull request and push commit, build without '-CrossGen' and run the parsing tests
|
|
|
|
# 2. For nightly build, build with '-CrossGen' but don't run the parsing tests
|
|
|
|
# With this workaround, CI builds triggered by pull request and push commit will exercise
|
|
|
|
# the parsing tests with IL assemblies, while nightly builds will exercise CrossGen'ed assemblies
|
|
|
|
# without running those class parsing tests so as to avoid the hang.
|
|
|
|
# NOTE: this change should be reverted once the 'CrossGen' issue is fixed by CoreCLR. The issue
|
|
|
|
# is tracked by https://github.com/dotnet/coreclr/issues/9745
|
|
|
|
$originalProgressPreference = $ProgressPreference
|
|
|
|
$ProgressPreference = 'SilentlyContinue'
|
|
|
|
try {
|
2017-08-09 23:01:52 +02:00
|
|
|
## We use CrossGen build to run tests only if it's the daily build.
|
|
|
|
Start-PSBuild -CrossGen:$isDailyBuild -PSModuleRestore
|
2017-07-14 06:21:32 +02:00
|
|
|
}
|
|
|
|
finally{
|
|
|
|
$ProgressPreference = $originalProgressPreference
|
|
|
|
}
|
2016-11-19 01:17:59 +01:00
|
|
|
|
2017-08-26 17:26:06 +02:00
|
|
|
$pesterParam = @{
|
|
|
|
'binDir' = $output
|
|
|
|
'PassThru' = $true
|
2017-09-19 23:56:32 +02:00
|
|
|
'Terse' = $true
|
2017-08-26 17:26:06 +02:00
|
|
|
}
|
2016-11-19 01:17:59 +01:00
|
|
|
|
2017-07-14 06:21:32 +02:00
|
|
|
if ($isFullBuild) {
|
|
|
|
$pesterParam['Tag'] = @('CI','Feature','Scenario')
|
|
|
|
$pesterParam['ExcludeTag'] = @()
|
|
|
|
} else {
|
|
|
|
$pesterParam['Tag'] = @('CI')
|
|
|
|
$pesterParam['ThrowOnFailure'] = $true
|
|
|
|
}
|
2016-11-19 01:17:59 +01:00
|
|
|
|
2017-09-13 23:14:08 +02:00
|
|
|
if ($hasRunFailingTestTag)
|
|
|
|
{
|
|
|
|
$pesterParam['IncludeFailingTest'] = $true
|
|
|
|
}
|
|
|
|
|
2017-07-14 06:21:32 +02:00
|
|
|
# Remove telemetry semaphore file in CI
|
|
|
|
$telemetrySemaphoreFilepath = Join-Path $output DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY
|
|
|
|
if ( Test-Path "${telemetrySemaphoreFilepath}" ) {
|
|
|
|
Remove-Item -force ${telemetrySemaphoreFilepath}
|
|
|
|
}
|
2017-05-17 20:08:38 +02:00
|
|
|
|
2017-08-26 17:26:06 +02:00
|
|
|
$pesterPassThruObject = Start-PSPester @pesterParam
|
2017-02-02 00:53:30 +01:00
|
|
|
|
2017-09-12 00:24:09 +02:00
|
|
|
# Determine whether the build passed
|
|
|
|
try {
|
|
|
|
# this throws if there was an error
|
|
|
|
Test-PSPesterResults -ResultObject $pesterPassThruObject
|
|
|
|
$result = "PASS"
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
$resultError = $_
|
|
|
|
$result = "FAIL"
|
|
|
|
}
|
|
|
|
|
2017-07-14 06:21:32 +02:00
|
|
|
if (-not $isPr) {
|
|
|
|
# Run 'CrossGen' for push commit, so that we can generate package.
|
|
|
|
# It won't rebuild powershell, but only CrossGen the already built assemblies.
|
2017-08-09 23:01:52 +02:00
|
|
|
if (-not $isDailyBuild) { Start-PSBuild -CrossGen }
|
2017-08-01 23:35:50 +02:00
|
|
|
|
|
|
|
$packageParams = @{}
|
|
|
|
if($env:TRAVIS_BUILD_NUMBER)
|
|
|
|
{
|
|
|
|
$version = $BaseVersion + $env:TRAVIS_BUILD_NUMBER
|
|
|
|
$packageParams += @{Version=$version}
|
|
|
|
}
|
2017-07-14 06:21:32 +02:00
|
|
|
# Only build packages for branches, not pull requests
|
2017-08-16 01:17:45 +02:00
|
|
|
$packages = @(Start-PSPackage @packageParams -SkipReleaseChecks)
|
|
|
|
# Packaging AppImage depends on the deb package
|
|
|
|
$packages += Start-PSPackage @packageParams -Type AppImage -SkipReleaseChecks
|
2017-08-01 23:35:50 +02:00
|
|
|
foreach($package in $packages)
|
|
|
|
{
|
2017-08-11 17:50:04 +02:00
|
|
|
# Publish the packages to the nuget feed if:
|
|
|
|
# 1 - It's a Daily build (already checked, for not a PR)
|
|
|
|
# 2 - We have the info to publish (NUGET_KEY and NUGET_URL)
|
|
|
|
# 3 - it's a nupkg file
|
|
|
|
if($isDailyBuild -and $env:NUGET_KEY -and $env:NUGET_URL -and [system.io.path]::GetExtension($package) -ieq '.nupkg')
|
2017-08-01 23:35:50 +02:00
|
|
|
{
|
|
|
|
log "pushing $package to $env:NUGET_URL"
|
|
|
|
Start-NativeExecution -sb {dotnet nuget push $package --api-key $env:NUGET_KEY --source "$env:NUGET_URL/api/v2/package"} -IgnoreExitcode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-05 20:11:47 +02:00
|
|
|
# update the badge if you've done a cron build, these are not fatal issues
|
|
|
|
if ( $cronBuild ) {
|
2017-07-14 06:21:32 +02:00
|
|
|
try {
|
|
|
|
$svgData = Get-DailyBadge -result $result
|
|
|
|
if ( ! $svgData ) {
|
|
|
|
write-warning "Could not retrieve $result badge"
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Write-Verbose -verbose "Setting status badge to '$result'"
|
|
|
|
Set-DailyBuildBadge -content $svgData
|
|
|
|
}
|
2017-02-02 00:53:30 +01:00
|
|
|
}
|
2017-07-14 06:21:32 +02:00
|
|
|
catch {
|
|
|
|
Write-Warning "Could not update status badge: $_"
|
2017-02-02 00:53:30 +01:00
|
|
|
}
|
|
|
|
}
|
2017-09-12 00:24:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# if the tests did not pass, throw the reason why
|
|
|
|
if ( $result -eq "FAIL" ) {
|
|
|
|
Throw $resultError
|
2017-02-02 00:53:30 +01:00
|
|
|
}
|
2016-11-19 01:17:59 +01:00
|
|
|
|
2017-07-14 06:21:32 +02:00
|
|
|
Start-PSxUnit
|
2017-08-08 18:09:11 +02:00
|
|
|
}
|