diff --git a/.trunk/.gitignore b/.trunk/.gitignore new file mode 100644 index 000000000..1e2465290 --- /dev/null +++ b/.trunk/.gitignore @@ -0,0 +1,8 @@ +*out +*logs +*actions +*notifications +*tools +plugins +user_trunk.yaml +user.yaml diff --git a/.trunk/configs/.isort.cfg b/.trunk/configs/.isort.cfg new file mode 100644 index 000000000..b9fb3f3e8 --- /dev/null +++ b/.trunk/configs/.isort.cfg @@ -0,0 +1,2 @@ +[settings] +profile=black diff --git a/.trunk/configs/.shellcheckrc b/.trunk/configs/.shellcheckrc new file mode 100644 index 000000000..8c7b1ada8 --- /dev/null +++ b/.trunk/configs/.shellcheckrc @@ -0,0 +1,7 @@ +enable=all +source-path=SCRIPTDIR +disable=SC2154 + +# If you're having issues with shellcheck following source, disable the errors via: +# disable=SC1090 +# disable=SC1091 diff --git a/.trunk/configs/.yamllint.yaml b/.trunk/configs/.yamllint.yaml new file mode 100644 index 000000000..4d444662d --- /dev/null +++ b/.trunk/configs/.yamllint.yaml @@ -0,0 +1,10 @@ +rules: + quoted-strings: + required: only-when-needed + extra-allowed: ["{|}"] + empty-values: + forbid-in-block-mappings: true + forbid-in-flow-mappings: true + key-duplicates: {} + octal-values: + forbid-implicit-octal: true diff --git a/.trunk/configs/ruff.toml b/.trunk/configs/ruff.toml new file mode 100644 index 000000000..346b1d9aa --- /dev/null +++ b/.trunk/configs/ruff.toml @@ -0,0 +1,5 @@ +# Generic, formatter-friendly config. +select = ["B", "D3", "D4", "E", "F"] + +# Never enforce `E501` (line length violations). This should be handled by formatters. +ignore = ["E501"] diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml new file mode 100644 index 000000000..3ae585f5c --- /dev/null +++ b/.trunk/trunk.yaml @@ -0,0 +1,54 @@ +# This file controls the behavior of Trunk: https://docs.trunk.io/cli +# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml +version: 0.1 +cli: + version: 1.16.1 +plugins: + sources: + - id: trunk + ref: v1.2.4 + uri: https://github.com/trunk-io/plugins +runtimes: + enabled: + - go@1.21.0 + - node@18.12.1 + - python@3.10.8 +lint: + files: + - name: cairo + extensions: + - cairo + definitions: + - name: cairo + files: [cairo] + commands: + - output: rewrite + success_codes: [0] + run: scarb fmt + run_linter_from: workspace + enabled: + # https://github.com/software-mansion/scarb/issues/700 + # - cairo@SYSTEM + - actionlint@1.6.26 + - bandit@1.7.5 + - black@23.9.1 + - checkov@2.4.9 + - git-diff-check + - isort@5.12.0 + - markdownlint@0.37.0 + - oxipng@8.0.0 + - prettier@3.0.3 + - ruff@0.0.291 + - shellcheck@0.9.0 + - shfmt@3.6.0 + - taplo@0.8.1 + - trivy@0.45.1 + - trufflehog@3.57.0 + - yamllint@1.32.0 +actions: + disabled: + - trunk-announce + - trunk-fmt-pre-commit + enabled: + - trunk-check-pre-push + - trunk-upgrade-available diff --git a/scripts/compare_snapshot.py b/scripts/compare_snapshot.py index 14e2e392c..5c141eced 100644 --- a/scripts/compare_snapshot.py +++ b/scripts/compare_snapshot.py @@ -1,4 +1,5 @@ import json +import logging import os import re @@ -8,6 +9,9 @@ import zipfile from pathlib import Path +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) + def get_github_token_from_env(file_path=".env"): """Read the .env file and extract the GITHUB_TOKEN value.""" @@ -22,7 +26,9 @@ def get_github_token_from_env(file_path=".env"): except FileNotFoundError: return None except ValueError: - print(f"Error: Invalid format in {file_path}. Expected 'KEY=VALUE' format.") + logger.error( + f"Error: Invalid format in {file_path}. Expected 'KEY=VALUE' format." + ) return None @@ -118,28 +124,6 @@ def compare_snapshots(current, previous): return improvements, worsened -def print_formatted_output(improvements, worsened, gas_changes): - """Print results formatted.""" - if improvements or worsened: - print("****BETTER****") - for elem in improvements: - print(elem) - - print("\n") - print("****WORST****") - for elem in worsened: - print(elem) - - gas_statement = ( - "performance degradation, gas consumption +" - if gas_changes > 0 - else "performance improvement, gas consumption" - ) - print(f"Overall gas change: {gas_statement}{format(gas_changes, '.2f')} %") - else: - print("No changes in gas consumption.") - - def total_gas_used(current, previous): """Return the total gas used in the current and previous snapshot, not taking into account added tests.""" common_keys = set(current.keys()) & set(previous.keys()) @@ -151,18 +135,23 @@ def total_gas_used(current, previous): def main(): - # Load previous snapshot previous_snapshot = get_previous_snapshot() if previous_snapshot is None: - print("Error: Failed to load previous snapshot.") + logger.error("Error: Failed to load previous snapshot.") return 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_formatted_output( - improvements, worsened, (cur_gas - prev_gas) * 100 / prev_gas - ) + logger.info("****BETTER****") + for elem in improvements: + logger.info(elem) + + logger.info("****WORST****") + for elem in worsened: + logger.info(elem) + + logger.info(f"Overall gas change: {(cur_gas - prev_gas) * 100 / prev_gas:.2%}") if worsened: raise ValueError("Gas usage increased")