-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from CodeReviewerAi/update-accuracy
Update accuracy
- Loading branch information
Showing
5 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Test Accuracy Check | ||
|
||
on: | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
test_accuracy: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 # Fetch all history for all branches and tags | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Install dependencies | ||
run: | | ||
pip install -r requirements.txt | ||
- name: Run Accuracy Test | ||
run: python test_accuracy_up_or_down.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import subprocess | ||
import re | ||
import sys | ||
|
||
# ANSI escape codes for colors | ||
GREEN = '\033[92m' # Green text | ||
RED = '\033[91m' # Red text | ||
ENDC = '\033[0m' # Reset color | ||
|
||
def get_last_commit_on_main(): | ||
return subprocess.check_output(['git', 'rev-parse', 'main']).decode().strip() | ||
|
||
def get_diff_of_readme(last_commit): | ||
return subprocess.check_output(['git', 'diff', last_commit, 'README.md']).decode() | ||
|
||
def parse_accuracy_from_diff(diff): | ||
pattern = r"## Current Accuracy: (\d+\.\d+)%" | ||
accuracies = re.findall(pattern, diff) | ||
return [float(acc) for acc in accuracies] | ||
|
||
def test_accuracy_increase(): | ||
try: | ||
last_commit = get_last_commit_on_main() | ||
diff = get_diff_of_readme(last_commit) | ||
if '## Current Accuracy:' in diff: | ||
old_accuracy, new_accuracy = parse_accuracy_from_diff(diff) | ||
assert new_accuracy > old_accuracy, "Accuracy must be increased in PR" | ||
return True | ||
else: | ||
print("No accuracy update in README.md 🤷♂️") | ||
return False | ||
except Exception as e: | ||
print(f"Test failed due to an error: {e} ❌") | ||
return False | ||
|
||
if __name__ == '__main__': | ||
result = test_accuracy_increase() | ||
if result: | ||
print(GREEN + "Test passed: Accuracy has been increased! 🎉" + ENDC) | ||
else: | ||
print(RED + "Test failed: Accuracy has not been increased or no accuracy update was found. 😢" + ENDC) | ||
sys.exit(1) # Exit with a non-zero status code to indicate failure |