Skip to content

Commit

Permalink
Update verify-and-merge script for easier local running (#969)
Browse files Browse the repository at this point in the history
  • Loading branch information
weshaggard authored Sep 6, 2020
1 parent d5b219b commit 99baaea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions eng/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ The 'Sync eng/common directory' PRs will be created in the language repositories
3. More changes pushed to the **Tools PR**, will automatically triggered new pipeline runs in the respective **Sync PRs**. The **Sync PRs** are used to make sure the changes would not break any of the connected pipelines.
4. Once satisfied with the changes;
- First make sure all checks in the **Sync PRs** are green and approved. The **Tools PR** contains links to all the **Sync PRs**. If for some reason the PRs is blocked by a CI gate get someone with permission to override and manually merge the PR.
- To test the state of all the **Sync PRs**, you can download the `PRsCreated.txt` artifact from the `azure-sdk-tools - sync - eng-common` pipeline, with that run the [Verify-And-Merge-PRs.ps1](https://github.com/Azure/azure-sdk-tools/blob/master/scripts/powershell/Verify-And-Merge-PRs.ps1) passing the downloaded `PRsCreated.txt` file path for `PRDataArtifactPath` and `false` to `ShouldMerge`.
- Next approve the `VerifyAndMerge` job for the `azure-sdk-tools - sync - eng-common` pipeline triggered by your **Tools PR** which will automatically merge all the **Sync PRs**. You need `azure-sdk` devops contributor permissions to reach the `azure-sdk-tools - sync - eng-common` pipeline.
- To test the state of all the **Sync PRs**, you can download the `PRsCreated.txt` artifact from your `azure-sdk-tools - sync - eng-common` pipeline, then run `./eng/scripts/Verify-And-Merge.ps1 <path to PRsCreated.txt>` which will output the status of each associated PR.
- Next approve the `VerifyAndMerge` job for the `azure-sdk-tools - sync - eng-common` pipeline triggered by your **Tools PR** which will automatically merge all the **Sync PRs**. You need `azure-sdk` devops contributor permissions to reach the `azure-sdk-tools - sync - eng-common` pipeline.
- Finally merge the **Tools PR**.
6 changes: 3 additions & 3 deletions eng/pipelines/eng-common-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ stages:
inputs:
artifactName: ${{ parameters.ArtifactName }}
path: $(Build.ArtifactStagingDirectory)/${{ parameters.PRDataFileName }}

- stage: VerifyAndMerge
jobs:
- deployment: VerifyandMergeSyncPrs
Expand All @@ -89,9 +89,9 @@ stages:
displayName: 'Verify then Merge Pull Requests'
inputs:
targetType: filePath
filePath: $(Build.SourcesDirectory)/scripts/powershell/Verify-And-Merge-PRs.ps1
filePath: $(Build.SourcesDirectory)/eng/scripts/Verify-And-Merge-PRs.ps1
arguments: >
-AuthToken "$(azuresdk-github-pat)"
-PRDataArtifactPath "$(Pipeline.Workspace)/${{parameters.ArtifactName}}/${{ parameters.PRDataFileName }}"
-AuthToken "$(azuresdk-github-pat)"
-devOpsLogging
pwsh: true
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
param(
$AuthToken,
$PRDataArtifactPath,
$AuthToken,
$ShouldMerge,
[switch]$devOpsLogging = $false
)
Expand Down Expand Up @@ -46,27 +46,29 @@ foreach ($prDataLine in $PRData)
$repoOwner, $repoName, $prNumber = $prDataLine.Split(";")

$prApiUrl = "https://api.github.com/repos/${repoOwner}/${repoName}/pulls/${prNumber}"
$prUrl = "https://github.com/${repoOwner}/${repoName}/pull/${prNumber}"

try
{
$response = Invoke-RestMethod -Headers $headers $prApiUrl
if ($response.merged) {
Write-Host "${prApiUrl} is merged."
Write-Host "${prUrl} is merged."
}
elseif ($response.state -eq "closed") {
LogWarning "${prApiUrl} is closed. Please investigate why was not merged."
LogWarning "${prUrl} is closed. Please investigate why was not merged."
$ReadyForMerge = $false
}
elseif ($response.mergeable -and $response.mergeable_state -eq "clean") {
Write-Host "${prApiUrl} is ready to merge."
Write-Host "${prUrl} is ready to merge."

$mergablePRs += @{ Url = $prApiUrl; HeadSHA = $response.head.sha }
}
elseif ($response.mergeable_state -ne "clean") {
LogWarning "${prApiUrl} is blocked ($($response.mergeable_state)). Please ensure all checks are green and reviewers have approved."
LogWarning "${prUrl} is blocked ($($response.mergeable_state)). Please ensure all checks are green and reviewers have approved."
$ReadyForMerge = $false
}
else {
LogWarning "${prApiUrl} is in an unknown state please contact engineering system team to understand the state."
LogWarning "${prUrl} is in an unknown state please contact engineering system team to understand the state."
LogWarning $response
$ReadyForMerge = $false
}
Expand Down

0 comments on commit 99baaea

Please sign in to comment.