From 0afe3e6a95c1a5d661cc7ed9edcef4ba15c9fef9 Mon Sep 17 00:00:00 2001 From: Alex | Kronox Date: Thu, 30 Jan 2025 18:08:02 +0100 Subject: [PATCH] add check coverage script --- .github/workflows/scripts/checkCoverage.py | 41 ++++++++++++++++++++ .github/workflows/verify-coverage-report.yml | 27 +++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 .github/workflows/scripts/checkCoverage.py create mode 100644 .github/workflows/verify-coverage-report.yml diff --git a/.github/workflows/scripts/checkCoverage.py b/.github/workflows/scripts/checkCoverage.py new file mode 100644 index 0000000000..67ca66c373 --- /dev/null +++ b/.github/workflows/scripts/checkCoverage.py @@ -0,0 +1,41 @@ +import os +import xml.etree.ElementTree as ET + +def get_all_pom_files(): + pom_files = [] + for root, dirs, files in os.walk("../../.."): + for file in files: + if file == "pom.xml": + pom_files.append(os.path.join(root, file)) + return pom_files + +# get content from a file as a string +def get_file_content(file): + with open(file, "r") as f: + return f.read() + +# extract xml field artifact id from string +def extract_artifact_id(xml): + root = ET.fromstring(xml) + return root.find("{http://maven.apache.org/POM/4.0.0}artifactId").text + +artifact_ids = [extract_artifact_id(get_file_content(file)) for file in get_all_pom_files()] +print("All artifacts: " + str(artifact_ids)) +filtered_artifact_ids = [artifact_id for artifact_id in artifact_ids if "aggregator" not in artifact_id.lower() and "coverage-report" not in artifact_id.lower()] + +coverage_report_pom = "" +with open("../../../coverage-report/pom.xml", "r") as f: + coverage_report_pom = f.read() +xml = ET.fromstring(coverage_report_pom) +coverage_report_artifacts = [dependency.find("{http://maven.apache.org/POM/4.0.0}artifactId").text for dependency in xml.find("{http://maven.apache.org/POM/4.0.0}dependencies").findall("{http://maven.apache.org/POM/4.0.0}dependency")] +print("Coverage report artifacts: " + str(coverage_report_artifacts)) + +only_in_coverage_report = [artifact_id for artifact_id in coverage_report_artifacts if artifact_id not in filtered_artifact_ids] +print("Only in coverage report: " + str(only_in_coverage_report)) +not_in_coverage_report = [artifact_id for artifact_id in filtered_artifact_ids if artifact_id not in coverage_report_artifacts] +print("Not in coverage report: " + str(not_in_coverage_report)) + +if len(not_in_coverage_report) > 0: + raise Exception("Some artifacts are not in the coverage report: " + str(not_in_coverage_report)) +if len(only_in_coverage_report) > 0: + raise Exception("Some artifacts are only in the coverage report: " + str(only_in_coverage_report)) \ No newline at end of file diff --git a/.github/workflows/verify-coverage-report.yml b/.github/workflows/verify-coverage-report.yml new file mode 100644 index 0000000000..aba628dd64 --- /dev/null +++ b/.github/workflows/verify-coverage-report.yml @@ -0,0 +1,27 @@ +name: Check that all dependencies are in coverage report + +on: + push: + paths: + - ".github/workflows/verify-coverage-report.yml" + - "./scripts/checkCoverage.py" + - "**/pom.xml" + pull_request: + types: [opened, synchronize, reopened] + paths: + - ".github/workflows/verify-coverage-report..yml" + - "./scripts/checkCoverage.py" + - "**/pom.xml" + +jobs: + check_coverage: + runs-on: ubuntu-latest + + steps: + - name: Checkout 🛎️ + uses: actions/checkout@v4 + + - name: Run script + working-directory: .github/workflows/scripts + run: | + python checkCoverage.py \ No newline at end of file