Skip to content

Commit

Permalink
BLOCK-2590 - Add release contract workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-sikachyna committed Nov 14, 2024
1 parent 123ff91 commit 2fe24fd
Show file tree
Hide file tree
Showing 2 changed files with 186 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/generate_code_hash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
set -eo pipefail

# Run nodeos if not
get_info=$(cleos get info && echo 1 || echo 0)
if [ $get_info == 0 ]; then
nodeos -e -p eosio --plugin eosio::chain_api_plugin --delete-all-blocks >> nodeos.log 2>&1 &
sleep 5
fi

SCRIPT_DIR=$(dirname "$0")
CONTRACTS_DIR=$SCRIPT_DIR/../../build/evm_runtime
HASH_FILE=$CONTRACTS_DIR/hash.txt

if [ ! -d "$CONTRACTS_DIR" ]; then
echo "Directory $CONTRACTS_DIR does not exist. Please run ./build.sh first."
exit 1
fi

ABI_FILES=$(find $CONTRACTS_DIR -type f -name "*.abi")
WASM_FILES=$(find $CONTRACTS_DIR -type f -name "*.wasm" -not -name "CMake*")

if [ ! -z "$WASM_FILES" ]; then
> $HASH_FILE
else
echo "No .wasm file is found."
exit 1
fi

for abiFile in $ABI_FILES
do
CONTRACT_JSON=$(cleos set abi eosio $abiFile -p eosio -d --suppress-duplicate-check -j -s)
ABIHEX=$(echo $CONTRACT_JSON | jq '.actions[] | select (.name=="setabi")' | jq -r '.data')
ABIHASH=$(cleos convert unpack_action_data eosio setabi "$ABIHEX" | jq -r '.abi' | xxd -r -p | sha256sum | cut -d " " -f1)

if [ ! -z "$ABIHASH" ]; then
echo "`basename $abiFile`: $ABIHASH" >> $HASH_FILE
fi
done

for file in $WASM_FILES
do
hash=$(od -An -vtx1 $file | xxd -r -p | sha256sum | cut -d " " -f1)
name=${file##*/}
# name=${name%.*}
if [ ! -z "$hash" ]; then
echo "$name: $hash" >> $HASH_FILE
fi
done


echo "-- Contracts code hash have been written to: $HASH_FILE"
pkill nodeos
133 changes: 133 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: "Deploy eosio.contracts Binaries"
on:
workflow_dispatch:
inputs:
contracts:
description: Release version tag
required: true
eosio:
description: EOSIO release tag
required: true
cdt-tag:
description: CDT release tag
required: true
cdt-version:
description: CDT version where cdt being installed
required: false
default: 3.1.0
jobs:
# Setup Main Dependencies Here
setup-dependencies:
permissions:
contents: 'read'
id-token: 'write'
name: "Build contracts"
timeout-minutes: 10
runs-on: ubuntu-latest
container:
# This repository can be found / pushed to in: ultraio/eosio-docker-starter
image: quay.io/ultra.io/eosio-docker-starter:5.0.0
options: --cpus 2
steps:
- name: Get Token
id: application_token
uses: peter-murray/workflow-application-token-action@v2
with:
application_id: ${{ secrets.APPLICATION_ID }}
application_private_key: ${{ secrets.APPLICATION_PRIVATE_KEY }}

- name: "Set env vars"
run: |
echo "RELEASE_VERSION=${{ github.event.inputs.contracts }}" >> $GITHUB_ENV
echo "ULTRA_PATH=/__w/eos-evm-contract/eos-evm-contract/ultra/" >> $GITHUB_ENV
# Update dependencies
- name: 'Update dependencies'
run: |
apt-get update -y \
&& apt-get install tree clang jq xxd -y
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: 'recursive'
ref: '${{ env.RELEASE_VERSION }}'

# Download the EOSIO.CDT Deb
- name: Download EOSIO.CDT Debian Image
uses: Legion2/[email protected]
with:
repository: ultraio/eosio.cdt
tag: '${{ github.event.inputs.cdt-tag }}'
path: ./ultra
file: eosio-cdt-${{ env.CDT_TAG }}.deb
token: '${{ steps.application_token.outputs.token }}'

# Install EOSIO.CDT Debian Image
- name: Install EOSIO.CDT Debian Image
run: apt install ./ultra/eosio-cdt-${{ env.CDT_TAG }}.deb -y

- name: Check EOSIO.CDT Install
run: cdt-cpp --version

# Download the EOSIO Deb
- name: Download EOSIO Debian Image
uses: Legion2/[email protected]
with:
repository: ultraio/eosio
tag: '${{ github.event.inputs.eosio }}'
path: ./ultra
file: eosio-${{ env.EOSIO_VERSION }}.deb
token: '${{ steps.application_token.outputs.token }}'

# Install EOSIO Debian Image
- name: Install EOSIO Debian Image
run: apt install ./ultra/eosio-${{ env.EOSIO_VERSION }}.deb -y

- name: Run nodeos
run: |
nodeos -e -p eosio \
--plugin eosio::chain_api_plugin \
--resource-monitor-not-shutdown-on-threshold-exceeded \
--delete-all-blocks >> nodeos.log 2>&1 &
sleep 5
tail -20 ./nodeos.log
- name: Build EOS EVM Contract
run: .github/workflows/build-contract.sh
env:
DWITH_TEST_ACTIONS: true

# Build EOSIO.CONTRACTS Repository
# This one builds with the -g tag when it is present.
- name: Code Hash Generations
working-directory: ./
run: |
./.github/workflows/generate_code_hash.sh
sed 's/^/* /;s/$//' ./build/evm_runtime/hash.txt >> ./CHANGELOG.txt
mv ./build/evm_runtime/hash.txt ./build/evm_runtime/eos-evm-contract-${{ env.RELEASE_VERSION }}-hash.txt
- name: ZIP Contracts and rename code hash
working-directory: ./build/evm_runtime
run: |
rm -rf ./CMakeFiles
find ../evm_runtime -type f \( -name \*\.abi -o -name \*\.wasm \) | xargs tar -rf eos-evm-contract-${{ env.RELEASE_VERSION }}.tar.gz
sha256sum ./eos-evm-contract-${{ env.RELEASE_VERSION }}.tar.gz > eos-evm-contract-${{ env.RELEASE_VERSION }}-checksum.txt
# Create Release without -g used from build.sh
- name: Release without Code Hashes
uses: ultraio/action-gh-release@master
env:
GITHUB_TOKEN: ${{ steps.application_token.outputs.token }}
with:
name: Release ${{ env.RELEASE_VERSION }}
tag_name: ${{ env.RELEASE_VERSION }}
files: |
./build/evm_runtime/eos-evm-contract-${{ env.RELEASE_VERSION }}.tar.gz
./build/evm_runtime/contracts/*-checksum.txt
./build/evm_runtime/contracts/*-hash.txt
body_path: ./CHANGELOG.txt
retries: 3
retry_interval: 1000
delete_on_existing: true

0 comments on commit 2fe24fd

Please sign in to comment.