ci: optimize downloading build_ssc artifacts

This commit is contained in:
Chen Yudong 2022-01-06 23:33:08 +08:00
parent dd4f27801f
commit ec4175b127
2 changed files with 70 additions and 1 deletions

View File

@ -872,7 +872,6 @@ UT_S3_FLASH:
- .before_script_minimal
needs:
- assign_integration_test
- build_ssc_esp32
variables:
LOCAL_ENV_CONFIG_PATH: "$CI_PROJECT_DIR/ci-test-runner-configs/$CI_RUNNER_DESCRIPTION/ESP32_IDF"
LOG_PATH: "${CI_PROJECT_DIR}/TEST_LOGS"
@ -880,6 +879,7 @@ UT_S3_FLASH:
MODULE_UPDATE_FILE: "$CI_PROJECT_DIR/components/idf_test/ModuleDefinition.yml"
CONFIG_FILE_PATH: "${CI_PROJECT_DIR}/tools/ci/integration_test/test_configs"
KNOWN_ISSUE_FILE: "${CI_PROJECT_DIR}/tools/ci/integration_test/KnownIssues"
PREPARE_TEST_BIN_SCRIPT: "${CI_PROJECT_DIR}/tools/ci/integration_test/prepare_test_bins.py"
CI_RUNNER_SCRIPT: "${CI_PROJECT_DIR}/auto_test_script/bin/CIRunner.py"
PYTHONPATH: ${CI_PROJECT_DIR}/auto_test_script/packages
# auto_test_script only supports python 3.7.x
@ -902,6 +902,7 @@ UT_S3_FLASH:
- python $CHECKOUT_REF_SCRIPT auto_test_script auto_test_script --customized_only
- cat ${KNOWN_ISSUE_FILE} >> ${TEST_CASE_FILE_PATH}/KnownIssues
# run test
- python ${PREPARE_TEST_BIN_SCRIPT} $CONFIG_FILE
- python ${CI_RUNNER_SCRIPT} -l "$LOG_PATH/$JOB_FULL_NAME" -c $CONFIG_FILE -e $LOCAL_ENV_CONFIG_PATH -t $TEST_CASE_FILE_PATH
nvs_compatible_test:
@ -935,6 +936,7 @@ nvs_compatible_test:
- cd auto_test_script
- ./tools/prepare_nvs_bin.sh
# run test
- python ${PREPARE_TEST_BIN_SCRIPT} $CONFIG_FILE
- python ${CI_RUNNER_SCRIPT} -l "$LOG_PATH/$JOB_FULL_NAME" -c $CONFIG_FILE -e $LOCAL_ENV_CONFIG_PATH -t $TEST_CASE_FILE_PATH
IT_001:

View File

@ -0,0 +1,67 @@
#!/usr/bin/env python
#
# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
import argparse
import os
import gitlab
import gitlab_api
from AutoTestScript.RunnerConfigs.Config import Config
SSC_BUILD_JOB_MAP = {
'ESP32': 'build_ssc_esp32',
'ESP32C3': 'build_ssc_esp32c3',
}
NEEDED_FILES = [
'flasher_args.json',
'bootloader/bootloader.bin',
'partition_table/partition-table.bin',
'ssc.bin',
'ssc.elf',
]
IDF_PATH = os.environ.get('IDF_PATH')
def try_to_download_artifacts(bin_path: str) -> None:
'''
bin_path: "SSC/ssc_bin/ESP32[C3]/SSC[_APP]"
'''
project_id = os.getenv('CI_PROJECT_ID')
pipeline_id = os.getenv('CI_PIPELINE_ID')
gitlab_inst = gitlab_api.Gitlab(project_id)
build_job_name = SSC_BUILD_JOB_MAP[bin_path.split('/')[-2]]
job_list = gitlab_inst.find_job_id(build_job_name, pipeline_id=pipeline_id)
files_to_download = [os.path.join(bin_path, f) for f in NEEDED_FILES]
for job_info in job_list:
try:
gitlab_inst.download_artifact(job_info['id'], files_to_download, IDF_PATH)
print('Downloaded {} from {}'.format(bin_path, job_info['id']))
break
except gitlab.exceptions.GitlabError as e:
if e.response_code == 404:
continue
raise
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument(
'test_config_file',
help='The test config file to be used.'
)
args = parser.parse_args()
configs = Config.parse(args.test_config_file)
test_bin_paths = configs.get_bin_paths()
for _path in test_bin_paths:
if os.path.exists(_path):
continue
relative_path = os.path.relpath(_path, IDF_PATH)
try_to_download_artifacts(relative_path)
if __name__ == '__main__':
main()