Skip to content

Commit

Permalink
Change workflow to use upstream branches
Browse files Browse the repository at this point in the history
  • Loading branch information
chidozieononiwu committed Oct 6, 2020
1 parent d6e7674 commit 30cfbd6
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 40 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 $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
}
56 changes: 56 additions & 0 deletions eng/common/scripts/Queue-Pipeline.ps1
Original file line number Diff line number Diff line change
@@ -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<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/git-branch-push.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
110 changes: 87 additions & 23 deletions eng/pipelines/eng-common-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ parameters:
- name: DirectoryToSync
type: string
default: eng/common
- name: Repos
type: object
default:
- azure-sdk-for-android
- azure-sdk-for-c
- azure-sdk-for-cpp
- azure-sdk-for-go
- azure-sdk-for-ios
- azure-sdk-for-java
- azure-sdk-for-js
- azure-sdk-for-net
- azure-sdk-for-python

trigger: none

Expand Down Expand Up @@ -58,11 +70,7 @@ stages:
CommitMessage: "Sync ${{ parameters.DirectoryToSync }} directory with azure-sdk-tools repository for Tools PR $(System.PullRequest.PullRequestNumber)"
DirectoryToSync: ${{ parameters.DirectoryToSync }}
PRBranchName: "sync-${{ parameters.DirectoryToSync }}-$(System.PullRequest.SourceBranch)-$(System.PullRequest.PullRequestNumber)"
BaseBranchName: $(system.pullRequest.targetBranch)
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)<br>
See [eng/common workflow](https://github.com/Azure/azure-sdk-tools/blob/master/eng/common/README.md#workflow)
BaseBranchName: $(system.pullRequest.targetBranch)
SkipCheckingForChanges: true
${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
CommitMessage: Sync ${{ parameters.DirectoryToSync }} directory with azure-sdk-tools repository
Expand All @@ -72,29 +80,85 @@ stages:
PRBody: >
Sync ${{ parameters.DirectoryToSync }} directory with azure-sdk-tools repository.<br>
See [eng/common workflow](https://github.com/Azure/azure-sdk-tools/blob/master/eng/common/README.md#workflow)
PRDataArtifactPath: $(Build.ArtifactStagingDirectory)/${{ parameters.PRDataFileName }}
Repos:
- azure-sdk-for-android
- azure-sdk-for-c
- azure-sdk-for-cpp
- azure-sdk-for-go
- azure-sdk-for-ios
- azure-sdk-for-java
- azure-sdk-for-js
- azure-sdk-for-net
- azure-sdk-for-python

- task: PublishPipelineArtifact@1
condition: succeeded()
inputs:
artifactName: ${{ parameters.ArtifactName }}
path: $(Build.ArtifactStagingDirectory)/${{ parameters.PRDataFileName }}
Repos: ${{ parameters.Repos }}

- stage: CreateSyncPRs
jobs:
- deployment: CreateSyncPullRequests
displayName: Create Sync Pull Requests
environment: githubmerges

pool:
vmImage: windows-2019

strategy:
runOnce:
deploy:
steps:
- checkout: self

- pwsh: |
New-Item -Path $(Build.ArtifactStagingDirectory)/${{ parameters.PRDataFileName }} -ItemType File
displayName: Create PRData Artifact
- ${{ each repo in parameters.Repos }}:
- task: PowerShell@2
displayName: Create pull request
condition: succeeded()
inputs:
pwsh: true
workingDirectory: ${{ parameters.WorkingDirectory }}
filePath: $(Build.SourcesDirectory)/eng/common/scripts/Submit-PullRequest.ps1
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
arguments: >
-RepoOwner "Azure"
-RepoName "${{ repo }}"
-BaseBranch $(system.pullRequest.targetBranch)
-PROwner "Azure"
-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)"
-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"
-RepoName "${{ repo }}"
-BaseBranch $(system.pullRequest.targetBranch)
-PROwner "Azure"
-PRBranch "sync-${{ parameters.DirectoryToSync }}"
-AuthToken "$(azuresdk-github-pat)"
-PRTitle "Sync ${{ parameters.DirectoryToSync }} directory with azure-sdk-tools for PR $(System.PullRequest.PullRequestNumber)"
-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)"
}
else
{
$PRData = "Azure;${{ repo }};sync-${{ parameters.DirectoryToSync }}"
}
Add-Content -Path "$(Build.ArtifactStagingDirectory)/${{ parameters.PRDataFileName }}" -Value $PRData
displayName: Write Sync PR Data to Artifact File
condition: succeeded()
- task: PublishPipelineArtifact@1
condition: succeeded()
displayName: Publish ${{ parameters.PRDataFileName }}
inputs:
artifactName: ${{ parameters.ArtifactName }}
path: $(Build.ArtifactStagingDirectory)/${{ parameters.PRDataFileName }}

- stage: VerifyAndMerge
jobs:
- deployment: VerifyandMergeSyncPrs
displayName: Verify and Merge Sync PRs
environment: github
environment: githubmerges

pool:
vmImage: windows-2019
Expand Down
49 changes: 34 additions & 15 deletions eng/pipelines/templates/steps/sync-directory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@ parameters:
CommitMessage: commit-message-not-set
PRBranchName: branch-name-not-set
BaseBranchName: master
PRTitle: pr-title-not-set
PRBody: pr-body-not-set
PRDataArtifactPath: pr-data-artifact-path-not-set
Sync: pr-data-artifact-path-not-set
SkipCheckingForChanges: false
ScriptDirectory: eng/common/scripts
PROwner: Azure
PushArgs:
PushArgs: -f

steps:
- pwsh: |
New-Item -Path ${{ parameters.PRDataArtifactPath }} -ItemType File
displayName: Create PRData Artifact
- ${{ each repo in parameters.Repos }}:
- pwsh: |
Set-PsDebug -Trace 1
Expand Down Expand Up @@ -57,17 +51,42 @@ steps:
condition: and(succeeded(), eq(variables['HasChanges'], 'true'))
inputs:
pwsh: true
workingDirectory: ${{ parameters.WorkingDirectory }}
workingDirectory: $(System.DefaultWorkingDirectory)/${{ repo }}
filePath: ${{ parameters.ScriptDirectory }}/git-branch-push.ps1
arguments: >
-PRBranchName "${{ parameters.PRBranchName }}"
-CommitMsg "${{ parameters.CommitMessage }}"
-GitUrl "https://$(azuresdk-github-pat)@github.com/${{ parameters.PROwner }}/${{ repo }}.git"
-PushArgs "${{ parameters.PushArgs }}"
-SkipCommit "${{parameters.SkipCheckingForChanges}}"
-SkipCommit $${{parameters.SkipCheckingForChanges}}
- pwsh: |
$PRData = "Azure;${{ repo }};$(Submitted.PullRequest.Number)"
Add-Content -Path ${{ parameters.PRDataArtifactPath }} -Value $PRData
displayName: Write Sync PR Data to Artifact File
condition: and(succeeded(), eq(variables['HasChanges'], 'true'))
- task: PowerShell@2
displayName: Queue test pipeline
condition: and(succeeded(), ne(variables['${{repo}}-template-definition-id'], ''))
inputs:
pwsh: true
workingDirectory: ${{ parameters.WorkingDirectory }}
filePath: ${{ parameters.ScriptDirectory }}/Queue-Pipeline.ps1
arguments: >
-Organization "azure-sdk"
-Project "internal"
-SourceBranch "${{ parameters.PRBranchName }}"
-DefinitionId "$(${{repo}}-template-definition-id)"
-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 30cfbd6

Please sign in to comment.