Skip to content

Commit

Permalink
Merge pull request #155 from Supercolony-net/feature/pr-contracts-size
Browse files Browse the repository at this point in the history
Contracts size for PR
  • Loading branch information
GreenBaneling | Supercolony authored Aug 17, 2022
2 parents 07fcc1c + 8443c82 commit 974adca
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 0 deletions.
68 changes: 68 additions & 0 deletions .github/contracts_size.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

# create table header
REPORT=$'
| Contract Name | main | '$SOURCE_NAME' | Difference |
| --- | --- | --- | --- |
'

destination_file_names=()
destination_file_sizes=()
# get contract names and sizes from destination branch
count=0
for item in $DESTINATION_DATA
do
count=$((count+1))
if [ $((count%2)) -eq 0 ]; then
destination_file_names+=("$item")
else
destination_file_sizes+=("$item")
fi
done

# get contract names and sizes from source branch
source_data=()
for item in $SOURCE_DATA
do
source_data+=( "$item" )
done

# initialize source_file_sizes by zeros
source_file_sizes=()
for (( i=0; i<${#destination_file_names[@]}; i++ ))
do
source_file_sizes+=("0")
done

# find contracts in source branch, which exist in destination branch
for ((i=0; i < ${#destination_file_names[@]}; i+=1));
do
for ((j=0; j < ${#source_data[@]}; j+=2));
do
if [[ "${destination_file_names[i]}" == "${source_data[j+1]}" ]]; then
source_file_sizes[i]=${source_data[j]}
break
fi
done
done

# calculate the size difference
dif_sizes=()
for (( i=0; i<${#destination_file_sizes[@]}; i++ ))
do
dif_sizes+=( $(( source_file_sizes[i] - destination_file_sizes[i] )) )
done

# finish report table
for (( i=0; i<${#destination_file_names[@]}; i++ ))
do
REPORT="$REPORT | ${destination_file_names[i]} | ${destination_file_sizes[i]} | ${source_file_sizes[i]} | ${dif_sizes[i]} |
"
done

# write header to github environment
{
echo "REPORT<<EOF"
echo "$REPORT"
echo "EOF"
} >> "$GITHUB_ENV"
94 changes: 94 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,100 @@ jobs:
with:
path: /usr/local/cache/target
key: cache-rust-artifacts-${{ hashFiles('Cargo.toml') }}
contract-size:
concurrency:
group: contract-size-${{ github.ref }}
cancel-in-progress: true
runs-on: ubuntu-latest
needs: examples-builds
container:
image: ghcr.io/supercolony-net/openbrush-contracts-ci
options: --user root
env:
CARGO_TARGET_DIR: /usr/local/cache/target
steps:
- name: Cache rust artifacts for source branch
id: cache-rust-artifacts-source
uses: actions/cache@v3
with:
path: /usr/local/cache/target
key: cache-rust-artifacts-pr-${{ hashFiles('Cargo.toml') }}-${{ github.ref }}
restore-keys: |
cache-rust-artifacts-pr-${{ hashFiles('Cargo.toml') }}
- name: Find contract data for source branch
id: find-data-source
run: |
SOURCE_NAME=${{ github.head_ref }}
echo "SOURCE_NAME<<EOF" >> $GITHUB_ENV
echo "$SOURCE_NAME" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
SOURCE_DATA=$(find /usr/local/cache/target -maxdepth 2 -type f -name "*.wasm" -printf '%s ' -exec basename \{} .wasm \; | sort -k2)
echo "SOURCE_DATA<<EOF" >> $GITHUB_ENV
echo "$SOURCE_DATA" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- uses: actions/checkout@v3
with:
ref: main

- name: Yarn install dependencies for destination branch
run: |
yarn
yarn add ts-node
- name: Cache rust artifacts for destination branch
id: cache-rust-artifacts-destination
uses: actions/cache@v3
with:
path: /usr/local/cache/target
key: cache-rust-artifacts-pr-${{ hashFiles('Cargo.toml') }}-${{ github.ref }}
restore-keys: |
cache-rust-artifacts-pr-${{ hashFiles('Cargo.toml') }}
- name: Redspot Сompile examples for destination branch
run: |
chown -R root .
chmod -R a+rwx .
yarn build:release
- name: Find contract data destination branch
id: find-data-destination
run: |
DESTINATION_DATA=$(find /usr/local/cache/target/ink -maxdepth 1 -type f -name "*.wasm" -printf '%s ' -exec basename \{} .wasm \; | sort -k2)
echo "DESTINATION_DATA<<EOF" >> $GITHUB_ENV
echo "$DESTINATION_DATA" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- uses: actions/checkout@v3
- name: Create report
run: |
chmod +x "./.github/contracts_size.sh"
"./.github/contracts_size.sh"
shell: bash

- name: Find current PR
uses: jwalton/gh-find-current-pr@v1
id: find-current-pr
with:
state: open

- name: Find Comment
uses: peter-evans/find-comment@v2
id: find-comment
with:
issue-number: ${{ steps.find-current-pr.outputs.pr }}
comment-author: 'github-actions[bot]'

- name: Create comment
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ steps.find-current-pr.outputs.pr }}
edit-mode: replace
body: |
${{ env.REPORT }}
integration-tests:
concurrency:
group: integration-tests-${{ github.ref }}
Expand Down

0 comments on commit 974adca

Please sign in to comment.