2018-09-20 08:11:54 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# internal use only
|
|
|
|
# check if expire time is set for all artifacts
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
import yaml
|
|
|
|
|
2021-01-26 02:49:01 +00:00
|
|
|
IDF_PATH = os.getenv('IDF_PATH')
|
2018-09-20 08:11:54 +00:00
|
|
|
if not IDF_PATH:
|
2021-01-26 02:49:01 +00:00
|
|
|
print('Please set IDF_PATH before running this script')
|
2018-09-20 08:11:54 +00:00
|
|
|
raise SystemExit(-1)
|
|
|
|
|
2022-02-09 10:00:54 +00:00
|
|
|
GITLAB_CONFIG_FILE = os.path.join(IDF_PATH, '.gitlab-ci.yml')
|
2018-09-20 08:11:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
def check_artifacts_expire_time():
|
2021-01-26 02:49:01 +00:00
|
|
|
with open(GITLAB_CONFIG_FILE, 'r') as f:
|
2022-02-09 10:00:54 +00:00
|
|
|
config = yaml.load(f, Loader=yaml.FullLoader)
|
2018-09-20 08:11:54 +00:00
|
|
|
|
2022-02-09 10:00:54 +00:00
|
|
|
# load files listed in `include`
|
|
|
|
if 'include' in config:
|
|
|
|
for _file in config['include']:
|
|
|
|
with open(os.path.join(IDF_PATH, _file)) as f:
|
|
|
|
config.update(yaml.load(f, Loader=yaml.FullLoader))
|
2018-09-20 08:11:54 +00:00
|
|
|
|
2021-01-26 02:49:01 +00:00
|
|
|
print('expire time for jobs:')
|
2022-02-09 10:00:54 +00:00
|
|
|
errors = []
|
2018-09-20 08:11:54 +00:00
|
|
|
|
2018-10-10 11:19:31 +00:00
|
|
|
job_names = list(config.keys())
|
2018-09-20 08:11:54 +00:00
|
|
|
job_names.sort()
|
|
|
|
|
|
|
|
for job_name in job_names:
|
|
|
|
try:
|
2021-01-26 02:49:01 +00:00
|
|
|
if 'expire_in' not in config[job_name]['artifacts']:
|
2018-09-20 08:11:54 +00:00
|
|
|
errors.append(job_name)
|
|
|
|
else:
|
2021-01-26 02:49:01 +00:00
|
|
|
print('{}: {}'.format(job_name, config[job_name]['artifacts']['expire_in']))
|
2018-09-20 08:11:54 +00:00
|
|
|
except (KeyError, TypeError):
|
|
|
|
# this is not job, or the job does not have artifacts
|
|
|
|
pass
|
|
|
|
|
|
|
|
if errors:
|
2021-01-26 02:49:01 +00:00
|
|
|
print('\n\nThe following jobs did not set expire time for its artifacts')
|
2018-09-20 08:11:54 +00:00
|
|
|
for error in errors:
|
|
|
|
print(error)
|
|
|
|
raise SystemExit(-2)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
check_artifacts_expire_time()
|