From 432c5a783d761d60c013b50b8c4f3d6b773a09b2 Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Tue, 23 Jan 2024 12:11:07 +0100 Subject: [PATCH] ci: gitlab auth failing hint --- conftest.py | 18 +--------------- tools/ci/python_packages/gitlab_api.py | 29 ++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/conftest.py b/conftest.py index 06699f2e6a..16ae426d22 100644 --- a/conftest.py +++ b/conftest.py @@ -11,8 +11,6 @@ import os import sys -import gitlab - if os.path.join(os.path.dirname(__file__), 'tools', 'ci') not in sys.path: sys.path.append(os.path.join(os.path.dirname(__file__), 'tools', 'ci')) @@ -161,22 +159,8 @@ def app_downloader(pipeline_id: t.Optional[str]) -> t.Optional[AppDownloader]: logging.info('Downloading build report from the build pipeline %s', pipeline_id) test_app_presigned_urls_file = None - try: - gl = gitlab_api.Gitlab(os.getenv('CI_PROJECT_ID', 'espressif/esp-idf')) - except gitlab.exceptions.GitlabAuthenticationError: - msg = """To download artifacts from gitlab, please create ~/.python-gitlab.cfg with the following content: -[global] -default = internal -ssl_verify = true -timeout = 5 - -[internal] -url = -private_token = -api_version = 4 -""" - raise SystemExit(msg) + gl = gitlab_api.Gitlab(os.getenv('CI_PROJECT_ID', 'espressif/esp-idf')) for child_pipeline in gl.project.pipelines.get(pipeline_id, lazy=True).bridges.list(iterator=True): if child_pipeline.name == 'build_child_pipeline': diff --git a/tools/ci/python_packages/gitlab_api.py b/tools/ci/python_packages/gitlab_api.py index 32652ec3b4..1bffbef372 100644 --- a/tools/ci/python_packages/gitlab_api.py +++ b/tools/ci/python_packages/gitlab_api.py @@ -1,6 +1,5 @@ -# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Apache-2.0 - import argparse import logging import os @@ -11,7 +10,12 @@ import tempfile import time import zipfile from functools import wraps -from typing import Any, Callable, Dict, List, Optional, Union +from typing import Any +from typing import Callable +from typing import Dict +from typing import List +from typing import Optional +from typing import Union import gitlab @@ -80,7 +84,24 @@ class Gitlab(object): def _init_gitlab_inst(self, project_id: Optional[int], config_files: Optional[List[str]]) -> None: gitlab_id = os.getenv('LOCAL_GITLAB_HTTPS_HOST') # if None, will use the default gitlab server self.gitlab_inst = gitlab.Gitlab.from_config(gitlab_id=gitlab_id, config_files=config_files) - self.gitlab_inst.auth() + + try: + self.gitlab_inst.auth() + except gitlab.exceptions.GitlabAuthenticationError: + msg = """To call gitlab apis locally, please create ~/.python-gitlab.cfg with the following content: + + [global] + default = internal + ssl_verify = true + timeout = 5 + + [internal] + url = + private_token = + api_version = 4 + """ + raise SystemExit(msg) + if project_id: self.project = self.gitlab_inst.projects.get(project_id, lazy=True) else: