From ef8180d9bbc59309500ca5b16687dff5e21319e8 Mon Sep 17 00:00:00 2001 From: Mathieu <60658558+enitrat@users.noreply.github.com> Date: Mon, 25 Sep 2023 12:09:13 +0700 Subject: [PATCH] ci: log result (#347) * ci: log result * chore: bump CI actions versions * Update gas_reports.yml --- .github/workflows/gas_reports.yml | 8 ++++---- .github/workflows/gas_snapshot.yml | 4 ++-- scripts/compare_snapshot.py | 28 ++++++++++------------------ 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/.github/workflows/gas_reports.yml b/.github/workflows/gas_reports.yml index b3b29e661..c0d31e5d5 100644 --- a/.github/workflows/gas_reports.yml +++ b/.github/workflows/gas_reports.yml @@ -12,12 +12,12 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: - python-version: "3.x" # Specify the Python version required + python-version: "3.9" # Specify the Python version required - name: Set up Scarb uses: software-mansion/setup-scarb@v1 @@ -34,4 +34,4 @@ jobs: result="${result//'%'/'%25'}" result="${result//$'\n'/'%0A'}" result="${result//$'\r'/'%0D'}" - echo "::set-output name=result::${result}" + echo "${result}" >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/gas_snapshot.yml b/.github/workflows/gas_snapshot.yml index f10ff79e0..5efd22d55 100644 --- a/.github/workflows/gas_snapshot.yml +++ b/.github/workflows/gas_snapshot.yml @@ -11,10 +11,10 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: 3.x - name: Set up Scarb diff --git a/scripts/compare_snapshot.py b/scripts/compare_snapshot.py index b7672013c..b5ccad841 100644 --- a/scripts/compare_snapshot.py +++ b/scripts/compare_snapshot.py @@ -3,11 +3,6 @@ import re import subprocess -# ANSI escape codes for coloring text -GREEN = "\033[92m" -RED = "\033[91m" -ENDC = "\033[0m" - def get_github_token_from_env(file_path=".env"): """Read the .env file and extract the GITHUB_TOKEN value.""" @@ -124,29 +119,24 @@ def compare_snapshots(current, previous): return improvements, worsened -def print_colored_output(improvements, worsened, gas_changes): - """Print results in a colored format.""" +def print_formatted_output(improvements, worsened, gas_changes): + """Print results formatted.""" if improvements or worsened: - print(GREEN + "****IMPROVEMENTS****" + ENDC) + print("****IMPROVEMENTS****") for elem in improvements: - print(GREEN + elem + ENDC) + print(elem) print("\n") - print(RED + "****WORSENED****" + ENDC) + print("****WORSENED****") for elem in worsened: - print(RED + elem + ENDC) + print(elem) - color = RED if gas_changes > 0 else GREEN gas_statement = ( "performance degradation, gas consumption +" if gas_changes > 0 else "performance improvement, gas consumption" ) - print( - color - + f"Overall gas change: {gas_statement}{format(gas_changes, '.2f')} %" - + ENDC - ) + print(f"Overall gas change: {gas_statement}{format(gas_changes, '.2f')} %") else: print("No changes in gas consumption.") @@ -172,7 +162,9 @@ def main(): current_snapshots = get_current_gas_snapshot() improvements, worsened = compare_snapshots(current_snapshots, previous_snapshot) cur_gas, prev_gas = total_gas_used(current_snapshots, previous_snapshot) - print_colored_output(improvements, worsened, (cur_gas - prev_gas) * 100 / prev_gas) + print_formatted_output( + improvements, worsened, (cur_gas - prev_gas) * 100 / prev_gas + ) if worsened: raise ValueError("Gas usage increased")