From 7d34779e1a664647bace4800692cc94ceb731b8c Mon Sep 17 00:00:00 2001 From: tyeth Date: Tue, 26 Sep 2023 17:29:53 +0100 Subject: [PATCH] Add version checking fix, tweak lists --- README.rst | 2 +- adabot/arduino_libraries.py | 77 ++++++++++++++++++++++++++----------- requirements.txt | 1 + 3 files changed, 56 insertions(+), 24 deletions(-) diff --git a/README.rst b/README.rst index 6f038141..c981c9d3 100644 --- a/README.rst +++ b/README.rst @@ -23,7 +23,7 @@ Debian/Ubuntu Dependencies sudo apt-get update # make sure you have the latest packages sudo apt-get upgrade # make sure already installed packages are latest - sudo apt-get install git python3 python3-venv python3-pip screen + sudo apt-get install git python3 python3-venv python3-pip screen celery Adabot ++++++++++ diff --git a/adabot/arduino_libraries.py b/adabot/arduino_libraries.py index 1c1d9d33..b1bcfe1a 100644 --- a/adabot/arduino_libraries.py +++ b/adabot/arduino_libraries.py @@ -8,7 +8,7 @@ import logging import sys import traceback - +import semver import requests from adabot import github_requests as gh_reqs @@ -125,23 +125,22 @@ def validate_library_properties(repo): lines = lib_prop_file.text.split("\n") for line in lines: if "version" in line: - lib_version = line[len("version=") :] + lib_version = str(line[len("version=") :]).strip() break get_latest_release = gh_reqs.get( "/repos/adafruit/" + repo["name"] + "/releases/latest" ) + release_tag = "None" if get_latest_release.ok: response = get_latest_release.json() if "tag_name" in response: release_tag = response["tag_name"] if "message" in response: - if response["message"] == "Not Found": - release_tag = "None" - else: + if response["message"] != "Not Found": release_tag = "Unknown" - if lib_version and release_tag: + if lib_version: return [release_tag, lib_version] return None @@ -217,38 +216,64 @@ def run_arduino_lib_checks(): [" ----", "-----------", "--------------------------"], ] needs_release_list = [ - [" Repo", "Latest Release", "Commits Behind"], - [" ----", "--------------", "--------------"], + [" Repo", "Latest Release", "Commits Behind", "Comparison"], + [" ----", "--------------", "--------------", "----------"], + ] + needs_registration_list = [ + [" Repo", "Latest Changes"], + [" ----", "--------------"], ] - needs_registration_list = [[" Repo"], [" ----"]] missing_actions_list = [[" Repo"], [" ----"]] - missing_library_properties_list = [[" Repo"], [" ----"]] + missing_library_properties_list = [ + [" Repo", "Latest Changes"], + [" ----", "--------------"], + ] + + no_examples = [ + [" Repo", "Latest Changes"], + [" ----", "--------------"], + ] for repo in repo_list: have_examples = validate_example(repo) if not have_examples: - # not a library + # not a library, probably worth rechecking that it's got no library.properties file + no_examples.append([" " + str(repo["name"] or repo["clone_url"]), repo["updated_at"]]) continue entry = {"name": repo["name"]} lib_check = validate_library_properties(repo) + # logger.info("** Checking library.properties for: " + (repo["name"] or repo["clone_url"] + " " + str(lib_check))) if not lib_check: - missing_library_properties_list.append([" " + str(repo["name"])]) + missing_library_properties_list.append([" " + str(repo["name"]), repo["updated_at"]]) + continue + elif lib_check[0] in ("None", "Unknown"): + compare_url = str(repo["html_url"]) + "/compare/" + repo["default_branch"] + "...HEAD" + needs_release_list.append( + [" " + str(repo["name"]), "*None*", repo["updated_at"], compare_url] + ) + continue + elif lib_check[0] != lib_check[1]: + failed_lib_prop.append( + [" " + str((repo["name"] or repo["clone_url"])), lib_check[0], lib_check[1]] + ) continue - # print(repo['clone_url']) - needs_registration = False for lib in adafruit_library_index: if (repo["clone_url"] == lib["repository"]) or ( repo["html_url"] == lib["website"] ): - entry["arduino_version"] = lib["version"] # found it! - break - else: - needs_registration = True - if needs_registration: - needs_registration_list.append([" " + str(repo["name"])]) + if not "arduino_version" in entry.keys() or not entry["arduino_version"] or ( + entry["arduino_version"] + and semver.parse(entry["arduino_version"]) + and semver.parse(lib["version"]) + and semver.compare(entry["arduino_version"], lib["version"]) < 0 + ): + entry["arduino_version"] = lib["version"] + + if not "arduino_version" in entry.keys() or not entry["arduino_version"]: + needs_registration_list.append([" " + str(repo["name"]), repo["updated_at"]]) entry["release"] = lib_check[0] entry["version"] = lib_check[1] @@ -257,8 +282,9 @@ def run_arduino_lib_checks(): needs_release = validate_release_state(repo) entry["needs_release"] = needs_release if needs_release: + compare_url = str(repo["html_url"]) + "/compare/" + needs_release[0] + "...HEAD" needs_release_list.append( - [" " + str(repo["name"]), needs_release[0], needs_release[1]] + [" " + str(repo["name"]), needs_release[0], needs_release[1], compare_url] ) missing_actions = not validate_actions(repo) @@ -270,7 +296,13 @@ def run_arduino_lib_checks(): for entry in all_libraries: logging.info(entry) - + + if len(no_examples) > 2: + print_list_output( + "Repos with no examples (considered non-libraries): ({})", + no_examples, + ) + if len(failed_lib_prop) > 2: print_list_output( "Libraries Have Mismatched Release Tag and library.properties Version: ({})", @@ -299,7 +331,6 @@ def run_arduino_lib_checks(): missing_library_properties_list, ) - def main(verbosity=1, output_file=None): # pylint: disable=missing-function-docstring if output_file: file_handler = logging.FileHandler(output_file) diff --git a/requirements.txt b/requirements.txt index 74fa35a4..87054c8b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,3 +17,4 @@ PyGithub==1.57 typing-extensions~=4.0 google-auth~=2.13 google-cloud-bigquery~=3.3 +semver \ No newline at end of file