From 890102cede6008ff69787cebfe70124bb315024b Mon Sep 17 00:00:00 2001 From: Lachee Date: Wed, 7 May 2025 15:42:25 +1000 Subject: [PATCH] updated readme script --- .gitea/workflows/update-readme.yaml | 87 +---------------------------- scripts/build-readme.py | 83 +++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 86 deletions(-) create mode 100644 scripts/build-readme.py diff --git a/.gitea/workflows/update-readme.yaml b/.gitea/workflows/update-readme.yaml index 34b4d34..10da0e7 100644 --- a/.gitea/workflows/update-readme.yaml +++ b/.gitea/workflows/update-readme.yaml @@ -30,92 +30,7 @@ jobs: password: ${{ secrets.DOCKER_PASSWORD }} - name: Generate Docker Images Table - run: | - python -c ' - import docker - import re - import os - from collections import defaultdict - - # Connect to Docker registry - client = docker.from_env() - client.login( - username=os.environ["DOCKER_USERNAME"], - password=os.environ["DOCKER_PASSWORD"], - registry="docker.lakes.house" - ) - - # Define the base repository - base_repo = "docker.lakes.house/unityci/editor" - - # Get all images - images = [] - try: - # For a real registry we would use the client.images.search, but for private registry - # we need to list tags for the repository - # This might require API calls specific to your registry - # For this example, we assume we can get a list of tags - response = client.api.get_registry_data(base_repo) - for tag in response.get("tags", []): - images.append(f"{base_repo}:{tag}") - except Exception as e: - print(f"Error listing images: {e}") - # Fallback approach or error handling - - # Process images to extract Unity versions and platforms - unity_platforms = defaultdict(set) - image_map = defaultdict(dict) - - pattern = re.compile(r"ubuntu-(\d+\.\d+\.\d+\w*)-(\w+)-runner") - - for image in images: - match = pattern.search(image) - if match: - unity_version = match.group(1) - platform = match.group(2) - unity_platforms[unity_version].add(platform) - image_map[unity_version][platform] = image - - # Get all unique platforms - all_platforms = set() - for platforms in unity_platforms.values(): - all_platforms.update(platforms) - all_platforms = sorted(list(all_platforms)) - - # Generate markdown table - markdown = "# Unity Docker Images\n\n" - markdown += "A table of available Docker images for Unity CI/CD:\n\n" - markdown += "| Unity Version |" - - # Add platform headers - for platform in all_platforms: - markdown += f" {platform} |" - markdown += "\n|" - - # Add separator row - for _ in range(len(all_platforms) + 1): - markdown += " --- |" - markdown += "\n" - - # Add rows for each Unity version - for unity_version in sorted(unity_platforms.keys()): - markdown += f"| {unity_version} |" - - for platform in all_platforms: - if platform in image_map[unity_version]: - image_name = image_map[unity_version][platform].split("/")[-1] - markdown += f" `{image_name}` |" - else: - markdown += " - |" - - markdown += "\n" - - # Write to README.md - with open("README.md", "w") as f: - f.write(markdown) - - print("README updated successfully!") - ' + run: python scripts/build-readme.py - name: Commit changes if README was updated run: | diff --git a/scripts/build-readme.py b/scripts/build-readme.py new file mode 100644 index 0000000..60eb879 --- /dev/null +++ b/scripts/build-readme.py @@ -0,0 +1,83 @@ +import docker +import re +import os +from collections import defaultdict + +# Connect to Docker registry +client = docker.from_env() +client.login( + username=os.environ["DOCKER_USERNAME"], + password=os.environ["DOCKER_PASSWORD"], + registry="docker.lakes.house" +) + +# Define the base repository +base_repo = "docker.lakes.house/unityci/editor" + +# Get all images +images = [] +try: + # For a real registry we would use the client.images.search, but for private registry + # we need to list tags for the repository + # This might require API calls specific to your registry + # For this example, we assume we can get a list of tags + response = client.api.get_registry_data(base_repo) + for tag in response.get("tags", []): + images.append(f"{base_repo}:{tag}") +except Exception as e: + print(f"Error listing images: {e}") + # Fallback approach or error handling + +# Process images to extract Unity versions and platforms +unity_platforms = defaultdict(set) +image_map = defaultdict(dict) + +pattern = re.compile(r"ubuntu-(\d+\.\d+\.\d+\w*)-(\w+)-runner") + +for image in images: + match = pattern.search(image) + if match: + unity_version = match.group(1) + platform = match.group(2) + unity_platforms[unity_version].add(platform) + image_map[unity_version][platform] = image + +# Get all unique platforms +all_platforms = set() +for platforms in unity_platforms.values(): + all_platforms.update(platforms) +all_platforms = sorted(list(all_platforms)) + +# Generate markdown table +markdown = "# Unity Docker Images\n\n" +markdown += "A table of available Docker images for Unity CI/CD:\n\n" +markdown += "| Unity Version |" + +# Add platform headers +for platform in all_platforms: + markdown += f" {platform} |" +markdown += "\n|" + +# Add separator row +for _ in range(len(all_platforms) + 1): + markdown += " --- |" +markdown += "\n" + +# Add rows for each Unity version +for unity_version in sorted(unity_platforms.keys()): + markdown += f"| {unity_version} |" + + for platform in all_platforms: + if platform in image_map[unity_version]: + image_name = image_map[unity_version][platform].split("/")[-1] + markdown += f" `{image_name}` |" + else: + markdown += " - |" + + markdown += "\n" + +# Write to README.md +with open("README.md", "w") as f: + f.write(markdown) + +print("README updated successfully!") \ No newline at end of file