Skip to content

Commit 8acb041

Browse files
CI enabled flag (#33387)
* try ci_enabled flag * try using a gh env var * fix import * set env var, add filter in discover_targeted_packages * add Public param to ci.yml test * retry setting env var * pass through template * missing paren * don't look for Public in ci.yml * try again * remove unrecognized arg * print vars * try checking build.reason * few fixes + prints * try testing skip * try more prints * try more prints * try more prints * try nonempty packages list * ignore discover_targeted_packages for now * try again * try again * try no parameter * missed import * accidentally deleted other var * try again * fix * test set PULLREQUEST * missed var * set var correctly * don't fail docs step * remove condition * comment * fake pull request run * with discover targeted packages filter run * remove print debugs * try only publish artifacts if they exist for docs * remove filter for now * try again * set in right tempalte * switch to a service we actually want to disable * formatting * feedback * block on release if ci_enabled=false * test disabling ci for template, should block on release * remove test setting from azure-template * remove unused import and add small doc
1 parent 5c4c683 commit 8acb041

File tree

7 files changed

+82
-1
lines changed

7 files changed

+82
-1
lines changed

doc/eng_sys_checks.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ The various tooling abstracted by the environments within `eng/tox/tox.ini` take
153153

154154
Packages with classifier `Development Status :: 7 - Inactive`, are **not** built by default and as such normal `checks` like `mypy` and `pylint` are also not run against them. Older "core" packages like `azure-common` and `azure-servicemanagement-legacy` are present, but excluded from the build due to this restriction.
155155

156+
Additionally, packages with the pyproject.toml option `ci_enabled = false` will **skip** normal checks and tests. This is used for packages that are not yet compliant with certain CI checks. If `ci_enabled = false` is present in the package's pyproject.toml, it will be blocked from releasing until it is removed and all required CI checks pass.
157+
156158
To temporarily **override** this restriction, a dev need only set the queue time variable: `ENABLE_PACKAGE_NAME`. The `-` in package names should be replaced by an `_`, as that is how the environment variable will be set on the actual CI machine anyway.
157159

158160
- `ENABLE_AZURE_COMMON=true`

eng/pipelines/templates/stages/archetype-python-release.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ stages:
4646
PackageName: ${{artifact.name}}
4747
ServiceName: ${{parameters.ServiceDirectory}}
4848
ForRelease: true
49+
50+
- task: PythonScript@0
51+
displayName: Verify CI enabled
52+
condition: succeeded()
53+
inputs:
54+
scriptPath: 'scripts/devops_tasks/verify_ci_enabled.py'
55+
arguments: '--package-name ${{ artifact.name }} --service ${{ parameters.ServiceDirectory }}'
56+
4957
- pwsh: |
5058
Get-ChildItem -Recurse $(Pipeline.Workspace)/${{parameters.ArtifactName}}/${{artifact.name}}
5159
workingDirectory: $(Pipeline.Workspace)

eng/pipelines/templates/steps/build-extended-artifacts.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,15 @@ steps:
8686
ArtifactPath: '$(Build.ArtifactStagingDirectory)'
8787
ArtifactName: 'packages_extended'
8888

89+
- pwsh: |
90+
$directoryExists = Test-Path -Path "$(Build.SourcesDirectory)/_docs"
91+
Write-Output "##vso[task.setvariable variable=DirectoryExists]$directoryExists"
92+
displayName: Check if docs directory exists
93+
8994
- template: /eng/common/pipelines/templates/steps/publish-artifact.yml
9095
parameters:
9196
ArtifactPath: '$(Build.SourcesDirectory)/_docs'
92-
CustomCondition: ${{ parameters.BuildDocs }}
97+
CustomCondition: and(${{ parameters.BuildDocs }}, eq(variables['DirectoryExists'], 'True'))
9398
ArtifactName: 'documentation'
9499

95100
- ${{if eq(variables['System.TeamProject'], 'internal') }}:
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python
2+
3+
# --------------------------------------------------------------------------------------------
4+
# Copyright (c) Microsoft Corporation. All rights reserved.
5+
# Licensed under the MIT License. See License.txt in the project root for license information.
6+
# --------------------------------------------------------------------------------------------
7+
8+
import argparse
9+
import sys
10+
import os
11+
12+
from ci_tools.environment_exclusions import get_config_setting
13+
14+
root_dir = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", ".."))
15+
16+
def verify_ci_enabled(package_name: str, package_path: str) -> None:
17+
"""Verifies that ci_enabled=false is not present in the package's pyproject.toml.
18+
This prevents releasing packages that have disabled their CI.
19+
"""
20+
21+
ci_enabled = get_config_setting(package_path, "ci_enabled")
22+
if ci_enabled is False:
23+
print(
24+
f"ci_enabled is set to false in {package_name}/pyproject.toml. " \
25+
"You must remove this setting before releasing the package."
26+
)
27+
sys.exit(1)
28+
29+
30+
if __name__ == "__main__":
31+
parser = argparse.ArgumentParser(
32+
description="Verifies ci_enabled=true or is not present in the package's pyproject.toml, Called from DevOps YAML Pipeline"
33+
)
34+
35+
parser.add_argument(
36+
"--package-name",
37+
required=True,
38+
help="name of package (accepts both formats: azure-service-package and azure_service_package)",
39+
)
40+
parser.add_argument(
41+
"--service",
42+
required=True,
43+
help="name of the service for which to set the dev build id (e.g. keyvault)",
44+
)
45+
46+
args = parser.parse_args()
47+
48+
package_name = args.package_name.replace("_", "-")
49+
path_to_setup = os.path.join(root_dir, "sdk", args.service, package_name, "setup.py")
50+
verify_ci_enabled(package_name, path_to_setup)

sdk/metricsadvisor/azure-ai-metricsadvisor/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ pylint = false
44
pyright = false
55
type_check_samples = false
66
verifytypes = false
7+
ci_enabled = false

tools/azure-sdk-tools/ci_tools/environment_exclusions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Licensed under the MIT License. See License.txt in the project root for license information.
66
# --------------------------------------------------------------------------------------------
77
from ci_tools.parsing import get_config_setting
8+
from ci_tools.variables import in_public
89
import os
910
from typing import Any
1011

@@ -42,6 +43,7 @@ def is_check_enabled(package_path: str, check: str, default: Any = True) -> bool
4243
In order:
4344
- Checks <CHECK>_OPT_OUT for package name.
4445
- Honors override variable if one is present: <PACKAGE_NAME>_<CHECK>. (Note the _ in the package name, `-` is not a valid env variable character.)
46+
- Checks for `ci_enabled` flag in pyproject.toml and skips all checks if set to false.
4547
- Finally falls back to the pyproject.toml at package root (if one exists) for a tools setting enabling/disabling <check>.
4648
"""
4749
if package_path.endswith("setup.py"):
@@ -50,6 +52,10 @@ def is_check_enabled(package_path: str, check: str, default: Any = True) -> bool
5052
if package_path == ".":
5153
package_path = os.getcwd()
5254

55+
ci_enabled = get_config_setting(package_path, "ci_enabled", default)
56+
if not in_public() and ci_enabled is False:
57+
return False
58+
5359
# now pull the new pyproject.toml configuration
5460
config = get_config_setting(package_path, check.strip().lower(), default)
5561

tools/azure-sdk-tools/ci_tools/variables.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,14 @@ def in_ci() -> int:
5959
return 0
6060

6161

62+
def in_public() -> int:
63+
# Returns 3 if the build originates from a pull request
64+
# 0 otherwise
65+
if os.getenv("BUILD_REASON") == "PullRequest" or os.getenv("GITHUB_EVENT_NAME") == "pull_request":
66+
return 3
67+
68+
return 0
69+
70+
6271
DEV_BUILD_IDENTIFIER = os.getenv("SDK_DEV_BUILD_IDENTIFIER", "a")
6372
DEFAULT_BUILD_ID = os.getenv("GITHUB_RUN_ID", os.getenv("BUILD.BUILDID", os.getenv("SDK_BUILD_ID", "20220101.1")))

0 commit comments

Comments
 (0)