Skip to content

Commit d3cf53d

Browse files
committed
re-recording
2 parents 9225659 + 6e8656d commit d3cf53d

File tree

1,141 files changed

+49802
-12986
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,141 files changed

+49802
-12986
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ Mypy install and run.
111111
**Example: Invoke tox, breaking into the debugger on failure**
112112
`tox -e whl -c ../../../eng/tox/tox.ini -- --pdb`
113113

114+
### More Reading
115+
116+
We maintain an [additional document](doc/eng_sys_checks.md) that has a ton of detail as to what is actually _happening_ in these executions.
117+
114118
### Dev Feed
115119
Daily dev build version of Azure sdk packages for python are available and are uploaded to Azure devops feed daily. We have also created a tox environment to test a package against dev built version of dependent packages. Below is the link to Azure devops feed.
116120
[`https://dev.azure.com/azure-sdk/public/_packaging?_a=feed&feed=azure-sdk-for-python`](https://dev.azure.com/azure-sdk/public/_packaging?_a=feed&feed=azure-sdk-for-python)

doc/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ This folder contains some documentations for this repository:
22

33
The folder structure is the following
44
- [sphinx](./sphinx) : contains the documentation source code for https://azure.github.io/azure-sdk-for-python/
5-
- [dev](./dev) : contains advanced documentation for _developers_ of SDK (not _consumers_ of SDK)
5+
- [dev](./dev) : contains advanced documentation for _developers_ of SDK (not _consumers_ of SDK)
6+
7+
The file [eng_sys_checks](eng_sys_checks.md) is a read up as to what a standard `ci.yml` will actually execute.

doc/eng_sys_checks.md

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
# Azure SDK for Python - Engineering System
2+
3+
There are various tests currently enabled in Azure pipeline for Python SDK and some of them are enabled only for nightly CI checks. We also run some static analysis tool to verify code completeness, security and lint check.
4+
5+
Check the [contributing guide](../CONTRIBUTING.md#building-and-testing) for an intro to `tox`.
6+
7+
As a contributor, you will see the build jobs run in two modes: `Nightly Scheduled` and `Pull Request`.
8+
9+
These utilize the _same build definition_, except that the `nightly` builds run additional, deeper checks that run for a bit longer.
10+
11+
Example PR build:
12+
13+
![res/job_snippet.png](res/job_snippet.png)
14+
15+
- `Analyze` tox envs run during the `Analyze job.
16+
- `Test <platform>_<pyversion>` runs PR/Nightly tox envs, depending on context.
17+
18+
## Analyze Checks
19+
Analyze job in both nightly CI and pull request validation pipeline runs a set of static analysis using external and internal tools. Following are the list of these static analysis.
20+
21+
#### MyPy
22+
`Mypy` is a static analysis tool that runs type checking of python package. Following are the steps to run `MyPy` locally for a specific package
23+
1. Go to root of the package
24+
2. Execute following command
25+
```tox -e mypy -c ../../../eng/tox/tox.ini ```
26+
27+
#### Pylint
28+
`Pylint` is a static analysis tool to run lint checking. Following are the steps to run `pylint` locally for a specific package.
29+
30+
1. Go to root of the package.
31+
2. Execute following command
32+
```tox -e pylint -c ../../../eng/tox/tox.ini```
33+
34+
35+
#### Bandit
36+
`Bandit` is static security analysis tool. This check is triggered for all Azure SDK package as part of analyze job. Following are the steps to `Bandit` tool locally for a specific package.
37+
38+
1. Got to package root directory.
39+
2. Execute following command
40+
```tox -e bandit -c ../../../eng/tox/tox.ini```
41+
42+
43+
#### ApiStubGen
44+
`ApiStubGen` is an internal tool used to create API stub to help reviewing public APIs in our SDK package using [`APIViewTool`.](https://apiview.dev/) This tool also has some built in lint checks available and purpose of having this step in analyze job is to ensure any change in code is not impacting stubbing process and also to have more and more custom lint checks added in future.
45+
46+
#### Change log verification
47+
48+
Change log verification is added to ensure package has valid change log for current version. Guidelines to properly maintain the change log is documented [here]()
49+
50+
## PR Validation Checks
51+
Each pull request runs various tests using `pytest` in addition to all the tests mentioned above in analyze check. Pull request validation performs 3 different types of test: `whl, sdist and depends`. Following section explains the purpose of each of these tests and how to execute them locally. All pull requests are validated on multiple python versions across different platforms and below is the test matrix for pull request.
52+
53+
54+
|`Python Version`|`Platform` |
55+
|--|--|
56+
|2.7|Linux|
57+
|3.5|Windows|
58+
|3.8|Linux|
59+
60+
### PR validation tox test environments
61+
Tests are executed using tox environment and following are the tox test names that are part of pull request validation
62+
#### whl
63+
This test installs wheel of the package being tested and runs all tests cases in the package using `pytest`. Following is the command to run this test environment locally.
64+
65+
1. Go to package root folder on a command line
66+
2. Run following command
67+
``tox -e whl -c ../../../eng/tox/tox.ini``
68+
69+
#### sdist
70+
This test installs sdist of the package being tested and runs all tests cases in the package using `pytest`. Following is the command to run this test environment locally.
71+
72+
1. Go to package root folder on a command line
73+
2. Run following command
74+
``tox -e sdist -c ../../../eng/tox/tox.ini``
75+
76+
####depends
77+
This test is to ensure all modules in the package being tested can be successfully imported. This is to ensure all package requirement is properly set in setup.py as well as to ensure modules are imported using valid namespace. This test install the package and it's required packages and executes `from <package-root-namespace> import *`. For e.g. `from azure.core import *`.
78+
79+
Following is the command to run this test environment locally.
80+
81+
1. Go to package root folder on a command line
82+
2. Run following command
83+
``tox -e sdist -c ../../../eng/tox/tox.ini``
84+
85+
86+
## Nightly CI Checks
87+
88+
Nightly continuous integration checks run all tests mentioned above in Analyze and Pull request checks in addition to multiple other tests. Nightly CI checks run on all python versions that are supported by Azure SDK packages across multiple platforms.
89+
90+
![res/full_matrix.png](res/full_matrix.png)
91+
92+
Regression also executes:
93+
![res/regression.png](res/regression.png)
94+
95+
Nightly CI check runs following additional tests to ensure the dependency between a package being developed against released packages to ensure backward compatibility. Following is the explanation of why we need dependency tests to ensure backward compatibility.
96+
97+
Imagine a situation where package `XYZ` requires another package `ABC` and as per the package requirement of `XYZ`, It should work with any version between 1.0 and 2.0 of package `ABC`.
98+
99+
Package `XYZ` requires package `ABC`
100+
101+
As a developer of package `XYZ`, we need to ensure that our package works fine with all versions of ABC as long as it is within package requirement specification.
102+
103+
Another scenario where regression test( reverse dependency) is required. Let's take same example above and assume we are developers of package `ABC` which is taken as required package by another package `XYZ`
104+
105+
Package `ABC is required by package `XYZ`
106+
107+
108+
As a developer of `ABC`, we need to ensure that any new change in `ABC` is not breaking the use of `XYZ` and hence ensures backward compatibility.
109+
110+
Let's take few Azure SDK packages instead of dummy names to explain this in a context we are more familiar of.
111+
112+
Most of the Azure SDK packages require `azure-core` and this requirement is within a range for e.g. `azure-storage-blob` that requires `azure-core >1.0.0, <2.0.0`. So any new change in azure-storage-blob needs to make sure it works fine with all versions of azure-core between 1.0.0 and 2.0.0(Both included).
113+
Similarly any new version of azure-core needs to ensure that it is still compatible with all released package versions which takes azure-core as required package.
114+
115+
It is lot of combinations if we need to run tests for all released versions within the range of requirement specification. In order to reduce the test matrix and at the same time ensures the quality, we currently run the test using oldest released and latest released packages and skips any version in between.
116+
117+
Following are the additional tests we run during nightly CI checks.
118+
119+
####Latest Dependency Test
120+
121+
This test makes sure that a package being developed works absolutely fine using latest released version of required Azure SDK package as long as there is a released version which satisfies the requirement specification. Workflow of this test is as follows:
122+
123+
1. Identify if any azure SDK package is marked as required package in setup.py of current package being tested.
124+
Note: Any dependency mentioned only in dev_requirements are not considered to identify dependency.
125+
2. Identify latest released version of required azure sdk package on PyPI
126+
3. Install latest released version of required package instead of dev dependency to package in code repo
127+
4. Install current package that is being tested
128+
5. Run pytest of all test cases in current package
129+
130+
Tox name of this test is `latestdependency` and steps to manually run this test locally is as follows.
131+
1. Go to package root. For e.g azure-storage-blob or azure-identity
132+
2. Run following command
133+
`Tox –e latestdependency –c ../../../tox/tox.ini`
134+
135+
136+
####Oldest Dependency Test
137+
138+
This test makes sure that a package being developed works absolutely fine using oldest released version of required Azure SDK package as long as there is a released version which satisfies the requirement specification. Workflow of this test is as follows:
139+
140+
1. Identify if any azure SDK package is marked as required package in setup.py of current package being tested.
141+
Note: Any dependency mentioned only in dev_requirements are not considered to identify dependency.
142+
2. Identify oldest released version of required azure sdk package on PyPI
143+
3. Install oldest released version of required package instead of dev dependency to package in code repo
144+
4. Install current package that is being tested
145+
5. Run pytest of all test cases in current package
146+
147+
Tox name of this test is `mindependency` and steps to manually run this test locally is as follows.
148+
1. Go to package root. For e.g azure-storage-blob or azure-identity
149+
2. Run following command
150+
`Tox –e mindependency –c ../../../tox/tox.ini`
151+
152+
153+
####Regression Test
154+
155+
As mentioned earlier, regression test or reverse dependency test is added to avoid a regression scenario for customers when any new change is made in a package that is required by other packages. Currently we have only very few Azure SDK packages that are added as required package by other Azure SDK package. As of now, list of these required packages are:
156+
`azure-core`
157+
`azure-eventhub`
158+
`azure-storage-blob`
159+
160+
Our regression framework automatically finds any such package that is added as required package so this list is not hardcoded.
161+
162+
We have two different set of regression tests to verify regression scenarios against oldest and latest released dependent packages.
163+
• Regression using latest released dependent package
164+
• Regression using oldest released dependent package
165+
166+
One main difference between regression tests and forward dependency test( latest and mindependency) is in terms of what test cases are executed as part of the tests. While forward dependency tests executes the test cases in current code repo, regression tests execute the tests that were part of repo at the time of dependent package release. To make it more clear, let's look at an example here.
167+
168+
Let's assume that we are testing regression for azure-core and this test is for regression against latest released dependent packages. Test will identify all packages that takes azure-core as required package and finds latest released version of those packages. Test framework install currently being developed azure-core and latest released dependent package and runs the test cases in dependent package, for e.g. azure-identity, that were part of repo at the time of releasing depending package.
169+
170+
Workflow of this test is as follows when running regression for an SDK package.
171+
1. Identify any packages that takes currently being tested package as required package
172+
2. Find latest and oldest released versions of dependent package from PyPI
173+
3. Install currently being developed version of package we are testing regression for. E.g. azure-core
174+
4. Checkout the release tag of dependent package from github
175+
5. Install latest/oldest version of dependent package. For e.g. azure-identity
176+
6. Run test cases within dependent package from checked out branch.
177+
178+
179+
Steps to manually run regression test locally:
180+
1. Run below command from your git code repo to generate the wheel of package being developed. Currently we have restricted to have prebuilt wheel.
181+
`./scripts/devops_tasks/build_packages.py --service= <service-name> -d <out-folder>`
182+
2. Run below command to start regression test locally
183+
`./scripts/devops_tasks/test_regression.py azure-* --service=<service-name> --whl-dir=<out-folder given above in step 2>`
184+
185+
186+
How to run these additional tests on azure pipelines manually
187+
188+
Following variables can be set at queueing time in order to run these additional tests which are by default run only for scheduled runs.
189+
190+
• Latest and oldest dependency test in addition to basic testing
191+
Variable name: `Run.DependencyTest`
192+
Value: true
193+
194+
• Regression test
195+
Variable name: `Run.Regression`
196+
Value: true

doc/res/full_matrix.png

19.3 KB
Loading

doc/res/job_snippet.png

14 KB
Loading

doc/res/regression.png

5.08 KB
Loading

eng/common/pipelines/templates/steps/create-pull-request.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ parameters:
1111
PushArgs:
1212
WorkingDirectory: $(System.DefaultWorkingDirectory)
1313
PRTitle: not-specified
14-
PRBody: not-specified
14+
PRBody: ''
1515
ScriptDirectory: eng/common/scripts
1616
GHReviewersVariable: ''
1717
GHTeamReviewersVariable: ''
@@ -68,12 +68,13 @@ steps:
6868
-PRBranch "${{ parameters.PRBranchName }}"
6969
-AuthToken "$(azuresdk-github-pat)"
7070
-PRTitle "${{ parameters.PRTitle }}"
71+
-PRBody "${{ coalesce(parameters.PRBody, parameters.CommitMsg, parameters.PRTitle) }}"
7172
-PRLabels "${{ parameters.PRLabels}}"
72-
-PRBody "${{ parameters.PRBody }}"
7373
7474
- task: PowerShell@2
7575
displayName: Tag a Reviewer on PR
7676
condition: and(succeeded(), eq(variables['HasChanges'], 'true'))
77+
continueOnError: true
7778
inputs:
7879
pwsh: true
7980
workingDirectory: ${{ parameters.WorkingDirectory }}

eng/common/pipelines/templates/steps/get-pr-owners.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,20 @@ steps:
1818
--kusto-database-var KUSTO_DB `
1919
--kusto-table-var KUSTO_TABLE `
2020
--identity "$(Build.QueuedBy)"
21-
$resolvedIdentity = $result[-1] | ConvertFrom-Json
2221
23-
Write-Host $resolvedIdentity
22+
$resolvedIdentity = ""
23+
try { $resolvedIdentity = $result[-1] | ConvertFrom-Json } catch {}
2424
25-
Write-Output "##vso[task.setvariable variable=${{ parameters.TargetVariable }}]$($resolvedIdentity.GithubUserName)"
25+
if($resolvedIdentity) {
26+
Write-Host $resolvedIdentity
27+
28+
Write-Host "##vso[task.setvariable variable=${{ parameters.TargetVariable }}]$($resolvedIdentity.GithubUserName)"
29+
}
30+
else {
31+
Write-Host "Unable to locate a github user for identity $(Build.QueuedBy)"
32+
}
2633
displayName: 'Resolving Queuing User'
34+
continueOnError: true
2735
workingDirectory: $(Build.SourcesDirectory)/tools_repo/tools/notification-configuration/identity-resolver
2836
env:
2937
APP_ID: $(notification-aad-app-id)
@@ -41,6 +49,6 @@ steps:
4149
$originalValue = "$(${{ parameters.TargetVariable }})"
4250
$result = $(Build.SourcesDirectory)/eng/common/scripts/get-codeowners.ps1 -TargetDirectory /sdk/${{ parameters.ServiceDirectory }}/ -RootDirectory $(Build.SourcesDirectory)
4351
if ($result) {
44-
Write-Output "##vso[task.setvariable variable=${{ parameters.TargetVariable }}]$originalValue,$result"
52+
Write-Host "##vso[task.setvariable variable=${{ parameters.TargetVariable }}]$originalValue,$result"
4553
}
4654
displayName: Add CodeOwners if Present

eng/common/scripts/Submit-PullRequest.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ The branch which we want to create a pull request for.
1717
A personal access token
1818
.PARAMETER PRTitle
1919
The title of the pull request.
20+
.PARAMETER PRBody
21+
The body message for the pull request.
2022
.PARAMETER PRLabels
2123
The labels added to the PRs. Multple labels seperated by comma, e.g "bug, service"
2224
#>
@@ -42,7 +44,9 @@ param(
4244

4345
[Parameter(Mandatory = $true)]
4446
[string]$PRTitle,
45-
$PRBody = $PRTitle,
47+
48+
[Parameter(Mandatory = $false)]
49+
[string]$PRBody = $PRTitle,
4650

4751
[Parameter(Mandatory = $false)]
4852
[string]$PRLabels

eng/common/scripts/add-pullrequest-reviewers.ps1

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,32 @@ param(
1818
$AuthToken
1919
)
2020

21+
function AddMembers($memberName, $additionSet) {
22+
$headers = @{
23+
Authorization = "bearer $AuthToken"
24+
}
25+
$uri = "https://api.github.com/repos/$RepoOwner/$RepoName/pulls/$PRNumber/requested_reviewers"
26+
$errorOccurred = $false
27+
28+
foreach ($id in $additionSet) {
29+
try {
30+
$postResp = @{}
31+
$postResp[$memberName] = @($id)
32+
$postResp = $postResp | ConvertTo-Json
33+
34+
Write-Host $postResp
35+
$resp = Invoke-RestMethod -Method Post -Headers $headers -Body $postResp -Uri $uri -MaximumRetryCount 3
36+
$resp | Write-Verbose
37+
}
38+
catch {
39+
Write-Host "Error attempting to add $user `n$_"
40+
$errorOccurred = $true
41+
}
42+
}
43+
44+
return $errorOccurred
45+
}
46+
2147
# at least one of these needs to be populated
2248
if (-not $GitHubUsers -and -not $GitHubTeams) {
2349
Write-Host "No user provided for addition, exiting."
@@ -27,54 +53,9 @@ if (-not $GitHubUsers -and -not $GitHubTeams) {
2753
$userAdditions = @($GitHubUsers.Split(",") | % { $_.Trim() } | ? { return $_ })
2854
$teamAdditions = @($GitHubTeams.Split(",") | % { $_.Trim() } | ? { return $_ })
2955

30-
$headers = @{
31-
Authorization = "bearer $AuthToken"
32-
}
33-
$uri = "https://api.github.com/repos/$RepoOwner/$RepoName/pulls/$PRNumber/requested_reviewers"
56+
$errorsOccurredAddingUsers = AddMembers -memberName "reviewers" -additionSet $userAdditions
57+
$errorsOccurredAddingTeams = AddMembers -memberName "team_reviewers" -additionSet $teamAdditions
3458

35-
try {
36-
$resp = Invoke-RestMethod -Headers $headers $uri -MaximumRetryCount 3
37-
}
38-
catch {
39-
Write-Error "Invoke-RestMethod [$uri] failed with exception:`n$_"
59+
if ($errorsOccurredAddingUsers -or $errorsOccurredAddingTeams) {
4060
exit 1
4161
}
42-
43-
# the response object takes this form: https://developer.github.com/v3/pulls/review_requests/#response-1
44-
# before we can push a new reviewer, we need to pull the simple Ids out of the complex objects that came back in the response
45-
$userReviewers = @($resp.users | % { return $_.login })
46-
$teamReviewers = @($resp.teams | % { return $_.slug })
47-
48-
if (!$userReviewers) { $modifiedUserReviewers = @() } else { $modifiedUserReviewers = $userReviewers.Clone() }
49-
$modifiedUserReviewers += ($userAdditions | ? { !$modifiedUserReviewers.Contains($_) })
50-
51-
if ($teamReviewers) { $modifiedTeamReviewers = @() } else { $modifiedTeamReviewers = $teamReviewers.Clone() }
52-
$modifiedTeamReviewers += ($teamAdditions | ? { !$modifiedTeamReviewers.Contains($_) })
53-
54-
$detectedUserDiffs = Compare-Object -ReferenceObject $userReviewers -DifferenceObject $modifiedUserReviewers
55-
$detectedTeamDiffs = Compare-Object -ReferenceObject $teamReviewers -DifferenceObject $modifiedTeamReviewers
56-
57-
# Compare-Object returns values when there is a difference between the comparied objects.
58-
# we only want to run the update if there IS a difference.
59-
if ($detectedUserDiffs -or $detectedTeamDiffs) {
60-
$postResp = @{}
61-
62-
if ($modifiedUserReviewers) { $postResp["reviewers"] = $modifiedUserReviewers }
63-
if ($modifiedTeamReviewers) { $postResp["team_reviewers"] = $modifiedTeamReviewers }
64-
65-
$postResp = $postResp | ConvertTo-Json
66-
67-
try {
68-
Write-Host $postResp
69-
$resp = Invoke-RestMethod -Method Post -Headers $headers -Body $postResp -Uri $uri -MaximumRetryCount 3
70-
$resp | Write-Verbose
71-
}
72-
catch {
73-
Write-Error "Unable to update PR reviewers. `n$_"
74-
}
75-
}
76-
else {
77-
$results = $GitHubUsers + $GitHubTeams
78-
Write-Host "Reviewers $results already added. Exiting."
79-
exit(0)
80-
}

0 commit comments

Comments
 (0)