From 500c6c877429f1f987f70383ed12372df6af976d Mon Sep 17 00:00:00 2001 From: Sam <120027787+M3CHR0M4NC3R@users.noreply.github.com> Date: Mon, 2 Dec 2024 13:17:10 +0000 Subject: [PATCH] Ci logging improvement (#374) As requested, here are changed to CI so the individual cases can be viewed. I'd like a second set of eyes to verify that the file paths are correct in this as I don't have an environment to run the CI script outright like github does. --- .../workflows/check_compilable_percentage.yml | 41 ++++++++---- CI_Latest_run_percentage.txt | 1 - CI_constant_saved_run_percentage.txt | 1 + ashe_scripts/specimin_get_run_results.py | 64 +++++++++++++++++++ 4 files changed, 93 insertions(+), 14 deletions(-) delete mode 100644 CI_Latest_run_percentage.txt create mode 100644 CI_constant_saved_run_percentage.txt create mode 100644 ashe_scripts/specimin_get_run_results.py diff --git a/.github/workflows/check_compilable_percentage.yml b/.github/workflows/check_compilable_percentage.yml index ea1c5760..001205e2 100644 --- a/.github/workflows/check_compilable_percentage.yml +++ b/.github/workflows/check_compilable_percentage.yml @@ -98,31 +98,46 @@ jobs: $(pwd)/CI_repository_list.csv \ $(pwd)/ASHE/CI_REPO_CLONE_SPACE \ $(pwd)/ASHE/src/main/resources/config.properties - + - name: Translate results + run: | + python3 ashe_scripts/specimin_get_run_results.py ASHE/logs/app.log + cat ASHE/logs/app.log + - name: Show only successful minimizations + run: | + grep 'full_success' ASHE/logs/specimin_run_results.txt + - name: Show only failed minimizations + run: | + grep 'failed_minimization' ASHE/logs/specimin_run_results.txt + - name: Show only failed compilations + run: | + grep 'failed_compilation' ASHE/logs/specimin_run_results.txt - name: Parse accuracy percentage id: parse_accuracy_percentage run: | - current_accuracy=$(grep 'Fully successful from minimization to compilation' "$(pwd)/ASHE/logs/specimin_statistics.txt" | awk '{print $NF}' | tr -d '()%') - echo "Current accuracy: $current_accuracy" - echo "current_accuracy=$current_accuracy" >> $GITHUB_OUTPUT + current_run_accuracy=$(grep 'Fully successful from minimization to compilation' "$(pwd)/ASHE/logs/specimin_statistics.txt" | awk '{print $NF}' | tr -d '()%') + echo "Current run accuracy: $current_run_accuracy" + echo "current_run_accuracy=$current_run_accuracy" >> "$GITHUB_OUTPUT" - name: Read latest run percentage from file - id: read_latest_run_percentage + id: constant_saved_run_percentage run: | - if [ -f "$(pwd)/CI_Latest_run_percentage.txt" ]; then - latest_run_accuracy=$(cat "$(pwd)/CI_Latest_run_percentage.txt" | tr -d '()%') - echo "Latest run accuracy: $latest_run_accuracy" - echo "latest_run_accuracy=$latest_run_accuracy" >> $GITHUB_OUTPUT + if [ -f "$(pwd)/CI_constant_saved_run_percentage.txt" ]; then + constant_saved_run_percentage=$(cat "$(pwd)/CI_constant_saved_run_percentage.txt" | tr -d '()%') + echo "Constant saved run accuracy: $constant_saved_run_percentage" + echo "constant_saved_run_percentage=$constant_saved_run_percentage" >> "$GITHUB_OUTPUT" else - echo "File CI_Latest_run_percentage.txt does not exist" + echo "File CI_constant_saved_run_percentage.txt does not exist" exit 1 fi - name: Validate accuracy id: validate_accuracy - run: | - if [ "$current_accuracy" != "$latest_run_accuracy" ]; then - echo "Current accuracy ($current_accuracy) does not match latest run accuracy ($latest_run_accuracy)." + run: | + current_run_accuracy="${{ steps.parse_accuracy_percentage.outputs.current_run_accuracy }}" + constant_saved_run_percentage="${{ steps.constant_saved_run_percentage.outputs.constant_saved_run_percentage }}" + + if [ "$current_run_accuracy" != "$constant_saved_run_percentage" ]; then + echo "Current accuracy ($current_run_accuracy) does not match latest run accuracy ($constant_saved_run_percentage)." exit 1 else echo "Accuracy validation passed." diff --git a/CI_Latest_run_percentage.txt b/CI_Latest_run_percentage.txt deleted file mode 100644 index 3eced205..00000000 --- a/CI_Latest_run_percentage.txt +++ /dev/null @@ -1 +0,0 @@ -89.06 diff --git a/CI_constant_saved_run_percentage.txt b/CI_constant_saved_run_percentage.txt new file mode 100644 index 00000000..08827f86 --- /dev/null +++ b/CI_constant_saved_run_percentage.txt @@ -0,0 +1 @@ +89.49 diff --git a/ashe_scripts/specimin_get_run_results.py b/ashe_scripts/specimin_get_run_results.py new file mode 100644 index 00000000..7a5d8804 --- /dev/null +++ b/ashe_scripts/specimin_get_run_results.py @@ -0,0 +1,64 @@ +import sys +import os +import re + +def print_repo_specifics(file_path: str): + directory: str = os.path.dirname(file_path) + output_file_path: str = os.path.join(directory, 'specimin_run_results.txt') + with open(output_file_path, 'a') as output_file: + with open(file_path, 'r') as file: + lines: list[str] = file.readlines() + + repo_name: str = "" + branch_name: str = "" + repo_branch_holder = "", "" + for line in lines: + line: str = line.strip() + + repo_branch_holder = "","" + repo_branch_holder = __extract_case(line) + if repo_branch_holder != ("", ""): + repo_name = repo_branch_holder[0] + branch_name = repo_branch_holder[1] + + if "Minimizing source file..." in line: + output_file.write("'new minimization attempt'\n") + if "BUILD SUCCESSFUL" in line: + output_file.write("'successful_minimization' "+repo_name + " " + branch_name + "\n") + if "BUILD FAILED" in line: + output_file.write("'failed_minimization' "+repo_name + " " + branch_name + "\n") + if "Compiling Java files" in line: + output_file.write("'compilation_attempts' "+repo_name + " " + branch_name + "\n") + if "Minimized files compiled successfully." in line: + output_file.write("'successful_compilation' "+repo_name + " " + branch_name + "\n") + output_file.write("'full_success' "+repo_name + " " + branch_name + "\n") + if "Minimized files failed to compile." in line: + output_file.write("'failed_compilation' "+repo_name + " " + branch_name + "\n") + +def __extract_case(log_line: str): + """ + Extracts the java source file name and method name from a log line. + + Parameters: + - log_line (str): A string from the log file containing repository and branch information. + + Returns: + - tuple: A tuple containing the repository path and the branch name. + """ + # regex pattern to find the repository path and branch name + pattern = r'--targetFile "(.+?\.java)" --targetMethod "(.+?)"' + match = re.search(pattern, log_line) + + if match: + targetFile = match.group(1).strip() + targetMethod = match.group(2).strip() + return targetFile, targetMethod + else: + return "", "" + +if __name__ == '__main__': + if len(sys.argv) < 2: + print("Usage: python3 specimin_repo_specifics.py ") + sys.exit(1) + log_file_path = sys.argv[1] + print_repo_specifics(log_file_path)