check_artifacts_expire_time.py
1 #!/usr/bin/env python 2 3 # internal use only 4 # check if expire time is set for all artifacts 5 6 import os 7 8 import yaml 9 10 try: 11 from yaml import CLoader as Loader 12 except ImportError: 13 from yaml import Loader as Loader 14 15 IDF_PATH = os.getenv("IDF_PATH") 16 if not IDF_PATH: 17 print("Please set IDF_PATH before running this script") 18 raise SystemExit(-1) 19 20 GITLAB_CONFIG_FILE = os.path.join(os.getenv("IDF_PATH"), ".gitlab-ci.yml") 21 22 23 def check_artifacts_expire_time(): 24 with open(GITLAB_CONFIG_FILE, "r") as f: 25 config = yaml.load(f, Loader=Loader) 26 27 errors = [] 28 29 print("expire time for jobs:") 30 31 job_names = list(config.keys()) 32 job_names.sort() 33 34 for job_name in job_names: 35 36 if job_name.startswith("."): 37 # skip ignored jobs 38 continue 39 40 try: 41 if "expire_in" not in config[job_name]["artifacts"]: 42 errors.append(job_name) 43 else: 44 print("{}: {}".format(job_name, config[job_name]["artifacts"]["expire_in"])) 45 except (KeyError, TypeError): 46 # this is not job, or the job does not have artifacts 47 pass 48 49 if errors: 50 print("\n\nThe following jobs did not set expire time for its artifacts") 51 for error in errors: 52 print(error) 53 raise SystemExit(-2) 54 55 56 if __name__ == '__main__': 57 check_artifacts_expire_time()