diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7f5b0484a0..fc2df280f0 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -28,6 +28,7 @@ jobs: run: make import - name: Generate newer usage graphs + continue-on-error: true run: | pip3 install click requests pygal python3 files/generate_usage.py diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 549ebdb9a4..aa06ea7849 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -19,11 +19,6 @@ jobs: - name: Import the nested docs run: make import - - name: Generate newer usage graphs - run: | - pip3 install click requests pygal - python3 files/generate_usage.py - - name: Install dependencies run: yarn install --frozen-lockfile - name: Test build website diff --git a/files/generate_usage.py b/files/generate_usage.py index ba6c06a4b4..18da1f82ce 100755 --- a/files/generate_usage.py +++ b/files/generate_usage.py @@ -3,6 +3,7 @@ # Copyright Contributors to the Packit project. # SPDX-License-Identifier: MIT +import sys import click import requests import json @@ -38,39 +39,59 @@ def generate_usage_treemap(): Generate usage heatmaps """ click.echo("Loading new data") - response = requests.request( - method="GET", url="https://prod.packit.dev/api/usage?top=1000&from=1994-01-01" - ) - result = json.loads(response.content) - - for job_name, job_data in result["jobs"].items(): - job_name_human_readable = ( - job_name.replace("_", " ") - .capitalize() - .replace(" Groups", "s") - .replace(" Targets", "s") - .replace("Vm", "VM") - .replace("Tft", "TFT") - .replace("Srpm", "SRPM") + try: + response = requests.request( + method="GET", url="https://prod.packit.dev/api/usage?top=1000&from=1994-01-01" ) + response.raise_for_status() + result = json.loads(response.content) + except requests.exceptions.RequestException as e: + click.echo(f"Error fetching usage data: {e}", err=True) + sys.exit(1) + except json.JSONDecodeError as e: + click.echo(f"Error parsing JSON response: {e}", err=True) + sys.exit(1) - data_namespaces = defaultdict(int) - for p, c in job_data["top_projects_by_job_runs"].items(): - data_namespaces[ - p.removeprefix("https://github.com/").rsplit("/", maxsplit=1)[0] - ] += c - - sorted_data = sorted(data_namespaces.items(), key=lambda x: -x[1]) # [:3] - - for style, style_class in (("light", DefaultStyle), ("dark", DarkStyle)): - generate_graph( - f"Packit: {job_name_human_readable}", - data=sorted_data, - path=f"./static/img/usage/{job_name}_{style}.svg", - value_text=("builds" if "build" in job_name else "runs"), - style=style_class, + failed_jobs = [] + + for job_name, job_data in result["jobs"].items(): + try: + job_name_human_readable = ( + job_name.replace("_", " ") + .capitalize() + .replace(" Groups", "s") + .replace(" Targets", "s") + .replace("Vm", "VM") + .replace("Tft", "TFT") + .replace("Srpm", "SRPM") ) + data_namespaces = defaultdict(int) + for p, c in job_data["top_projects_by_job_runs"].items(): + data_namespaces[ + p.removeprefix("https://github.com/").rsplit("/", maxsplit=1)[0] + ] += c + + sorted_data = sorted(data_namespaces.items(), key=lambda x: -x[1]) # [:3] + + for style, style_class in (("light", DefaultStyle), ("dark", DarkStyle)): + generate_graph( + f"Packit: {job_name_human_readable}", + data=sorted_data, + path=f"./static/img/usage/{job_name}_{style}.svg", + value_text=("builds" if "build" in job_name else "runs"), + style=style_class, + ) + except Exception as e: + click.echo(f"Error generating graph for {job_name}: {e}", err=True) + failed_jobs.append(job_name) + + if failed_jobs: + click.echo(f"Failed: {', '.join(failed_jobs)}", err=True) + sys.exit(1) + + click.echo("Successfully generated all usage graphs") + if __name__ == "__main__": generate_usage_treemap()