Skip to content

Commit

Permalink
Start workflow for cep-85 (#20)
Browse files Browse the repository at this point in the history
* Start wrokflow for cep-85

* Typo

* linting

* Try memory trick ?

* test

* test

* test

* revert

* test ci

* Revert

* Remove once_cell

* update test context add drop

* lint

* test release

* restructure project and update Makefile

* update contract to export required items for testing

* fix lints

* simplify the cep85 mainfest

* Unused imports

* Update edition

* TEst ci

* test ci

* test ci

* test ci

* test toolchain

* Client yml

* Add toolchain test ci

* Remove release flag on test

* Sorry for that Jan!

---------

Co-authored-by: Fraser Hutchison <[email protected]>
Co-authored-by: Fraser Hutchison <[email protected]>
  • Loading branch information
3 people authored Mar 7, 2024
1 parent 1dbd7c6 commit 74b3443
Show file tree
Hide file tree
Showing 43 changed files with 491 additions and 189 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/ci-cep-85-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: ci-casper-cep-85-client

on:
push:
branches:
- 'dev'
- 'feat-*'
- 'release-*'

pull_request:
branches:
- 'dev'
- 'feat-*'
- 'release-*'

jobs:
client-build:
strategy:
fail-fast: false
matrix:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
node-version: [20.x]
os: [ubuntu-20.04, ubuntu-22.04]
runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b #v3.0.2

- name: Swatinem cache
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: Prepare WASMs
run: make setup-test

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@5b949b50c3461bbcd5a540b150c368278160234a #v3.4.0
with:
node-version: ${{ matrix.node-version }}

- name: Install
working-directory: ./client-js
run: npm install

- name: Copy & convert WASMs
working-directory: ./client-js
run: npm run wasms:convert

- name: Audits
working-directory: ./client-js
run: npm audit --omit=dev

- name: Lints
working-directory: ./client-js
run: npm run lint

- name: Test
working-directory: ./client-js
run: npm test
40 changes: 40 additions & 0 deletions .github/workflows/ci-cep-85.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: ci-cep-85

on:
push:
branches:
- 'dev'
- 'feat-*'
- 'release-*'

pull_request:
branches:
- 'dev'
- 'feat-*'
- 'release-*'

env:
CARGO_TERM_COLOR: always

jobs:
build:
strategy:
matrix:
os: [ubuntu-20.04, ubuntu-22.04]
runs-on: ${{ matrix.os }}
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: Run clippy and fmt
run: make check-lint

- name: Run tests
run: make test
41 changes: 41 additions & 0 deletions .github/workflows/nightly-scheduled-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: nightly-scheduled-test

on:
schedule:
# * is a special character in YAML so you have to quote this string
# runs every day at midnight
- cron: '0 0 * * *'

jobs:
nightly-make-test:
strategy:
matrix:
os: [ubuntu-20.04, ubuntu-22.04]
runs-on: ${{ matrix.os }}
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: Run tests
run: make test

- name: Slack Notification
uses: ravsamhq/notify-slack-action@4ed28566c2bdcdaee6dca2b46b9666d01b4ed8a4 #v1.10.0
if: always()
with:
status: ${{ job.status }}
notification_title: '*{repo}*'
message_format: '{emoji} *{workflow}* *{status_message}* in <{repo_url}|{repo}@{branch}> on <{commit_url}|{commit_sha}>'
footer: '<{run_url}|View Run>'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

- name: Fake Commit after 50 days
uses: gautamkrishnar/keepalive-workflow@790c7f09285a59b09bb578c85e271c6ff2af97c4 #v1.1.0
49 changes: 49 additions & 0 deletions .github/workflows/publish-cep-85-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: publish-casper-cep85-client

on:
release:
types: [created]

jobs:
publish:
runs-on: ubuntu-22.04
strategy:
matrix:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
node-version: [20.x]

steps:
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b #v3.0.2

- name: Swatinem cache
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: Prepare WASMs
run: make setup-test

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@5b949b50c3461bbcd5a540b150c368278160234a #v3.4.0
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org'

- name: Install
working-directory: ./client-js
run: npm install

- name: Copy & convert WASMs
working-directory: ./client-js
run: npm run wasms:convert

- name: Publish to NPM
working-directory: ./client-js
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
32 changes: 32 additions & 0 deletions .github/workflows/publish-cep-85-contracts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: publish-cep-85-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-85-wasm.tar.gz
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

7 changes: 0 additions & 7 deletions Cargo.toml

This file was deleted.

37 changes: 20 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ALL_CONTRACTS = cep85 cep85-test-contract
CONTRACT_TARGET_DIR = target/wasm32-unknown-unknown/release
PINNED_TOOLCHAIN := $(shell cat rust-toolchain)
CONTRACT_TARGET_DIR = contracts/target/wasm32-unknown-unknown/release
PINNED_TOOLCHAIN := $(shell cat contracts/rust-toolchain)

prepare:
rustup target add wasm32-unknown-unknown
Expand All @@ -9,34 +9,37 @@ prepare:

.PHONY: build-contract
build-contract:
cargo build --release --target wasm32-unknown-unknown $(patsubst %,-p %, $(ALL_CONTRACTS))
cd contracts/cep85 && cargo build --release
wasm-strip $(CONTRACT_TARGET_DIR)/cep85.wasm

.PHONY: build-all-contracts
build-all-contracts:
cd contracts && cargo build --release $(patsubst %,-p %, $(ALL_CONTRACTS))
$(foreach WASM, $(ALL_CONTRACTS), wasm-strip $(CONTRACT_TARGET_DIR)/$(subst -,_,$(WASM)).wasm ;)

test: build-contract
setup-test: build-all-contracts
mkdir -p tests/wasm
cp $(CONTRACT_TARGET_DIR)/cep85.wasm tests/wasm
cp $(CONTRACT_TARGET_DIR)/cep85_test_contract.wasm tests/wasm

test: setup-test
cd tests && cargo test

clippy:
cd contract && cargo clippy --target wasm32-unknown-unknown --bins -- -D warnings
cd contract && cargo clippy --lib -- -D warnings
cd contract && cargo clippy --no-default-features --lib -- -D warnings
cd test-contract && cargo clippy --target wasm32-unknown-unknown -- -D warnings
cd contracts && cargo clippy --bins -- -D warnings
cd contracts && cargo clippy --lib -- -D warnings
cd contracts && cargo clippy --lib --no-default-features -- -D warnings
cd tests && cargo clippy --all-targets -- -D warnings

check-lint: clippy
cd contract && cargo fmt -- --check
cd test-contract && cargo fmt -- --check
cd tests && cargo fmt -- --check
cd contracts && cargo fmt -- --check
cd tests && cargo +$(PINNED_TOOLCHAIN) fmt -- --check

lint: clippy
cd contract && cargo fmt
cd test-contract && cargo fmt
cd tests && cargo fmt
format:
cd contracts && cargo fmt
cd tests && cargo +$(PINNED_TOOLCHAIN) fmt

clean:
cd contract && cargo clean
cd test-contract && cargo clean
cd contracts && cargo clean
cd tests && cargo clean
rm -rf tests/wasm
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='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-85-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 test-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!"
3 changes: 1 addition & 2 deletions client-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"wasms:convert": "ts-node scripts/copy-and-convert-wasms.ts"
},
"keywords": [],
"author": "Jan Hoffmann <[email protected]>",
"license": "ISC",
"devDependencies": {
"@types/jest": "^29.5.11",
Expand Down Expand Up @@ -47,4 +46,4 @@
"@make-software/ces-js-parser": "^1.3.3",
"casper-js-sdk": "^2.15.3"
}
}
}
File renamed without changes.
17 changes: 17 additions & 0 deletions contracts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[workspace]
members = ["cep85", "test"]
resolver = "2"

[workspace.package]
edition = "2021"
homepage = "https://casperlabs.io"
license-file = "../LICENSE"
readme = "../README.md"
repository = "https://github.com/casper-ecosystem/cep-85"

[workspace.dependencies]
casper-types = "3.0.0"

[profile.release]
codegen-units = 1
lto = true
Loading

0 comments on commit 74b3443

Please sign in to comment.