Created
May 21, 2023 14:05
-
-
Save kevinAlbs/f6e45a6f9cbc16f95f87d2b789abb516 to your computer and use it in GitHub Desktop.
Validate that all tasks in an Evergreen config are used.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import yaml | |
try: | |
from yaml import CLoader as Loader | |
except ImportError: | |
from yaml import Loader | |
# Load evaluated Evergreen config. | |
# `evaluated.yml` was created by running: `evergreen evaluate ./.evergreen/config.yml > evaluated.yml` | |
with open("evaluated.yml", "r") as file: | |
config = yaml.load(file, Loader=Loader) | |
tasks = set() | |
# Load `tasks` section. | |
for task in config["tasks"]: | |
task_name = task["name"] | |
tasks.add (task_name) | |
# Load `buildvariants` section. | |
buildvariant_tasks = set() | |
for buildvariant in config["buildvariants"]: | |
for task in buildvariant["tasks"]: | |
if type(task) == str: | |
buildvariant_tasks.add(task) | |
continue | |
buildvariant_tasks.add(task["name"]) | |
# Load `task_groups` tasks. | |
task_groups_tasks = set() | |
for task_group in config["task_groups"]: | |
for task in task_group["tasks"]: | |
if type(task) == str: | |
task_groups_tasks.add(task) | |
continue | |
task_groups_tasks.add(task["name"]) | |
nonreferenced_tasks = tasks.difference (buildvariant_tasks, task_groups_tasks) | |
nonreferenced_tasks = list(nonreferenced_tasks) | |
nonreferenced_tasks.sort() | |
if len(nonreferenced_tasks) > 0: | |
print ("Error") | |
print ("`tasks` not referenced in `buildvariants` or `task_groups`:\n-{}".format("\n-".join(nonreferenced_tasks))) | |
sys.exit(1) | |
print ("OK. All `tasks` referenced") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment