From 6b3e5b7dc0a5dff7e64f2ce53cef0e2555cb1db9 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Mon, 28 Sep 2020 16:43:35 -0700 Subject: [PATCH] Change workflow to use upstream branches --- .../templates/steps/create-pull-request.yml | 2 +- eng/common/scripts/Add-Issue-Comment.ps1 | 53 ++++++++++++++++++ eng/common/scripts/Queue-Pipeline.ps1 | 56 +++++++++++++++++++ eng/common/scripts/git-branch-push.ps1 | 2 +- .../scripts/modules/ChangeLog-Operations.psm1 | 1 - 5 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 eng/common/scripts/Add-Issue-Comment.ps1 create mode 100644 eng/common/scripts/Queue-Pipeline.ps1 diff --git a/eng/common/pipelines/templates/steps/create-pull-request.yml b/eng/common/pipelines/templates/steps/create-pull-request.yml index 0e5753dce58b..e3b3e538c036 100644 --- a/eng/common/pipelines/templates/steps/create-pull-request.yml +++ b/eng/common/pipelines/templates/steps/create-pull-request.yml @@ -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 diff --git a/eng/common/scripts/Add-Issue-Comment.ps1 b/eng/common/scripts/Add-Issue-Comment.ps1 new file mode 100644 index 000000000000..b945d70c3fe9 --- /dev/null +++ b/eng/common/scripts/Add-Issue-Comment.ps1 @@ -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 $commentValue $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 +} \ No newline at end of file diff --git a/eng/common/scripts/Queue-Pipeline.ps1 b/eng/common/scripts/Queue-Pipeline.ps1 new file mode 100644 index 000000000000..4e0122ca9256 --- /dev/null +++ b/eng/common/scripts/Queue-Pipeline.ps1 @@ -0,0 +1,56 @@ +[CmdletBinding(SupportsShouldProcess = $true)] +param( + [Parameter(Mandatory = $true)] + [string]$Organization, + + [Parameter(Mandatory = $true)] + [string]$Project, + + [Parameter(Mandatory = $true)] + [string]$SourceBranch, + + [Parameter(Mandatory = $true)] + [int]$DefinitionId, + + [Parameter(Mandatory = $false)] + [string]$VsoQueuedPipelines, + + [Parameter(Mandatory = $true)] + [string]$AuthToken +) + +. "${PSScriptRoot}\logging.ps1" + +$headers = @{ + Authorization = "Basic $AuthToken" +} + +$apiUrl = "https://dev.azure.com/$Organization/$Project/_apis/build/builds?api-version=6.0" + +$body = @{ + sourceBranch = $SourceBranch + definition = @{ id = $DefinitionId } +} + +Write-Verbose ($body | ConvertTo-Json) + +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$_" + exit 1 +} + +LogDebug "Pipeline [ $($resp.definition.name) ] queued at [ $($resp._links.web.href) ]" + +if ($VsoQueuedPipelines) { + $enVarValue = [System.Environment]::GetEnvironmentVariable($VsoQueuedPipelines) + $QueuedPipelineLinks = if ($enVarValue) { + "$enVarValue
[$($resp.definition.name)]($($resp._links.web.href))" + }else { + "[$($resp.definition.name)]($($resp._links.web.href))" + } + $QueuedPipelineLinks + Write-Host "##vso[task.setvariable variable=$VsoQueuedPipelines]$QueuedPipelineLinks" +} \ No newline at end of file diff --git a/eng/common/scripts/git-branch-push.ps1 b/eng/common/scripts/git-branch-push.ps1 index 2f8541ce93af..333ed0a62c5e 100644 --- a/eng/common/scripts/git-branch-push.ps1 +++ b/eng/common/scripts/git-branch-push.ps1 @@ -28,7 +28,7 @@ param( [string] $PushArgs = "", [Parameter(Mandatory = $false)] - [string] $SkipCommit = $false + [boolean] $SkipCommit = $false ) # This is necessay because of the janky git command output writing to stderr. diff --git a/eng/common/scripts/modules/ChangeLog-Operations.psm1 b/eng/common/scripts/modules/ChangeLog-Operations.psm1 index 46e4fd9302f4..bfcd8d193b00 100644 --- a/eng/common/scripts/modules/ChangeLog-Operations.psm1 +++ b/eng/common/scripts/modules/ChangeLog-Operations.psm1 @@ -1,5 +1,4 @@ # Common Changelog Operations -# This Files has been retired $RELEASE_TITLE_REGEX = "(?^\#+.*(?\b\d+\.\d+\.\d+([^0-9\s][^\s:]+)?)(\s(?\(Unreleased\)|\(\d{4}-\d{2}-\d{2}\)))?)" # Returns a Collection of changeLogEntry object containing changelog info for all version present in the gived CHANGELOG