fix: updated the unit tests workflow to simplify job names and read test paths from a separate file (#29472)

This commit is contained in:
Aarif
2021-12-09 18:21:17 +05:00
committed by GitHub
parent 472ccdabe0
commit 76a8aaf6cd
10 changed files with 79 additions and 33 deletions

View File

@@ -2,24 +2,25 @@ import sys
import os
import yaml
import argparse
import json
def get_all_unit_test_modules():
unit_tests_yml = f'{os.getcwd()}/.github/workflows/unit-tests.yml'
with open(unit_tests_yml) as file:
unit_test_workflow_yaml = yaml.safe_load(file)
def get_all_unit_test_shards():
unit_tests_json = f'{os.getcwd()}/.github/workflows/unit-test-shards.json'
with open(unit_tests_json) as file:
unit_test_workflow_shards = json.loads(file.read())
return unit_test_workflow_yaml['jobs']['run-tests']['strategy']['matrix']['test_module']
return unit_test_workflow_shards
def get_modules_except_cms():
all_unit_test_modules = get_all_unit_test_modules()
return [module for module in all_unit_test_modules if not module.startswith('cms')]
all_unit_test_shards = get_all_unit_test_shards()
return [paths for shard_name, paths in all_unit_test_shards.items() if not paths.startswith('cms')]
def get_cms_modules():
all_unit_test_modules = get_all_unit_test_modules()
return [module for module in all_unit_test_modules if module.startswith('cms')]
all_unit_test_shards = get_all_unit_test_shards()
return [paths for shard_name, paths in all_unit_test_shards.items() if paths.startswith('cms')]
if __name__ == "__main__":

View File

@@ -0,0 +1,27 @@
import sys
import os
import argparse
import json
def get_test_paths_for_shard(shard_name):
unit_tests_json = f'{os.getcwd()}/.github/workflows/unit-test-shards.json'
with open(unit_tests_json) as file:
unit_test_workflow_shards = json.loads(file.read())
if shard_name not in unit_test_workflow_shards:
sys.stdout.write("Error, invalid shard name provided. please provide a valid shard name as specified in unit-test-shards.json")
return unit_test_workflow_shards.get(shard_name)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--shard-name", action="store", default="")
argument = parser.parse_args()
if not argument.shard_name:
sys.stdout.write("Error, no shard name provided. please provide a valid shard name as specified in unit-test-shards.json")
unit_test_paths = get_test_paths_for_shard(argument.shard_name)
sys.stdout.write(unit_test_paths)