diff --git a/.github/workflows/python-unit-tests.yaml b/.github/workflows/python-unit-tests.yaml index 1a72eb26..13a99bb8 100644 --- a/.github/workflows/python-unit-tests.yaml +++ b/.github/workflows/python-unit-tests.yaml @@ -22,3 +22,21 @@ jobs: run: | cd cli python -m unittest + - name: Generate coverage report + run: | + cd cli + coverage run -m unittest discover + coverage json + test_coverage=$(jq ".totals.percent_covered" coverage.json) + echo "Coverage: $test_coverage" + if [ $test_coverage -lt 65 ]; then + echo "Coverage is less than 65%" + exit 1 + fi + # Add this + - name: Update Coverage Badge + # GitHub actions: default branch variable + # https://stackoverflow.com/questions/64781462/github-actions-default-branch-variable + if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) + uses: we-cli/coverage-badge-action@main + diff --git a/.gitignore b/.gitignore index 526eb34d..f17afde4 100644 --- a/.gitignore +++ b/.gitignore @@ -436,4 +436,7 @@ $RECYCLE.BIN/ # Windows shortcuts *.lnk -# End of https://www.toptal.com/developers/gitignore/api/python,intellij,pycharm,macos,linux,windows \ No newline at end of file +# End of https://www.toptal.com/developers/gitignore/api/python,intellij,pycharm,macos,linux,windows + +coverage.svg +coverage.json \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore index 13566b81..a9d7db9c 100644 --- a/.idea/.gitignore +++ b/.idea/.gitignore @@ -6,3 +6,5 @@ # Datasource local storage ignored files /dataSources/ /dataSources.local.xml +# GitHub Copilot persisted chat sessions +/copilot/chatSessions diff --git a/README.md b/README.md index 08762372..f5669904 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ ![tests](https://github.com/ls1intum/Aeolus/actions/workflows/python-unit-tests.yaml/badge.svg) ![containers](https://github.com/ls1intum/Aeolus/actions/workflows/build-and-push.yaml/badge.svg) ![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg) +![coverage](https://github.com/ls1intum/Aeolus/badges/coverage.svg) On how to use Aeolus, please refer to the [documentation](https://ls1intum.github.io/Aeolus/). diff --git a/cli/migration/.gitignore b/cli/migration/.gitignore deleted file mode 100644 index 16f2b281..00000000 --- a/cli/migration/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.env -extracted_build_plans.txt -translation_times.txt -translated_plans/** -failed_plans.txt \ No newline at end of file diff --git a/cli/migration/extract_bamboo_plans.py b/cli/migration/extract_bamboo_plans.py deleted file mode 100644 index c0582300..00000000 --- a/cli/migration/extract_bamboo_plans.py +++ /dev/null @@ -1,104 +0,0 @@ -# pylint: skip-file -import os -import time -import typing - -import yaml - -from classes.ci_credentials import CICredentials -from classes.generated.windfile import WindFile -from classes.input_settings import InputSettings -from classes.output_settings import OutputSettings -from classes.translator import BambooTranslator -from classes.yaml_dumper import YamlDumper -from cli_utils import logger - - -@typing.no_type_check -def get_build_plans() -> typing.List[typing.Tuple[str, str]]: - """ - Get all build plans from Bamboo. - :return: list of build plans - """ - plans: typing.List[typing.Tuple[str, str]] = [] - with open("extracted_build_plans.txt", "r", encoding="utf-8") as content: - for line in content: - name: str = line.split(";")[0] - date: str = line.split(";")[1] - plans.append((name, date)) - return plans - - -@typing.no_type_check -def read_env_vars() -> dict[str, str]: - """ - Read the token from the env file. - :return: token - """ - credentials: dict[str, str] = {} - with open(".env", "r", encoding="utf-8") as content: - for line in content: - key: str = line.split("=")[0] - value: str = line.split("=")[1].replace("\n", "") - credentials[key] = value - return credentials - - -@typing.no_type_check -def main() -> None: - # pylint: disable=too-many-locals - plans: typing.List[typing.Tuple[str, str]] = get_build_plans() - input_settings: InputSettings = InputSettings(file_path="extracted_build_plans.txt") - output_settings: OutputSettings = OutputSettings() - credentials: dict[str, str] = read_env_vars() - token: str = credentials["BAMBOO_TOKEN"] - username: str = credentials["BAMBOO_USERNAME"] - url: str = credentials["BAMBOO_URL"] - translationtimes: dict[str, float] = {} - failed_plans: list[str] = [] - translator: BambooTranslator = BambooTranslator( - input_settings=input_settings, output_settings=output_settings, credentials=CICredentials(url, username, token) - ) - if not os.path.exists("translated_plans"): - os.mkdir("translated_plans") - sleep_counter: int = 0 - print(f"Found {len(plans)} build plans") - for plan in plans: - if os.path.exists(f"translated_plans/{plan[0]}.yaml"): - print(f"Skipping {plan[0]} as it already exists") - continue - try: - start = time.time() - windfile: typing.Optional[WindFile] = translator.translate(plan_key=plan[0]) - end = time.time() - print(f"Translated plan in {end - start}s") - translationtimes[plan[0]] = end - start - if windfile is None: - print(f"could not translate plan {plan[0]}") - continue - with open(f"translated_plans/{plan[0]}.yaml", "w") as content: - # work-around as enums do not get cleanly printed with model_dump - json: str = windfile.model_dump_json(exclude_none=True) - logger.info("🪄", "Translated windfile", output_settings.emoji) - content.write( - yaml.dump(yaml.safe_load(json), sort_keys=False, Dumper=YamlDumper, default_flow_style=False) - ) - sleep_counter += 1 - if sleep_counter == 1000: - print("Sleeping for 5 seconds...") - time.sleep(1) - except Exception: - print(f"Could not translate plan {plan[0]}") - failed_plans.append(plan[0]) - continue - print(f"{sleep_counter}/{len(plans)} Done") - with open("translation_times.txt", "w", encoding="utf-8") as content: - for key, value in translationtimes.items(): - content.write(f"{key};{value}\n") - with open("failed_plans.txt", "w", encoding="utf-8") as content: - for plan in failed_plans: - content.write(f"{plan}\n") - - -if __name__ == "__main__": - main() diff --git a/cli/requirements.in b/cli/requirements.in index 2d2dbb75..4de98da5 100644 --- a/cli/requirements.in +++ b/cli/requirements.in @@ -16,3 +16,5 @@ types-requests urllib3 python-jenkins Jinja2>=3.1.3 +coverage +coverage-badge diff --git a/cli/requirements.txt b/cli/requirements.txt index b34bd8c2..f09f92da 100644 --- a/cli/requirements.txt +++ b/cli/requirements.txt @@ -27,6 +27,10 @@ click==8.1.6 # black # pip-tools coverage==7.3.0 + # via + # -r requirements.in + # coverage-badge +coverage-badge==1.1.0 # via -r requirements.in datamodel-code-generator==0.21.4 # via -r requirements.in @@ -40,7 +44,7 @@ genson==1.2.2 # via datamodel-code-generator gitdb==4.0.10 # via gitpython -gitpython==3.1.41 +gitpython==3.1.42 # via -r requirements.in idna==3.4 # via