Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Tox Environments to be Configured As Skippable via platform-matrix #19965

Merged
merged 4 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions eng/pipelines/templates/jobs/ci.tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ parameters:
- name: ToxEnvParallel
type: string
default: '--tenvparallel'
- name: UnsupportedToxEnvironments
type: string
default: ''
- name: InjectedPackages
type: string
default: ''
Expand Down Expand Up @@ -79,20 +82,14 @@ jobs:
ServiceDirectory: "template"
TestPipeline: ${{ parameters.TestPipeline }}

- pwsh: |
$toxenvvar = "whl,sdist,mindependency"
if ('$(System.TeamProject)' -eq 'internal') {
$toxenvvar = "whl,sdist,depends,latestdependency,mindependency,whl_no_aio"
}

# ensure that the variable is unset. if it isn't, use the value discovered there
if ('$(Run.ToxCustomEnvs)' -ne ('$' + '(Run.ToxCustomEnvs)'))
{
$toxenvvar = '$(Run.ToxCustomEnvs)'
}

echo "##vso[task.setvariable variable=toxenv]$toxenvvar"
displayName: "Set Tox Environment"
- task: PythonScript@0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why the "@0"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the version of the job! The way that you access native devops tasks is by the name + the version. here is the index of native tasks

image

displayName: 'Set Tox Environment'
inputs:
scriptPath: 'scripts/devops_tasks/set_tox_environment.py'
arguments: >-
--unsupported="$(UnsupportedToxEnvironments)"
--override="$(Run.ToxCustomEnvs)"
--team-project="$(System.TeamProject)"

- template: ../steps/build-test.yml
parameters:
Expand Down
4 changes: 4 additions & 0 deletions eng/pipelines/templates/jobs/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ parameters:
- name: ValidateFormatting
type: boolean
default: false
- name: UnsupportedToxEnvironments
type: string
default: ''

jobs:
- job: 'Build'
Expand Down Expand Up @@ -137,6 +140,7 @@ jobs:
TestTimeoutInMinutes: ${{ parameters.TestTimeoutInMinutes }}
ToxEnvParallel: ${{ parameters.ToxEnvParallel }}
InjectedPackages: ${{ parameters.InjectedPackages }}
UnsupportedToxEnvironments: ${{ parameters.UnsupportedToxEnvironments }}

- ${{ if gt(length(parameters.CondaArtifacts), 0) }}:
- template: /eng/common/pipelines/templates/jobs/archetype-sdk-tests-generate.yml
Expand Down
85 changes: 85 additions & 0 deletions scripts/devops_tasks/set_tox_environment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env python

# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import argparse

FULL_BUILD_SET = [
"whl",
"sdist",
"depends",
"latestdependency",
"mindependency",
"whl_no_aio",
]
PR_BUILD_SET = ["whl", "sdist", "mindependency"]


def resolve_devops_variable(var_value):
if var_value.startswith("$("):
return []
else:
return [tox_env.strip() for tox_env in var_value.split(",") if tox_env.strip()]


def set_devops_value(resolved_set):
string_value = ",".join(resolved_set)

print('Setting environment variable toxenv with value "{}"'.format(string_value))
print("##vso[task.setvariable variable=toxenv]{}".format(string_value))


def remove_unsupported_values(selected_set, unsupported_values):
for unsupported_tox_env in unsupported_values:
if unsupported_tox_env in selected_set:
selected_set.remove(unsupported_tox_env)


if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="This script is used to resolve a set of arguments (that correspond to devops runtime variables) and determine which tox environments should be run for the current job."
)

parser.add_argument(
"-t", "--team-project", dest="team_project", help="", required=True
)

parser.add_argument(
"-o",
"--override",
dest="override_set",
help="",
)

parser.add_argument(
"-u",
"--unsupported",
dest="unsupported",
help="",
)

args = parser.parse_args()

team_project = resolve_devops_variable(args.team_project)
override_set = resolve_devops_variable(args.override_set)
unsupported = resolve_devops_variable(args.unsupported)

# by default, we should always start with the default set
selected_set = PR_BUILD_SET

# however if we are internal, use the full set
if "internal" in team_project:
selected_set = FULL_BUILD_SET

# if there is an override present, that will win ALWAYS
if override_set:
selected_set = override_set

# however we never run unsupported values
remove_unsupported_values(selected_set, unsupported)

# and finally output
set_devops_value(selected_set)
3 changes: 2 additions & 1 deletion sdk/identity/platform-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"Pool": "azsdk-pool-mms-ubuntu-1804-general",
"PythonVersion": "3.7",
"CoverageArg": "--disablecov",
"InjectedPackages": "git+https://github.com/AzureAD/microsoft-authentication-library-for-python@dev"
"InjectedPackages": "git+https://github.com/AzureAD/microsoft-authentication-library-for-python@dev",
"UnsupportedToxEnvironments": "mindependency,latestdependency"
}
}
}
Expand Down