import json from git import Repo import os import shutil import logging logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s' ) DOCS_PATH = '../docs/' def get_registry(filename): """Reads registry into dictionary. Params: filename (str): The filename. Returns: dict: json object """ return json.loads(open(filename).read()) def get_repo_doc(repo_name, app_name, path): try: github_token = os.getenv("GITHUB_TOKEN") repo_url = f'https://{github_token}@github.com/{repo_name}.git' if github_token \ else f'https://github.com/{repo_name}.git' logging.info(f"Cloning repository: {repo_url}") Repo.clone_from(repo_url, app_name) logging.info(f"Copying documentation file from {app_name}/{path} to {DOCS_PATH}{app_name}") shutil.copyfile(f"{app_name}/{path}", f"{DOCS_PATH}{app_name}") logging.info(f"Cleaning up temporary directory: {app_name}") shutil.rmtree(app_name) except Exception as e: logging.error(f"Error processing {app_name}: {str(e)}") raise try: registry = get_registry('../registry.json') for doc in registry: repo_name = doc.get('repo') app_name = doc.get('name') path = doc.get('path') logging.info(f"Processing documentation for {app_name}") get_repo_doc(repo_name, app_name, path) except Exception as e: logging.error(f"Failed to process registry: {str(e)}") raise # Temp change to debug the missing spec files in the built image. logging.info(f"CWD: {os.getcwd()} -> {os.path.abspath(DOCS_PATH)}") logging.info(f"Docs dir contents: {os.listdir(DOCS_PATH)}")