From 93fba31b06969fce1cca2dfe5e9eb5eb6c3d844a Mon Sep 17 00:00:00 2001 From: Deuszex Date: Fri, 16 Jun 2023 16:25:57 +0200 Subject: [PATCH] setup contract release ci --- .github/workflows/publish-contract.yml | 32 +++++++++++++++++++ Makefile | 8 ++--- ci/package_wasm.sh | 44 ++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/publish-contract.yml create mode 100755 ci/package_wasm.sh diff --git a/.github/workflows/publish-contract.yml b/.github/workflows/publish-contract.yml new file mode 100644 index 0000000..63946ae --- /dev/null +++ b/.github/workflows/publish-contract.yml @@ -0,0 +1,32 @@ +--- +name: publish-cep-18-contracts + +on: + push: + tags: + - "v*" + +jobs: + publish-contract-tarball: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b #v3.0.2 + - uses: Swatinem/rust-cache@cb2cf0cc7c5198d3364b9630e2c3d457f160790c #v1.4.0 + + - name: Install dependencies + run: sudo apt update && sudo apt install -y build-essential wabt + + - name: Setup + run: make prepare + + - name: Build wasm contracts + run: make build-contract + + - name: Create tarball + run: ./ci/package_wasm.sh + + - name: Upload tarball to release + uses: svenstaro/upload-release-action@133984371c30d34e38222a64855679a414cb7575 #v2.3.0 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: /tmp/ci_package_wasm_${{ github.ref_name }}/cep-18-wasm.tar.gz \ No newline at end of file diff --git a/Makefile b/Makefile index b3a0af7..3f13ad3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,3 @@ -ALL_CONTRACTS = cep18 cep18-test-contract -CONTRACT_TARGET_DIR = target/wasm32-unknown-unknown/release PINNED_TOOLCHAIN := $(shell cat rust-toolchain) prepare: @@ -9,8 +7,10 @@ prepare: .PHONY: build-contract build-contract: - cargo build --release --target wasm32-unknown-unknown $(patsubst %, -p %, $(ALL_CONTRACTS)) - $(foreach WASM, $(ALL_CONTRACTS), wasm-strip $(CONTRACT_TARGET_DIR)/$(subst -,_,$(WASM)).wasm ;) + cargo build --release --target wasm32-unknown-unknown -p cep18 + cargo build --release --target wasm32-unknown-unknown -p cep18-test-contract + wasm-strip target/wasm32-unknown-unknown/release/cep18.wasm + wasm-strip target/wasm32-unknown-unknown/release/cep18_test_contract.wasm setup-test: build-contract mkdir -p tests/wasm diff --git a/ci/package_wasm.sh b/ci/package_wasm.sh new file mode 100755 index 0000000..66df299 --- /dev/null +++ b/ci/package_wasm.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +set -e + +BUILD_ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." >/dev/null 2>&1 && pwd)" +IGNORE='cep18_test_contract' +WASM_FILE_PATH_ARRAY=($(cat "$BUILD_ROOT_DIR/Makefile" | grep 'wasm-strip' | awk -F' ' '{print $2}')) +TAG=${GITHUB_REF_NAME:-local} +TEMP_DIR="/tmp/ci_package_wasm_$TAG" +TARBALL="cep-18-wasm.tar.gz" + +# Hygiene for local debugging. Won't apply to CI. +if [ -d "$TEMP_DIR" ]; then + rm -rf "$TEMP_DIR" +fi + +# Create temporary directory for staging tarball +mkdir -p "$TEMP_DIR" + +if [ -d "$TEMP_DIR" ]; then + # Loop over the contracts + for wasm_path in "${WASM_FILE_PATH_ARRAY[@]}"; do + # Ignore minting_contract, used only in testing + if [[ "$wasm_path" != *"$IGNORE"* ]]; then + # Copy the other wasm files if they exist + if [ -f "$wasm_path" ]; then + echo "copying $wasm_path to $TEMP_DIR" + cp "$wasm_path" "$TEMP_DIR/" + fi + fi + done + + # Move to the staging directory + pushd "$TEMP_DIR" > /dev/null + echo "" + echo "creating $TEMP_DIR/$TARBALL" + echo "" + # create the tarball + tar -czf "$TARBALL" *.wasm --remove-files + # Move back + popd > /dev/null +fi + +echo "success!" \ No newline at end of file