File: verify_ci_enabled.py

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (50 lines) | stat: -rw-r--r-- 1,856 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/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
import sys
import os

from ci_tools.environment_exclusions import get_config_setting

root_dir = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", ".."))

def verify_ci_enabled(package_name: str, package_path: str) -> None:
    """Verifies that ci_enabled=false is not present in the package's pyproject.toml.
    This prevents releasing packages that have disabled their CI.
    """

    ci_enabled = get_config_setting(package_path, "ci_enabled")
    if ci_enabled is False:
        print(
            f"ci_enabled is set to false in {package_name}/pyproject.toml. " \
            "You must remove this setting before releasing the package."
        )
        sys.exit(1)


if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="Verifies ci_enabled=true or is not present in the package's pyproject.toml, Called from DevOps YAML Pipeline"
    )

    parser.add_argument(
        "--package-name",
        required=True,
        help="name of package (accepts both formats: azure-service-package and azure_service_package)",
    )
    parser.add_argument(
        "--service",
        required=True,
        help="name of the service for which to set the dev build id (e.g. keyvault)",
    )

    args = parser.parse_args()

    package_name = args.package_name.replace("_", "-")
    path_to_setup = os.path.join(root_dir, "sdk", args.service, package_name, "setup.py")
    verify_ci_enabled(package_name, path_to_setup)