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 Sep 29, 2020
1 parent e790cb3 commit 386c3e1
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 40 deletions.
43 changes: 43 additions & 0 deletions eng/common/scripts/Queue-Pipeline.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[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 = $true)]
[string]$AuthToken
)

. "${PSScriptRoot}\logging.ps1"

$encodedAuthToken = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes([string]::Format("{0}:{1}", "", $AuthToken)))
$headers = @{
Authorization = "Basic $encodedAuthToken"
}

$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 {
Write-Error "Invoke-RestMethod $apiUrl failed with exception:`n$_"
exit 1
}

LogDebug "Pipeline [ $($resp.definition.name) ] queued at [ $($resp._links.web.href) ]"
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,
[string]$BaseBranch = "master",

[Parameter(Mandatory = $true)]
[string]$PROwner,
Expand Down
4 changes: 2 additions & 2 deletions eng/common/scripts/logging.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ function LogDebug
{
if ($isDevOpsRun)
{
Write-Host "##vso[task.LogIssue type=debug;]$args"
Write-Host "[debug]$args"
}
else
{
Write-Debug "$args"
Write-Debug "$args" -Debug
}
}
101 changes: 78 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,76 @@ 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: github

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: /eng/common/scripts/Submit-PullRequest.ps1
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
arguments: >
-RepoOwner "Azure"
-RepoName "${{ repo }}"
-BaseBranch $(system.pullRequest.targetBranch)
-PROwner "Azure"
-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"
${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
arguments: >
-RepoOwner "Azure"
-RepoName "${{ repo }}"
-BaseBranch $(system.pullRequest.targetBranch)
-PROwner "Azure"
-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"
- pwsh: |
$PRData = "Azure;${{ repo }};"${{ parameters.PRBranchName }}"
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
30 changes: 16 additions & 14 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,7 +51,7 @@ 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 }}"
Expand All @@ -66,8 +60,16 @@ steps:
-PushArgs "${{ parameters.PushArgs }}"
-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)"
-AuthToken $(azuresdk-azure-sdk-devops-build-queuing-pat)

0 comments on commit 386c3e1

Please sign in to comment.