Skip to content

Commit b5c04d8

Browse files
authored
Sync eng/common directory with azure-sdk-tools for PR 1081 (#15886)
Sync eng/common directory with azure-sdk-tools for PR Azure/azure-sdk-tools#1081 See [eng/common workflow](https://github.com/Azure/azure-sdk-tools/blob/master/eng/common/README.md#workflow)
1 parent 3d12ebf commit b5c04d8

File tree

6 files changed

+299
-62
lines changed

6 files changed

+299
-62
lines changed

eng/common/README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ languages repos as they will be overwritten the next time an update is taken fro
1313

1414
### Workflow
1515

16-
The 'Sync eng/common directory' PRs will be created in the language repositories once a pull request that touches the eng/common directory is submitted against the master branch. This will make it easier for changes to be tested in each individual language repo before merging the changes in the azure-sdk-tools repo. The workflow is explained below:
16+
The 'Sync eng/common directory' PRs will be created in the language repositories when a pull request that touches the eng/common directory is submitted against the master branch. This will make it easier for changes to be tested in each individual language repo before merging the changes in the azure-sdk-tools repo. The workflow is explained below:
1717

18-
1. Create a PR against Azure/azure-sdk-tools:master. This is the **Tools PR**.
19-
2. `azure-sdk-tools - sync - eng-common` is run automatically. It creates **Sync PRs** in each of the connected language repositories using the format `Sync eng/common directory with azure-sdk-tools for PR {Tools PR Number}`. Each **Sync PR** will contain a link back to the **Tools PR** that triggered it.
20-
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.
21-
4. Once satisfied with the changes;
22-
- 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.
23-
- 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-PRs.ps1 <path to PRsCreated.txt>` which will output the status of each associated PR.
24-
- 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.
25-
- Finally merge the **Tools PR**.
18+
1. Create a PR (**Tools PR**) in the `azure-sdk-tools` repo with changes to eng/common directory.
19+
2. `azure-sdk-tools - sync - eng-common` pipeline is triggered for the **Tools PR**
20+
3. The `azure-sdk-tools - sync - eng-common` pipeline queues test runs for template pipelines in various languages. These help you test your changes in the **Tools PR**.
21+
4. If there are changes in the **Tools PR** that will affect the release stage you should approve the release test pipelines by clicking the approval gate. The test (template) pipeline will automatically release the next eligible version without needing manual intervention for the versioning. Please approve your test releases as quickly as possible. A race condition may occur due to someone else queueing the pipeline and going all the way to release using your version while yours is still waiting. If this occurs manually rerun the pipeline that failed.
22+
5. If you make additional changes to your **Tools PR** repeat steps 1 - 4 until you have completed the necessary testing of your changes. This includes full releases of the template package, if necessary.
23+
6. Sign off on CreateSyncPRs stage of the sync pipeline using the approval gate. This stage will create the **Sync PRs** in the various language repos with the `auto-merge` label applied. A link to each of the **Sync PRs** will show up in the **Tools PR** for you to click and review.
24+
7. Go review and approve each of your **Sync PRs**. The merging will happen automatically.
25+
8. Sign off on VerifyAndMerge stage of the sync pipeline using the approval gate. This stage will merge any remaining open **Sync PRs** and also append `auto-merge` to the **Tools PR** so it will automatically merge once the pipeline finishes.
26+
7. Sign Off on the VerifyAndMerge stage. This will merge any remaining open **Sync PR** and also append `auto-merge` to the **Tools PR**.

eng/common/scripts/Add-Issue-Comment.ps1

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[CmdletBinding(SupportsShouldProcess = $true)]
2+
param(
3+
[Parameter(Mandatory = $true)]
4+
[string]$RepoOwner,
5+
6+
[Parameter(Mandatory = $true)]
7+
[string]$RepoName,
8+
9+
[Parameter(Mandatory = $true)]
10+
[string]$IssueNumber,
11+
12+
[Parameter(Mandatory = $true)]
13+
[string]$Comment,
14+
15+
[Parameter(Mandatory = $true)]
16+
[string]$AuthToken
17+
)
18+
19+
. "${PSScriptRoot}\common.ps1"
20+
21+
try {
22+
Add-IssueComment -RepoOwner $RepoOwner -RepoName $RepoName `
23+
-IssueNumber $IssueNumber -Comment $Comment -AuthToken $AuthToken
24+
}
25+
catch {
26+
LogError "Add-IssueComment failed with exception:`n$_"
27+
exit 1
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[CmdletBinding(SupportsShouldProcess = $true)]
2+
param(
3+
[Parameter(Mandatory = $true)]
4+
[string]$RepoOwner,
5+
6+
[Parameter(Mandatory = $true)]
7+
[string]$RepoName,
8+
9+
[Parameter(Mandatory = $true)]
10+
[string]$IssueNumber,
11+
12+
[Parameter(Mandatory = $true)]
13+
[string]$Labels,
14+
15+
[Parameter(Mandatory = $true)]
16+
[string]$AuthToken
17+
)
18+
19+
. "${PSScriptRoot}\common.ps1"
20+
21+
try {
22+
Add-IssueLabels -RepoOwner $RepoOwner -RepoName $RepoName `
23+
-IssueNumber $IssueNumber -Labels $Labels -AuthToken $AuthToken
24+
}
25+
catch {
26+
LogError "Add-IssueLabels failed with exception:`n$_"
27+
exit 1
28+
}
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
$GithubAPIBaseURI = "https://api.github.com/repos"
2+
3+
function Get-GitHubHeaders ($token) {
4+
$headers = @{
5+
Authorization = "bearer $token"
6+
}
7+
return $headers
8+
}
9+
10+
function Invoke-GitHubAPIPost {
11+
param (
12+
[Parameter(Mandatory = $true)]
13+
$apiURI,
14+
[Parameter(Mandatory = $true)]
15+
$body,
16+
[Parameter(Mandatory = $true)]
17+
$token
18+
)
19+
20+
$resp = Invoke-RestMethod `
21+
-Method POST `
22+
-Body ($body | ConvertTo-Json) `
23+
-Uri $apiURI `
24+
-Headers (Get-GitHubHeaders -token $token) `
25+
-MaximumRetryCount 3
26+
27+
return $resp
28+
}
29+
30+
function Invoke-GitHubAPIPatch {
31+
param (
32+
[Parameter(Mandatory = $true)]
33+
$apiURI,
34+
[Parameter(Mandatory = $true)]
35+
$body,
36+
[Parameter(Mandatory = $true)]
37+
$token
38+
)
39+
40+
$resp = Invoke-RestMethod `
41+
-Method PATCH `
42+
-Body ($body | ConvertTo-Json) `
43+
-Uri $apiURI `
44+
-Headers (Get-GitHubHeaders -token $token) `
45+
-MaximumRetryCount 3
46+
47+
return $resp
48+
}
49+
50+
function Invoke-GitHubAPIGet {
51+
param (
52+
[Parameter(Mandatory = $true)]
53+
$apiURI,
54+
$token
55+
)
56+
57+
if ($token)
58+
{
59+
$resp = Invoke-RestMethod `
60+
-Method GET `
61+
-Uri $apiURI `
62+
-Headers (Get-GitHubHeaders -token $token) `
63+
-MaximumRetryCount 3
64+
}
65+
else {
66+
$resp = Invoke-RestMethod `
67+
-Method GET `
68+
-Uri $apiURI `
69+
-MaximumRetryCount 3
70+
}
71+
72+
return $resp
73+
}
74+
75+
function SplitMembers ($membersString)
76+
{
77+
if (!$membersString) { return $null }
78+
return @($membersString.Split(",") | % { $_.Trim() } | ? { return $_ })
79+
}
80+
81+
function List-PullRequests {
82+
param (
83+
[Parameter(Mandatory = $true)]
84+
$RepoOwner,
85+
[Parameter(Mandatory = $true)]
86+
$RepoName,
87+
[ValidateSet("open","closed","all")]
88+
$State = "open",
89+
$Head,
90+
$Base,
91+
[ValidateSet("created","updated","popularity","long-running")]
92+
$Sort,
93+
[ValidateSet("asc","desc")]
94+
$Direction
95+
)
96+
97+
$uri = "$GithubAPIBaseURI/$RepoOwner/$RepoName/pulls"
98+
if ($State -or $Head -or $Base -or $Sort -or $Direction) { $uri += '?'}
99+
if ($State) { $uri += "state=$State&" }
100+
if ($Head) { $uri += "head=$Head&" }
101+
if ($Base) { $uri += "base=$Base&" }
102+
if ($Sort) { $uri += "sort=$Sort&" }
103+
if ($Direction){ $uri += "direction=$Direction&" }
104+
105+
return Invoke-GitHubAPIGet -apiURI $uri
106+
}
107+
108+
function Add-IssueComment {
109+
param (
110+
[Parameter(Mandatory = $true)]
111+
$RepoOwner,
112+
[Parameter(Mandatory = $true)]
113+
$RepoName,
114+
[Parameter(Mandatory = $true)]
115+
$IssueNumber,
116+
[Parameter(Mandatory = $true)]
117+
$Comment,
118+
[Parameter(Mandatory = $true)]
119+
$AuthToken
120+
121+
)
122+
$uri = "$GithubAPIBaseURI/$RepoOwner/$RepoName/issues/$IssueNumber/comments"
123+
124+
$parameters = @{
125+
body = $Comment
126+
}
127+
128+
return Invoke-GitHubAPIPost -apiURI $uri -body $parameters -token $AuthToken
129+
}
130+
131+
# Will add labels to existing labels on the issue
132+
function Add-IssueLabels {
133+
param (
134+
[Parameter(Mandatory = $true)]
135+
$RepoOwner,
136+
[Parameter(Mandatory = $true)]
137+
$RepoName,
138+
[Parameter(Mandatory = $true)]
139+
$IssueNumber,
140+
[ValidateNotNullOrEmpty()]
141+
[Parameter(Mandatory = $true)]
142+
$Labels,
143+
[Parameter(Mandatory = $true)]
144+
$AuthToken
145+
)
146+
147+
if ($Labels.Trim().Length -eq 0)
148+
{
149+
throw "The 'Labels' parameter should not not be whitespace..`
150+
You can use the 'Update-Issue' function if you plan to reset the labels"
151+
}
152+
153+
$uri = "$GithubAPIBaseURI/$RepoOwner/$RepoName/issues/$IssueNumber/labels"
154+
$labelAdditions = SplitMembers -membersString $Labels
155+
$parameters = @{
156+
labels = @($labelAdditions)
157+
}
158+
159+
return Invoke-GitHubAPIPost -apiURI $uri -body $parameters -token $AuthToken
160+
}
161+
162+
# Will add assignees to existing assignees on the issue
163+
function Add-IssueAssignees {
164+
param (
165+
[Parameter(Mandatory = $true)]
166+
$RepoOwner,
167+
[Parameter(Mandatory = $true)]
168+
$RepoName,
169+
[Parameter(Mandatory = $true)]
170+
$IssueNumber,
171+
[ValidateNotNullOrEmpty()]
172+
[Parameter(Mandatory = $true)]
173+
$Assignees,
174+
[Parameter(Mandatory = $true)]
175+
$AuthToken
176+
)
177+
178+
if ($Assignees.Trim().Length -eq 0)
179+
{
180+
throw "The 'Assignees' parameter should not be whitespace.`
181+
You can use the 'Update-Issue' function if you plan to reset the Assignees"
182+
}
183+
184+
$uri = "$GithubAPIBaseURI/$RepoOwner/$RepoName/issues/$IssueNumber/assignees"
185+
$assigneesAdditions = SplitMembers -membersString $Assignees
186+
$parameters = @{
187+
assignees = @($assigneesAdditions)
188+
}
189+
190+
return Invoke-GitHubAPIPost -apiURI $uri -body $parameters -token $AuthToken
191+
}
192+
193+
# For labels and assignee pass comma delimited string, to replace existing labels or assignees.
194+
# Or pass white space " " to remove all labels or assignees
195+
function Update-Issue {
196+
param (
197+
[Parameter(Mandatory = $true)]
198+
$RepoOwner,
199+
[Parameter(Mandatory = $true)]
200+
$RepoName,
201+
[Parameter(Mandatory = $true)]
202+
$IssueNumber,
203+
[string]$Title,
204+
[string]$Body,
205+
[ValidateSet("open","closed")]
206+
[string]$State,
207+
[int]$Milestome,
208+
[ValidateNotNullOrEmpty()]
209+
[string]$Labels,
210+
[ValidateNotNullOrEmpty()]
211+
[string]$Assignees,
212+
[Parameter(Mandatory = $true)]
213+
$AuthToken
214+
)
215+
216+
$uri = "$GithubAPIBaseURI/$RepoOwner/$RepoName/issues/$IssueNumber"
217+
$parameters = @{}
218+
if ($Title) { $parameters["title"] = $Title }
219+
if ($Body) { $parameters["body"] = $Body }
220+
if ($State) { $parameters["state"] = $State }
221+
if ($Milestone) { $parameters["milestone"] = $Milestone }
222+
if ($Labels) {
223+
$labelAdditions = SplitMembers -membersString $Labels
224+
$parameters["labels"] = @($labelAdditions)
225+
}
226+
if ($Assignees) {
227+
$assigneesAdditions = SplitMembers -membersString $Assignees
228+
$parameters["assignees"] = @($assigneesAdditions)
229+
}
230+
231+
return Invoke-GitHubAPIPatch -apiURI $uri -body $parameters -token $AuthToken
232+
}

eng/common/scripts/common.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ $EngScriptsDir = Join-Path $EngDir "scripts"
99
. (Join-Path $EngCommonScriptsDir ChangeLog-Operations.ps1)
1010
. (Join-Path $EngCommonScriptsDir Package-Properties.ps1)
1111
. (Join-Path $EngCommonScriptsDir logging.ps1)
12+
. (Join-Path $EngCommonScriptsDir Invoke-GitHubAPI.ps1)
1213

1314
# Setting expected from common languages settings
1415
$Language = "Unknown"

0 commit comments

Comments
 (0)