check_artifacts_expire_time.py 1.5 KB

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