Skip to content

Commit

Permalink
Write info about queued pipelines back to the tools PR
Browse files Browse the repository at this point in the history
  • Loading branch information
chidozieononiwu committed Oct 2, 2020
1 parent 1aab5f2 commit 130c5aa
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ steps:
-CommitMsg "${{ parameters.CommitMsg }}"
-GitUrl "https://$(azuresdk-github-pat)@github.com/${{ parameters.PROwner }}/$(RepoNameWithoutOwner).git"
-PushArgs "${{ parameters.PushArgs }}"
-SkipCommit $"${{parameters.SkipCheckingForChanges}}"
-SkipCommit $${{parameters.SkipCheckingForChanges}}
- task: PowerShell@2
displayName: Create pull request
Expand Down
53 changes: 53 additions & 0 deletions eng/common/scripts/Add-Issue-Comment.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[Parameter(Mandatory = $true)]
[string]$RepoOwner,

[Parameter(Mandatory = $true)]
[string]$RepoName,

[Parameter(Mandatory = $true)]
[string]$IssueNumber,

[Parameter(Mandatory = $false)]
[string]$CommentPrefix,

[Parameter(Mandatory = $true)]
[string]$Comment,

[Parameter(Mandatory = $false)]
[string]$CommentPostFix,

[Parameter(Mandatory = $true)]
[string]$AuthToken
)

. "${PSScriptRoot}\logging.ps1"

$headers = @{
Authorization = "bearer $AuthToken"
}

$apiUrl = "https://api.github.com/repos/$RepoOwner/$RepoName/issues/$IssueNumber/comments"

$commentPrefixValue = [System.Environment]::GetEnvironmentVariable($CommentPrefix)
$commentValue = [System.Environment]::GetEnvironmentVariable($Comment)
$commentPostFixValue = [System.Environment]::GetEnvironmentVariable($CommentPostFix)

if (!$commentPrefixValue) { $commentPrefixValue = $CommentPrefix }
if (!$commentValue) { $commentValue = $Comment }
if (!$commentPostFixValue) { $commentPostFixValue = $CommentPostFix }

$PRComment = "$commentPrefixValue<br>$commentValue<br>$commentPostFixValue"

$data = @{
body = $PRComment
}

try {
$resp = Invoke-RestMethod -Method POST -Headers $headers -Uri $apiUrl -Body ($data | ConvertTo-Json)
}
catch {
LogError "Invoke-RestMethod [ $apiUrl ] failed with exception:`n$_"
exit 1
}
18 changes: 16 additions & 2 deletions eng/common/scripts/Queue-Pipeline.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ param(
[Parameter(Mandatory = $true)]
[int]$DefinitionId,

[Parameter(Mandatory = $false)]
[string]$VsoQueuedPipelines,

[Parameter(Mandatory = $true)]
[string]$AuthToken
)
Expand All @@ -35,8 +38,19 @@ try {
$resp = Invoke-RestMethod -Method POST -Headers $headers $apiUrl -Body ($body | ConvertTo-Json) -ContentType application/json
}
catch {
LogError "Invoke-RestMethod $apiUrl failed with exception:`n$_"
LogError "Invoke-RestMethod [ $apiUrl ] failed with exception:`n$_"
exit 1
}

LogDebug "Pipeline [ $($resp.definition.name) ] queued at [ $($resp._links.web.href) ]"
LogDebug "Pipeline [ $($resp.definition.name) ] queued at [ $($resp._links.web.href) ]"

