prepare_test_bins.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env python
  2. #
  3. # SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
  4. # SPDX-License-Identifier: Apache-2.0
  5. import argparse
  6. import os
  7. import gitlab
  8. import gitlab_api
  9. from AutoTestScript.RunnerConfigs.Config import Config
  10. SSC_BUILD_JOB_MAP = {
  11. 'ESP32': 'build_ssc_esp32',
  12. 'ESP32C3': 'build_ssc_esp32c3',
  13. }
  14. NEEDED_FILES = [
  15. 'flasher_args.json',
  16. 'bootloader/bootloader.bin',
  17. 'partition_table/partition-table.bin',
  18. 'ssc.bin',
  19. 'ssc.elf',
  20. ]
  21. IDF_PATH = os.environ.get('IDF_PATH')
  22. def try_to_download_artifacts(bin_path: str) -> None:
  23. '''
  24. bin_path: "SSC/ssc_bin/ESP32[C3]/SSC[_APP]"
  25. '''
  26. project_id = os.getenv('CI_PROJECT_ID')
  27. pipeline_id = os.getenv('CI_PIPELINE_ID')
  28. gitlab_inst = gitlab_api.Gitlab(project_id)
  29. build_job_name = SSC_BUILD_JOB_MAP[bin_path.split('/')[-2]]
  30. job_list = gitlab_inst.find_job_id(build_job_name, pipeline_id=pipeline_id)
  31. files_to_download = [os.path.join(bin_path, f) for f in NEEDED_FILES]
  32. for job_info in job_list:
  33. try:
  34. gitlab_inst.download_artifact(job_info['id'], files_to_download, IDF_PATH)
  35. print('Downloaded {} from {}'.format(bin_path, job_info['id']))
  36. break
  37. except gitlab.exceptions.GitlabError as e:
  38. if e.response_code == 404:
  39. continue
  40. raise
  41. def main() -> None:
  42. parser = argparse.ArgumentParser()
  43. parser.add_argument(
  44. 'test_config_file',
  45. help='The test config file to be used.'
  46. )
  47. args = parser.parse_args()
  48. configs = Config.parse(args.test_config_file)
  49. test_bin_paths = configs.get_bin_paths()
  50. for _path in test_bin_paths:
  51. if os.path.exists(_path):
  52. continue
  53. relative_path = os.path.relpath(_path, IDF_PATH)
  54. try_to_download_artifacts(relative_path)
  55. if __name__ == '__main__':
  56. main()