check_artifacts_expire_time.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. try:
  7. from yaml import CLoader as Loader
  8. except ImportError:
  9. from yaml import Loader as Loader
  10. IDF_PATH = os.getenv("IDF_PATH")
  11. if not IDF_PATH:
  12. print("Please set IDF_PATH before running this script")
  13. raise SystemExit(-1)
  14. GITLAB_CONFIG_FILE = os.path.join(os.getenv("IDF_PATH"), ".gitlab-ci.yml")
  15. def check_artifacts_expire_time():
  16. with open(GITLAB_CONFIG_FILE, "r") as f:
  17. config = yaml.load(f, Loader=Loader)
  18. errors = []
  19. print("expire time for jobs:")
  20. job_names = list(config.keys())
  21. job_names.sort()
  22. for job_name in job_names:
  23. if job_name.startswith("."):
  24. # skip ignored jobs
  25. continue
  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()