def validate()

in asfyaml/cli.py [0:0]


def validate():
    """Validates a .asf.yaml file according to the current schema."""
    parser = argparse.ArgumentParser()
    parser.add_argument("--repo", type=dir_path, help="path to the repo to process", required=True)
    parser.add_argument("--org", type=str, default="apache", help="the organization this repo belongs to")
    args = parser.parse_args()

    repo_path = Path(os.path.abspath(args.repo))
    repo = dataobjects.Repository(str(repo_path), org_id=args.org)

    yml_file = os.path.join(repo_path, ".asf.yaml")
    if not os.path.exists(yml_file):
        raise Exception(f".asf.yaml does not exist at location '{yml_file}'")

    with open(yml_file, mode="r") as f:
        yml_content = f.read()

    os.environ["PATH_INFO"] = repo_path.name
    os.environ["GIT_PROJECT_ROOT"] = str(repo_path.parent)

    a = ASFYamlInstance(repo, "anonymous", yml_content, dataobjects.DEFAULT_BRANCH)

    a.environments_enabled.add("production")

    try:
        a.run_parts(validate_only=True)
        print(f"{yml_file} is a valid .asf.yaml file.")
    except ASFYAMLException as err:
        print(err.error_message)