Files
esp-idf/tools/ci/check_artifacts_expire_time.py
T

55 lines
1.5 KiB
Python
Raw Normal View History

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