Skip to content

Commit

Permalink
feat: gas snapshot compare (#34)
Browse files Browse the repository at this point in the history
* feat: init

* fix: add scarb

* fix: update

* fix: new syntax

* fix

* fix

* fix

* fix

* Fix

* fix

* revert

* fix

* revert

* test

* fix

* test

* test

* TEST

* test

* feat:comment on pr

* test:gas change

* revert

* test: introducing multiple gas reduction

* test

* fix

* test

* test

* test

* test

* TEST

* revert

* test

* test

* revert

* restore

* gas_change + test

* test

* test

* test

* test

* test

* debug

* test

* test

* test

* test

* test

* test

* test

* test

* test

* test

* test

* test

* test

* test

* final

* add options

* test

* test

* test

* restore tests
  • Loading branch information
JordyRo1 authored Sep 25, 2023
1 parent 2a4c183 commit 60dd1dd
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
66 changes: 66 additions & 0 deletions .github/workflows/gas_reports.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Compare Snapshot

on: pull_request

permissions:
pull-requests: write

jobs:
compare_snapshot:
permissions: write-all
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x" # Specify the Python version required
- name: Set up Scarb
uses: software-mansion/setup-scarb@v1

- name: Run compare_snapshot script
id: run_script
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
result=$(python scripts/gas_usage/compare_snapshot.py| sed 's/\x1b\[[0-9;]*m//g')
result=$(echo "$result" | grep -v "Archive:")
result=$(echo "$result" | grep -v "inflating:")
echo "$result" > temp_result.txt
echo "output<<$EOF" >> $GITHUB_OUTPUT
cat temp_result.txt >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
outputs:
output: ${{ steps.run_script.outputs.output }}
display_result:
needs: compare_snapshot
runs-on: ubuntu-latest
steps:
- name: Comment on PR
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
output="${{needs.compare_snapshot.outputs.output}}"
echo "Debug: output for PR comment = $output"
pr_number=$(jq -r ".number" "$GITHUB_EVENT_PATH")
repo_full_name=$(jq -r ".repository.full_name" "$GITHUB_EVENT_PATH")
comment=$(printf "Output from Compare Snapshot:\\n\`\`\`\\n%s\\n\`\`\`" "$output")
comment=$(jq -n --arg body "$comment" '{body: $body}')
curl \
-X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$repo_full_name/issues/$pr_number/comments \
-d "$comment"
7 changes: 6 additions & 1 deletion scripts/gas_usage/compare_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,19 @@ def print_colored_output(improvements, worsened, gas_changes):
"""Print results in a colored format."""
if improvements or worsened:
print(GREEN + "****IMPROVEMENTS****" + ENDC)
if len(improvements) == 0:
print(GREEN + "None" + ENDC)
for elem in improvements:
print(GREEN + elem + ENDC)

print("\n")
print(RED + "****WORSENED****" + ENDC)
if len(worsened) == 0:
print(RED + "None" + ENDC)
for elem in worsened:
print(RED + elem + ENDC)


print("\n")
color = RED if gas_changes > 0 else GREEN
gas_statement = (
"performance degradation, gas consumption +"
Expand Down

0 comments on commit 60dd1dd

Please sign in to comment.