From a6e7c6e7ee26155d63597b651e2495e05155b149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Fri, 15 May 2020 16:35:11 -0400 Subject: [PATCH] ensure all github projects have correct template Ensure all the projects depend on `system-required` template. Consequently, correct `amazon.aws` and `ansible-bender` configuration. - `amazon.aws`: adjust the location of the repo and the default branch - `ansible-blender`: use `system-required` template Also, improve `zuul-projects-checks.py` to cover this case. - Depends on Python3 and use pathlib because it's 2020! - ensure github projects have consistent templates --- tools/zuul-projects-checks.py | 53 +++++++++++++++++++++++++++++++---- zuul.d/projects.yaml | 13 ++++----- 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/tools/zuul-projects-checks.py b/tools/zuul-projects-checks.py index da9d16e6..68a1ad5e 100755 --- a/tools/zuul-projects-checks.py +++ b/tools/zuul-projects-checks.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Copyright 2017 SUSE Linux GmbH # @@ -14,11 +14,14 @@ # See the License for the specific language governing permissions and # limitations under the License. +from pathlib import Path +import re import sys import yaml -projects_yaml = 'zuul.d/projects.yaml' -projects = yaml.safe_load(open(projects_yaml)) +tenants = yaml.safe_load(Path("zuul/tenants.yaml").read_text()) +projects = yaml.safe_load(Path("zuul.d/projects.yaml").read_text()) +ansible_tenant = tenants[0]["tenant"] def normalize(s): @@ -170,6 +173,45 @@ def check_only_boilerplate(): return errors +def check_project_templates(): + + print("\nChecking that every project has entries") + print("======================") + + untrusted_github_projects = ansible_tenant["source"]["github.com"][ + "untrusted-projects" + ] + github_projects = [ + "github.com/" + i for i in untrusted_github_projects if type(i) == str + ] + + errors = False + for github_project in github_projects: + templates = [] + for project in [i["project"] for i in projects]: + name = project["name"] + if name.startswith("^") and re.match(name, github_project): + templates += project.get("templates", []) + elif github_project == name: + templates += project.get("templates", []) + if not templates: + print( + "No template for project {github_project}".format( + github_project=github_project + ) + ) + errors = True + if "system-required" not in templates: + print( + ( + "system-required template not enabled for " + "{github_project}" + ).format(github_project=github_project) + ) + errors = True + return errors + + def check_all(): errors = check_projects_sorted() @@ -177,11 +219,12 @@ def check_all(): errors = check_release_jobs() or errors errors = check_voting() or errors errors = check_only_boilerplate() or errors + errors = check_project_templates() or errors if errors: - print("\nFound errors in zuul.d/projects.yaml!\n") + print("\nFound errors in zuul configuration!\n") else: - print("\nNo errors found in zuul.d/projects.yaml!\n") + print("\nNo errors found in zuul configuration!\n") return errors diff --git a/zuul.d/projects.yaml b/zuul.d/projects.yaml index 1b7c1b50..d559b191 100644 --- a/zuul.d/projects.yaml +++ b/zuul.d/projects.yaml @@ -6,6 +6,11 @@ templates: - system-required +- project: + name: github.com/ansible-collections/amazon.aws + templates: + - system-required + - project: name: github.com/ansible-collections/ansible.netcommon templates: @@ -164,7 +169,7 @@ - project: name: github.com/ansible-community/ansible-bender templates: - - noop-jobs + - system-required - project: name: github.com/ansible-community/molecule @@ -256,12 +261,6 @@ templates: - ansible-python-jobs -- project: - name: github.com/ansible-network/aws - default-branch: devel - templates: - - noop-jobs - - project: name: github.com/ansible-network/azure default-branch: devel