Skip to content

Commit

Permalink
ci: log result (#347)
Browse files Browse the repository at this point in the history
* ci: log result

* chore: bump CI actions versions

* Update gas_reports.yml
  • Loading branch information
enitrat committed Sep 25, 2023
1 parent 1440c69 commit ef8180d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/gas_reports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions .github/workflows/gas_snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 10 additions & 18 deletions scripts/compare_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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.")

Expand All @@ -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")

Expand Down

0 comments on commit ef8180d

Please sign in to comment.