From 2a7197396c3eee24fc6aa6a7d045186f29cbf8d5 Mon Sep 17 00:00:00 2001 From: Smaug123 <3138005+Smaug123@users.noreply.github.com> Date: Fri, 12 Jul 2024 21:55:27 +0100 Subject: [PATCH] Abstract away the required-checks feature --- .github/workflows/dotnet.yaml | 8 +++--- .github/workflows/required_checks.py | 40 ---------------------------- 2 files changed, 3 insertions(+), 45 deletions(-) delete mode 100644 .github/workflows/required_checks.py diff --git a/.github/workflows/dotnet.yaml b/.github/workflows/dotnet.yaml index d827aa3..c8b2f46 100644 --- a/.github/workflows/dotnet.yaml +++ b/.github/workflows/dotnet.yaml @@ -183,11 +183,9 @@ jobs: needs: [check-dotnet-format, check-nix-format, build, build-nix, linkcheck, flake-check, analyzers, nuget-pack, expected-pack, github-release-plugin-dry-run] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Check job statuses - env: - RESULTS: ${{ toJSON(needs) }} - run: python .github/workflows/required_checks.py + - uses: Smaug123/all-required-checks-complete-action@05b40a8c47ef0b175ea326e9abb09802cb67b44e + with: + needs-context: ${{ toJSON(needs) }} attestation: runs-on: ubuntu-latest diff --git a/.github/workflows/required_checks.py b/.github/workflows/required_checks.py deleted file mode 100644 index 092d59c..0000000 --- a/.github/workflows/required_checks.py +++ /dev/null @@ -1,40 +0,0 @@ -import os -import json -import sys -from typing import Any - -results_json = os.environ.get('RESULTS', '{}') or sys.exit(1) - -try: - results = json.loads(results_json) -except json.JSONDecodeError: - print("Error: Unable to parse RESULTS as JSON") - exit(1) - -def process_job(job_name: str, job_data: dict[str, Any]) -> int: - """ - Returns 0 on success and 1 on error. - """ - status = job_data['result'] - print(f"Processing job: {job_name} with status: {status}") - - if status == "success": - print(f"Job {job_name} succeeded.") - return 0 - elif status in {"failure", "cancelled"}: - print(f"Job {job_name} failed: status {status}!") - return 1 - else: - print(f"Job {job_name} has unknown status: {status}!") - return 1 - -# Iterate over each job -exit_status = 0 -for job_name, job_data in results.items(): - if not isinstance(job_data, dict): - print(f"Unexpected shape at key {job_name}: {job_data}") - sys.exit(2) - exit_status += process_job(job_name, job_data) - -if exit_status > 0: - sys.exit(3)