check_artifacts_expire_time.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env python
  2. # internal use only
  3. # check if expire time is set for all artifacts
  4. import os
  5. import yaml
  6. IDF_PATH = os.getenv('IDF_PATH')
  7. if not IDF_PATH:
  8. print('Please set IDF_PATH before running this script')
  9. raise SystemExit(-1)
  10. GITLAB_CONFIG_FILE = os.path.join(IDF_PATH, '.gitlab-ci.yml')
  11. def check_artifacts_expire_time():
  12. with open(GITLAB_CONFIG_FILE, 'r') as f:
  13. config = yaml.load(f, Loader=yaml.FullLoader)
  14. # load files listed in `include`
  15. if 'include' in config:
  16. for _file in config['include']:
  17. with open(os.path.join(IDF_PATH, _file)) as f:
  18. config.update(yaml.load(f, Loader=yaml.FullLoader))
  19. print('expire time for jobs:')
  20. errors = []
  21. job_names = list(config.keys())
  22. job_names.sort()
  23. for job_name in job_names:
  24. try:
  25. if 'expire_in' not in config[job_name]['artifacts']:
  26. errors.append(job_name)
  27. else:
  28. print('{}: {}'.format(job_name, config[job_name]['artifacts']['expire_in']))
  29. except (KeyError, TypeError):
  30. # this is not job, or the job does not have artifacts
  31. pass
  32. if errors:
  33. print('\n\nThe following jobs did not set expire time for its artifacts')
  34. for error in errors:
  35. print(error)
  36. raise SystemExit(-2)
  37. if __name__ == '__main__':
  38. check_artifacts_expire_time()