[CI] Migrate all code to use the new api to set the status on github. (#14728)
This commit is contained in:
Родитель
1f1189fae0
Коммит
d94ede01b3
|
@ -116,7 +116,7 @@ class GitHubStatuses {
|
|||
Authorization = ("token {0}" -f $this.Token)
|
||||
}
|
||||
|
||||
$url = [GitHubStatuses]::GetStatusUrl()
|
||||
$url = $this.GetStatusUrl()
|
||||
|
||||
# Check if the status was already set, if it was we will override yet print a message for the user to know this action was done.
|
||||
$presentStatuses = Invoke-Request -Request { Invoke-RestMethod -Uri $url -Headers $headers -Method "GET" -ContentType 'application/json' }
|
||||
|
@ -146,6 +146,32 @@ class GitHubStatuses {
|
|||
|
||||
return Invoke-Request -Request { Invoke-RestMethod -Uri $url -Headers $headers -Method "POST" -Body ($payload | ConvertTo-json) -ContentType 'application/json' }
|
||||
}
|
||||
|
||||
[object] SetStatus($status, $description, $context) {
|
||||
return $this.SetStatus($status, $description, $context, $null)
|
||||
}
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates a new GitHubComments object from that can be used to create comments for the build.
|
||||
#>
|
||||
function New-GitHubStatusesObject {
|
||||
param (
|
||||
|
||||
[ValidateNotNullOrEmpty ()]
|
||||
[string]
|
||||
$Org,
|
||||
|
||||
[ValidateNotNullOrEmpty ()]
|
||||
[string]
|
||||
$Repo,
|
||||
|
||||
[ValidateNotNullOrEmpty ()]
|
||||
[string]
|
||||
$Token
|
||||
)
|
||||
return [GitHubStatuses]::new($Org, $Repo, $Token)
|
||||
}
|
||||
|
||||
class GitHubComments {
|
||||
|
@ -1182,3 +1208,4 @@ Export-ModuleMember -Function Push-RepositoryDispatch
|
|||
|
||||
# new future API that uses objects.
|
||||
Export-ModuleMember -Function New-GitHubCommentsObject
|
||||
Export-ModuleMember -Function New-GitHubStatusesObject
|
||||
|
|
|
@ -121,8 +121,9 @@ steps:
|
|||
|
||||
- pwsh: |
|
||||
Import-Module $Env:SYSTEM_DEFAULTWORKINGDIRECTORY\tools\devops\automation\scripts\MaciosCI.psd1
|
||||
$statuses = New-GitHubStatusesObject -Org "xamarin" -Repo "xamarin-macios" -Token $(GitHub.Token)
|
||||
|
||||
Dir "$(Build.SourcesDirectory)\artifacts\package"
|
||||
Dir "$(Build.SourcesDirectory)\\artifacts\\package"
|
||||
|
||||
# $Env:STORAGE_URI/ ends with a /, annoying
|
||||
$pkgsVirtualUrl = "$Env:STORAGE_URI" +"$(Build.SourceBranchName)/$(Build.SourceVersion)/$(Build.BuildId)/package"
|
||||
|
@ -177,7 +178,7 @@ steps:
|
|||
ShouldExist = $notarizedShouldExist;
|
||||
},
|
||||
@{
|
||||
Path = "$pkgsPath\bundle.zip" ;
|
||||
Path = "$pkgsPath\\bundle.zip" ;
|
||||
Context = "bundle.zip" ;
|
||||
Description = "bundle.zip" ;
|
||||
TargetUrl = "$pkgsVirtualUrl/bundle.zip" ;
|
||||
|
@ -196,9 +197,9 @@ steps:
|
|||
|
||||
foreach ($info in $statusInfo) {
|
||||
if (Test-Path $info.Path -PathType Leaf) {
|
||||
Set-GitHubStatus -Status "success" -Description $info.Description -TargetUrl $info.TargetUrl -Context $info.Context
|
||||
$statuses.SetStatus("success", $info.Description, $info.Context, $info.TargetUrl)
|
||||
} elseif ($info.ShouldExist) {
|
||||
Set-GitHubStatus -Status "error" -Description $info.Error -Context $info.Context
|
||||
$statuses.SetStatus("error", $info.Error, $info.Context)
|
||||
}
|
||||
}
|
||||
if ($Env:ENABLE_DOTNET -eq "True" -and $Env:SkipNugets -ne "True") {
|
||||
|
@ -208,17 +209,17 @@ steps:
|
|||
|
||||
if ($nugets.Count -gt 0) {
|
||||
Write-Host "Setting status to success."
|
||||
Set-GitHubStatus -Status "success" -Description "Nugets built." -TargetUrl "$pkgsVirtualUrl/$n" -Context "$(Build.DefinitionName) (Nugets built)"
|
||||
$statuses.SetStatus("success", "Nugets built.", "$(Build.DefinitionName) (Nugets built)", "$pkgsVirtualUrl/$n")
|
||||
Write-Host "Publishing result is $Env:NUGETS_PUBLISHED"
|
||||
if ($Env:NUGETS_PUBLISHED -ne "Failed") {
|
||||
Set-GitHubStatus -Status "success" -Description "Nugets published." -TargetUrl "$pkgsVirtualUrl/$n" -Context "$(Build.DefinitionName) (Nugets published)"
|
||||
$statuses.SetStatus("success", "Nugets published.", "$(Build.DefinitionName) (Nugets published)", "$pkgsVirtualUrl/$n")
|
||||
} else {
|
||||
Set-GitHubStatus -Status "error" -Description "Error when publishing nugets." -TargetUrl "$pkgsVirtualUrl/$n" -Context "$(Build.DefinitionName) (Nugets published)"
|
||||
$statuses.SetStatus("error", "Error when publishing nugets.", "$(Build.DefinitionName) (Nugets published)", "$pkgsVirtualUrl/$n")
|
||||
}
|
||||
} else {
|
||||
Write-Host "Setting nuget status to failure."
|
||||
Set-GitHubStatus -Status "error" -Description "No nugets were built." -TargetUrl "$pkgsVirtualUrl/$n" -Context "$(Build.DefinitionName) (Nugets built)"
|
||||
Set-GitHubStatus -Status "error" -Description "No nugets were published." -TargetUrl "$pkgsVirtualUrl/$n" -Context "$(Build.DefinitionName) (Nugets published)"
|
||||
$statuses.SetStatus("error", "No nugets were built.", "$(Build.DefinitionName) (Nugets built)", "$pkgsVirtualUrl/$n")
|
||||
$statuses.SetStatus("error", "No nugets were published.", "$(Build.DefinitionName) (Nugets published)", "$pkgsVirtualUrl/$n")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -226,7 +227,7 @@ steps:
|
|||
$msi = Get-ChildItem -Path $pkgsPath -Filter *.msi -File -Name
|
||||
|
||||
foreach ($n in $msi) {
|
||||
Set-GitHubStatus -Status "success" -Description "$n" -TargetUrl "$pkgsVirtualUrl/$n" -Context "$n"
|
||||
$statuses.SetStatus("success", "$n", "$n", "$pkgsVirtualUrl/$n")
|
||||
}
|
||||
|
||||
Write-Host "Setting SBOM.PackagesPath: ${pkgsPath}"
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
# This templates allows to set a status on github. Takes the following paramenters:
|
||||
|
||||
parameters:
|
||||
|
||||
- name: org
|
||||
type: string
|
||||
default: "xamarin"
|
||||
|
||||
- name: repo
|
||||
type: string
|
||||
default: "xamarin-macios"
|
||||
|
||||
- name: githubToken
|
||||
type: string
|
||||
|
||||
- name: status
|
||||
type: string
|
||||
values:
|
||||
- error
|
||||
- failure
|
||||
- pending
|
||||
- success
|
||||
|
||||
- name: description
|
||||
type: string
|
||||
|
||||
- name: context
|
||||
type: string
|
||||
|
||||
- name: targetUrl
|
||||
type: string
|
||||
default: ''
|
||||
|
||||
- name: displayName
|
||||
type: string
|
||||
default: 'Set GitHub status'
|
||||
|
||||
- name: continueOnError
|
||||
default: true
|
||||
|
||||
- name: condition
|
||||
default: true
|
||||
|
||||
- name: timeoutInMinutes
|
||||
default: 5
|
||||
|
||||
steps:
|
||||
|
||||
- pwsh: |
|
||||
Import-Module .\\MaciosCI.psd1
|
||||
$statuses = New-GitHubStatusesObject -Org "${{ parameters.org }}" -Repo "${{ parameters.repo }}" -Token "${{ parameters.githubToken }}"
|
||||
$statuses.SetStatus("${{ parameters.status }}", "${{ parameters.description }}", "${{ parameters.context }}", "${{ parameters.targetUrl }}")
|
||||
displayName: ${{ parameters.displayName }}
|
||||
workingDirectory: $(System.DefaultWorkingDirectory)/xamarin-macios/tools/devops/automation/scripts
|
||||
continueOnError: ${{ parameters.continueOnError }}
|
||||
condition: ${{ parameters.condition }}
|
||||
timeoutInMinutes: ${{ parameters.timeoutInMinutes }}
|
|
@ -23,8 +23,10 @@ steps:
|
|||
# if something goes wrong before we successfully complete the tests (in which case we delete the file).
|
||||
- pwsh: |
|
||||
Import-Module $Env:SYSTEM_DEFAULTWORKINGDIRECTORY\xamarin-macios\tools\devops\automation\scripts\MaciosCI.psd1
|
||||
Set-Content -Path "$Env:GITHUB_FAILURE_COMMENT_FILE" -Value "Tests on macOS $Env:CONTEXT failed for unknown reasons."
|
||||
Set-GitHubStatus -Status "pending" -Description "Tests on macOS $Env:CONTEXT have started." -Context "$Env:CONTEXT"
|
||||
$statuses = New-GitHubStatusesObject -Org "xamarin" -Repo "xamarin-macios" -Token $(GitHub.Token)
|
||||
|
||||
Set-Content -Path "$Env:GITHUB_FAILURE_COMMENT_FILE" -Value "Tests on macOS ${{ parameters.statusContext }} failed for unknown reasons."
|
||||
$statuses.SetStatus("pending", "Tests on macOS ${{ parameters.statusContext }} have started.", "${{ parameters.statusContext }}")
|
||||
displayName: "Initialize state"
|
||||
env:
|
||||
BUILD_REVISION: $(Build.SourceVersion)
|
||||
|
@ -182,6 +184,7 @@ steps:
|
|||
|
||||
- pwsh: |
|
||||
Import-Module $Env:SYSTEM_DEFAULTWORKINGDIRECTORY\xamarin-macios\tools\devops\automation\scripts\MaciosCI.psd1
|
||||
$statuses = New-GitHubStatusesObject -Org "xamarin" -Repo "xamarin-macios" -Token $(GitHub.Token)
|
||||
|
||||
Write-Host "Found tests"
|
||||
$testsPath = "$(Build.SourcesDirectory)/artifacts/mac-test-package/tests"
|
||||
|
@ -210,7 +213,7 @@ steps:
|
|||
if ($failures.Count -ne 0) {
|
||||
# post status and comment in the build
|
||||
$failedTestsStr = [string]::Join(",",$failures)
|
||||
Set-GitHubStatus -Status "error" -Description "Tests on macOS $Env:CONTEXT failed ($failedTestsStr)." -Context "$Env:CONTEXT"
|
||||
$statuses.SetStatus("error", "Tests on macOS ${{ parameters.statusContext }} failed ($failedTestsStr).", "${{ parameters.statusContext }}")
|
||||
# build message
|
||||
$msg = [System.Text.StringBuilder]::new()
|
||||
$msg.AppendLine("Failed tests are:")
|
||||
|
@ -244,11 +247,12 @@ steps:
|
|||
# Make sure to report any errors
|
||||
- pwsh: |
|
||||
Import-Module $Env:SYSTEM_DEFAULTWORKINGDIRECTORY\xamarin-macios\tools\devops\automation\scripts\MaciosCI.psd1
|
||||
$statuses = New-GitHubStatusesObject -Org "xamarin" -Repo "xamarin-macios" -Token $(GitHub.Token)
|
||||
if (Test-Path -Path "$Env:GITHUB_FAILURE_COMMENT_FILE" -PathType Leaf) {
|
||||
Set-GitHubStatus -Status "error" -Description "Tests on macOS $Env:CONTEXT failed." -Context "$Env:CONTEXT"
|
||||
$statuses.SetStatus("error", "Tests on macOS ${{ parameters.statusContext }} failed.", "${{ parameters.statusContext }}")
|
||||
New-GitHubCommentFromFile -Header "Tests on macOS $Env:CONTEXT failed" -Emoji ":x:" -Path "$Env:GITHUB_FAILURE_COMMENT_FILE"
|
||||
} else {
|
||||
Set-GitHubStatus -Status "success" -Description "Tests on macOS $Env:CONTEXT passed." -Context "$Env:CONTEXT"
|
||||
$statuses.SetStatus("success", "Tests on macOS ${{ parameters.statusContext }} passed.", "${{ parameters.statusContext }}")
|
||||
New-GitHubComment -Header "Tests on macOS $Env:CONTEXT passed" -Description "Tests passed" -Message "**All** tests on macOS $Env:CONTEXT passed." -Emoji ":white_check_mark:"
|
||||
}
|
||||
displayName: 'Report results to GitHub'
|
||||
|
|
|
@ -78,13 +78,14 @@ steps:
|
|||
# 3. Cancel the pipeline and do not execute any of the following steps.
|
||||
- pwsh: |
|
||||
Import-Module ./MaciosCI.psd1
|
||||
$statuses = New-GitHubStatusesObject -Org "xamarin" -Repo "xamarin-macios" -Token $(GitHub.Token)
|
||||
|
||||
if ( -not (Test-HDFreeSpace -Size 20)) {
|
||||
Set-GitHubStatus -Status "error" -Description "Not enough free space in the host." -Context "$Env:CONTEXT"
|
||||
$statuses.SetStatus("error", "Not enough free space in the host.", "${{ parameters.statusContext }}")
|
||||
New-GitHubComment -Header "Tests failed catastrophically on $Env:CONTEXT" -Emoji ":fire:" -Description "Not enough free space in the host."
|
||||
Stop-Pipeline
|
||||
} else {
|
||||
Set-GitHubStatus -Status "pending" -Description "Device tests on VSTS have been started." -Context "$Env:CONTEXT"
|
||||
$statuses.SetStatus("pending", "Device tests on VSTS have been started.", "${{ parameters.statusContext }}")
|
||||
}
|
||||
env:
|
||||
BUILD_REVISION: $(Build.SourceVersion)
|
||||
|
|
|
@ -52,17 +52,15 @@ steps:
|
|||
|
||||
# Update the status to pending, that way the monitoring person knows that we started running the tests. Up to this
|
||||
# point we were just setting up the agent.
|
||||
- pwsh: |
|
||||
Import-Module $Env:SYSTEM_DEFAULTWORKINGDIRECTORY/xamarin-macios/tools/devops/automation/scripts/MaciosCI.psd1
|
||||
Set-GitHubStatus -Status "pending" -Context "$Env:CONTEXT" -Description "Running device tests on $Env:CONTEXT"
|
||||
env:
|
||||
BUILD_REVISION: $(Build.SourceVersion)
|
||||
CONTEXT: ${{ parameters.statusContext }}
|
||||
GITHUB_TOKEN: $(GitHub.Token)
|
||||
displayName: Set pending GitHub status
|
||||
continueOnError: true
|
||||
condition: succeededOrFailed() # re-starting the daemon should not be an issue
|
||||
timeoutInMinutes: 5
|
||||
- template: ../common/status.yml
|
||||
parameters:
|
||||
status: "pending"
|
||||
description: "Running device tests on ${{ parameters.statusContext }}"
|
||||
context: ${{ parameters.statusContext }}
|
||||
githubToken: $(GitHub.Token)
|
||||
continueOnError: true
|
||||
condition: succeededOrFailed() # re-starting the daemon should not be an issue
|
||||
timeoutInMinutes: 5
|
||||
|
||||
- bash: |
|
||||
make -C src build/generator-frameworks.g.cs
|
||||
|
|
Загрузка…
Ссылка в новой задаче