1
0
Fork 0
mirror of https://github.com/MillironX/nf-configs.git synced 2024-12-04 20:49:54 +00:00
nf-configs/bin/cchecker.py

76 lines
2.6 KiB
Python
Raw Normal View History

2019-11-26 12:57:32 +00:00
#!/usr/bin/env python
#######################################################################
#######################################################################
## Created on November 26 to check pipeline configs for nf-core/configs
#######################################################################
#######################################################################
import os
import sys
import argparse
import re
2021-07-03 12:52:44 +00:00
import yaml
2019-11-26 12:57:32 +00:00
############################################
############################################
## PARSE ARGUMENTS
############################################
############################################
Description = 'Double check custom config file and github actions file to test all cases'
Epilog = """Example usage: python cchecker.py <nfcore_custom.config> <github_actions_file>"""
argParser = argparse.ArgumentParser(description=Description, epilog=Epilog)
## REQUIRED PARAMETERS
argParser.add_argument('CUSTOM_CONFIG', help="Input nfcore_custom.config.")
argParser.add_argument('GITHUB_CONFIG', help="Input Github Actions YAML")
args = argParser.parse_args()
############################################
############################################
## MAIN FUNCTION
############################################
############################################
def check_config(Config, Github):
regex = 'includeConfig*'
ERROR_STR = 'ERROR: Please check config file! Did you really update the profiles?'
## CHECK Config First
config_profiles = set()
with open(Config, 'r') as cfg:
for line in cfg:
if re.search(regex, line):
hit = line.split('/')[2].split('.')[0]
2019-11-26 13:04:58 +00:00
config_profiles.add(hit.strip())
### Check Github Config now
2019-11-26 12:57:32 +00:00
tests = set()
### Ignore these profiles
ignore_me = ['czbiohub_aws']
2019-11-26 13:38:57 +00:00
tests.update(ignore_me)
2021-07-03 12:52:44 +00:00
# parse yaml GitHub actions file
try:
with open(Github, 'r') as ghfile:
wf = yaml.safe_load(ghfile)
2021-07-03 13:11:51 +00:00
profile_list = wf["jobs"]["profile_test"]["strategy"]["matrix"]["profile"]
2021-07-03 12:52:44 +00:00
except Exception as e:
2021-07-03 13:09:43 +00:00
print("Could not parse yaml file: {}, {}".format(Github, e))
sys.exit(1)
2021-07-03 12:52:44 +00:00
# Add profiles to test
for profile in profile_list:
tests.add(profile.strip())
2019-11-26 12:57:32 +00:00
###Check if sets are equal
2021-07-03 13:09:43 +00:00
try:
assert tests == config_profiles
except (AssertionError):
2019-11-26 14:12:42 +00:00
print("Tests don't seem to test these profiles properly. Please check whether you added the profile to the Github Actions testing YAML.\n")
2019-11-26 13:04:58 +00:00
print(config_profiles.symmetric_difference(tests))
2019-11-26 12:57:32 +00:00
sys.exit(1)
check_config(Config=args.CUSTOM_CONFIG,Github=args.GITHUB_CONFIG)