if ($VsoQueuedPipelines) {
$enVarValue = [System.Environment]::GetEnvironmentVariable($VsoQueuedPipelines)
$QueuedPipelineLinks = if ($enVarValue) {
"$enVarValue<br>[$($resp.definition.name)]($($resp._links.web.href))"
}else {
"[$($resp.definition.name)]($($resp._links.web.href))"
}
$QueuedPipelineLinks
Write-Host "##vso[task.setvariable variable=$VsoQueuedPipelines]$QueuedPipelineLinks"
}
2 changes: 1 addition & 1 deletion eng/common/scripts/Submit-PullRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ param(
[string]$RepoName,

[Parameter(Mandatory = $true)]
[string]$BaseBranch = "master",
[string]$BaseBranch,

[Parameter(Mandatory = $true)]
[string]$PROwner,
Expand Down
16 changes: 8 additions & 8 deletions eng/pipelines/eng-common-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ stages:
jobs:
- deployment: CreateSyncPullRequests
displayName: Create Sync Pull Requests
environment: github
environment: githubmerges

pool:
vmImage: windows-2019
Expand All @@ -108,7 +108,7 @@ stages:
inputs:
pwsh: true
workingDirectory: ${{ parameters.WorkingDirectory }}
filePath: /eng/common/scripts/Submit-PullRequest.ps1
filePath: $(Build.SourcesDirectory)/eng/common/scripts/Submit-PullRequest.ps1
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
arguments: >
-RepoOwner "Azure"
Expand All @@ -118,9 +118,9 @@ stages:
-PRBranch "sync-${{ parameters.DirectoryToSync }}-$(System.PullRequest.SourceBranch)-$(System.PullRequest.PullRequestNumber)"
-AuthToken "$(azuresdk-github-pat)"
-PRTitle "Sync ${{ parameters.DirectoryToSync }} directory with azure-sdk-tools for PR $(System.PullRequest.PullRequestNumber)"
-PRBody "Sync ${{ parameters.DirectoryToSync }} directory with azure-sdk-tools for PR https://github.com/Azure/azure-sdk-tools/pull/$(System.PullRequest.PullRequestNumber)
See [eng/common workflow](https://github.com/Azure/azure-sdk-tools/blob/master/eng/common/README.md#workflow)"
-PRLabels "Central-EngSys, EngSys"
-PRBody "Sync ${{ parameters.DirectoryToSync }} directory with azure-sdk-tools for PR https://github.com/Azure/azure-sdk-tools/pull/$(System.PullRequest.PullRequestNumber)`
See [eng/common workflow](https://github.com/Azure/azure-sdk-tools/blob/master/eng/common/README.md#workflow)"
${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
arguments: >
-RepoOwner "Azure"
Expand All @@ -130,18 +130,18 @@ stages:
-PRBranch "sync-${{ parameters.DirectoryToSync }}"
-AuthToken "$(azuresdk-github-pat)"
-PRTitle "Sync ${{ parameters.DirectoryToSync }} directory with azure-sdk-tools for PR $(System.PullRequest.PullRequestNumber)"
-PRBody "Sync ${{ parameters.DirectoryToSync }} directory with azure-sdk-tools for PR https://github.com/Azure/azure-sdk-tools/pull/$(System.PullRequest.PullRequestNumber)
See [eng/common workflow](https://github.com/Azure/azure-sdk-tools/blob/master/eng/common/README.md#workflow)"
-PRLabels "Central-EngSys, EngSys"
-PRBody "Sync ${{ parameters.DirectoryToSync }} directory with azure-sdk-tools for PR https://github.com/Azure/azure-sdk-tools/pull/$(System.PullRequest.PullRequestNumber)`
See [eng/common workflow](https://github.com/Azure/azure-sdk-tools/blob/master/eng/common/README.md#workflow)"
- pwsh: |
if ($(System.PullRequest.SourceBranch) -and $(System.PullRequest.PullRequestNumber))
{
$PRData = "Azure;${{ repo }};"sync-${{ parameters.DirectoryToSync }}-$(System.PullRequest.SourceBranch)-$(System.PullRequest.PullRequestNumber)"
$PRData = "Azure;${{ repo }};sync-${{ parameters.DirectoryToSync }}-$(System.PullRequest.SourceBranch)-$(System.PullRequest.PullRequestNumber)"
}
else
{
$PRData = "Azure;${{ repo }};"sync-${{ parameters.DirectoryToSync }}"
$PRData = "Azure;${{ repo }};sync-${{ parameters.DirectoryToSync }}"
}
Add-Content -Path "$(Build.ArtifactStagingDirectory)/${{ parameters.PRDataFileName }}" -Value $PRData
displayName: Write Sync PR Data to Artifact File
Expand Down
21 changes: 19 additions & 2 deletions eng/pipelines/templates/steps/sync-directory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ steps:
-CommitMsg "${{ parameters.CommitMessage }}"
-GitUrl "https://$(azuresdk-github-pat)@github.com/${{ parameters.PROwner }}/${{ repo }}.git"
-PushArgs "${{ parameters.PushArgs }}"
-SkipCommit $"${{parameters.SkipCheckingForChanges}}"
-SkipCommit $${{parameters.SkipCheckingForChanges}}
- task: PowerShell@2
displayName: Queue test pipeline
Expand All @@ -72,4 +72,21 @@ steps:
-Project "internal"
-SourceBranch "${{ parameters.PRBranchName }}"
-DefinitionId "$(${{repo}}-template-definition-id)"
-AuthToken $(azuresdk-azure-sdk-devops-build-queuing-pat)
-VsoQueuedPipelines "QueuedPipelines"
-AuthToken "$(azuresdk-azure-sdk-devops-build-queuing-pat)"
- task: PowerShell@2
displayName: Write Queued Pipeline Information to Tools PR
condition: and(succeeded(), and(ne(variables['QueuedPipelines'], ''), eq(variables['Build.Reason'], 'PullRequest')))
inputs:
pwsh: true
workingDirectory: ${{ parameters.WorkingDirectory }}
filePath: ${{ parameters.ScriptDirectory }}/Add-Issue-Comment.ps1
arguments: >
-RepoOwner "Azure"
-RepoName "azure-sdk-tools"
-IssueNumber "$(System.PullRequest.PullRequestNumber)"
-CommentPrefix "The following pipelines have been queued for testing:<br>"
-Comment "QueuedPipelines"
-CommentPostFix "<br>Sign off on the approval gate to test the release stage of each pipeline."
-AuthToken "$(azuresdk-github-pat)"

0 comments on commit 130c5aa

Please sign in to comment.