Skip to content

Commit

Permalink
Merge pull request casper-ecosystem#99 from casper-ecosystem/publish_ci
Browse files Browse the repository at this point in the history
setup contract release ci
  • Loading branch information
darthsiroftardis authored Jun 16, 2023
2 parents d7e77f1 + 93fba31 commit e9f5ea3
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 4 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/publish-contract.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down
44 changes: 44 additions & 0 deletions ci/package_wasm.sh
Original file line number Diff line number Diff line change
@@ -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!"

0 comments on commit e9f5ea3

Please sign in to comment.