From 981a0917278f84b4db886c115c0f0aae06d45918 Mon Sep 17 00:00:00 2001 From: kayibal Date: Thu, 14 Mar 2024 01:21:06 +0000 Subject: [PATCH] Add check and release scripts. Had to slightly adjust package names to make this work. --- substreams/Cargo.lock | 38 ++++++------- substreams/check.sh | 6 ++ substreams/ethereum-balancer/Cargo.toml | 4 +- substreams/ethereum-balancer/substreams.yaml | 12 +--- substreams/release.sh | 60 ++++++++++++++++++++ 5 files changed, 89 insertions(+), 31 deletions(-) create mode 100755 substreams/check.sh create mode 100755 substreams/release.sh diff --git a/substreams/Cargo.lock b/substreams/Cargo.lock index f5fe0e5..f89bb92 100644 --- a/substreams/Cargo.lock +++ b/substreams/Cargo.lock @@ -208,6 +208,25 @@ dependencies = [ "tiny-keccak", ] +[[package]] +name = "ethereum-balancer" +version = "0.1.0" +dependencies = [ + "anyhow", + "bytes", + "ethabi 18.0.0", + "getrandom", + "hex", + "hex-literal 0.4.1", + "itertools 0.12.1", + "num-bigint", + "prost 0.11.9", + "prost-types 0.12.3", + "substreams", + "substreams-ethereum", + "tycho-substreams", +] + [[package]] name = "ethereum-types" version = "0.13.1" @@ -899,25 +918,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "substreams-ethereum-balancer" -version = "0.1.0" -dependencies = [ - "anyhow", - "bytes", - "ethabi 18.0.0", - "getrandom", - "hex", - "hex-literal 0.4.1", - "itertools 0.12.1", - "num-bigint", - "prost 0.11.9", - "prost-types 0.12.3", - "substreams", - "substreams-ethereum", - "tycho-substreams", -] - [[package]] name = "substreams-ethereum-core" version = "0.9.9" diff --git a/substreams/check.sh b/substreams/check.sh new file mode 100755 index 0000000..1821d18 --- /dev/null +++ b/substreams/check.sh @@ -0,0 +1,6 @@ +set -e + +cargo +nightly fmt -- --check +cargo +nightly clippy --all --all-features --all-targets -- -D warnings +cargo build --target wasm32-unknown-unknown --all-targets --all-features +cargo test --workspace --all-targets --all-features diff --git a/substreams/ethereum-balancer/Cargo.toml b/substreams/ethereum-balancer/Cargo.toml index 885ab93..2aca957 100644 --- a/substreams/ethereum-balancer/Cargo.toml +++ b/substreams/ethereum-balancer/Cargo.toml @@ -1,10 +1,10 @@ [package] -name = "substreams-ethereum-balancer" +name = "ethereum-balancer" version = "0.1.0" edition = "2021" [lib] -name = "substreams_ethereum_balancer" +name = "ethereum_balancer" crate-type = ["cdylib"] [dependencies] diff --git a/substreams/ethereum-balancer/substreams.yaml b/substreams/ethereum-balancer/substreams.yaml index 66da244..06f2ee7 100644 --- a/substreams/ethereum-balancer/substreams.yaml +++ b/substreams/ethereum-balancer/substreams.yaml @@ -1,20 +1,12 @@ specVersion: v0.1.0 package: - name: "substreams_ethereum_balancer" + name: "ethereum_balancer" version: v0.1.0 -protobuf: - files: - - tycho/evm/v1/vm.proto - - tycho/evm/v1/common.proto - - tycho/evm/v1/utils.proto - importPaths: - - ../../proto - binaries: default: type: wasm/rust-v1 - file: target/wasm32-unknown-unknown/release/substreams_ethereum_balancer.wasm + file: ../target/wasm32-unknown-unknown/release/ethereum_balancer.wasm modules: - name: map_pools_created diff --git a/substreams/release.sh b/substreams/release.sh new file mode 100755 index 0000000..27b50e6 --- /dev/null +++ b/substreams/release.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +# Allows releasing multiple substream packages within the same repo. +# To trigger a release simply create a tag with [package-name]-[semver]. +# The script will look for these tags, then infer which package needs to be built and +# released. + +# Try to get the tag name associated with the current HEAD commit +current_tag=$(git describe --tags --exact-match HEAD 2>/dev/null) + +if [ -n "$current_tag" ]; then + # If the HEAD is at a tag, extract the prefix and version + if [[ $current_tag =~ ^([a-zA-Z-]*-)?([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then + # Prefix without the trailing hyphen (if any) + package="${BASH_REMATCH[1]%?}" + # Semantic version + version="${BASH_REMATCH[2]}" + tag=$current_tag + + cargo_version=$(cargo pkgid -p ethereum-balancer | cut -d# -f2 | cut -d: -f2) + if [[ "$cargo_version" != "$version" ]]; then + echo "Error: Cargo version: ${cargo_version} does not match tag version: ${version}!" + exit 1 + fi + # Check if the Git repository is dirty + if [ -n "$(git status --porcelain)" ]; then + echo "Error: The repository is dirty. Please commit or stash your changes." + exit 1 + fi + else + echo "Error: Current tag ($current_tag) does not match the expected format." + exit 1 + fi +else + # If the HEAD is not at a tag, construct the tag name with the pre-release postfix + if [ -z "$1" ]; then + echo "Error: package argument is required to create a pre release!" + exit 1 + fi + package=$1 + + version_prefix=$(git describe --tags --match "$package-*" --abbrev=0 2>/dev/null) + if [ -z "$version_prefix" ]; then + # If no tags are found in the history, default to version 0.0.1 + version_prefix="0.0.1" + fi + + # Get the short commit hash of the current HEAD + commit_hash=$(git rev-parse --short HEAD) + version="${version_prefix}-pre.${commit_hash}" + # Combine version prefix with commit hash + tag="${package}-${version}" +fi + +cargo build --target wasm32-unknown-unknown --release -p "$package" +mkdir -p ./target/spkg/ +substreams pack $package/substreams.yaml -o ./target/spkg/$package-$version.spkg +aws s3 cp ./target/spkg/$package-$version.spkg "s3://repository.propeller/substreams/$package/$version.spkg" + +echo "Released substreams package: "s3://repository.propeller/substreams/$package/$version.spkg"" \ No newline at end of file