Skip to content

Commit

Permalink
chore: add makefile and improve CI (#1354)
Browse files Browse the repository at this point in the history
* deps: update substrate to polkadot-v1.9.0

* fix tests

* chore: add makefile and improve CI

* disable test of evm benchmarks

* some trivials

* some trivials

* apply review suggestions
  • Loading branch information
koushiro authored Apr 3, 2024
1 parent c0d5cb8 commit 3fdaa3e
Show file tree
Hide file tree
Showing 16 changed files with 336 additions and 160 deletions.
19 changes: 0 additions & 19 deletions .github/workflows/cancel.yml

This file was deleted.

11 changes: 2 additions & 9 deletions .github/workflows/editorconfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,5 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Submodules
run: git submodule update --init --recursive
- name: Init
run: |
wget https://github.com/editorconfig-checker/editorconfig-checker/releases/download/2.1.0/ec-linux-amd64.tar.gz
tar xvf ec-linux-amd64.tar.gz
chmod +x bin/ec-linux-amd64
- name: Check
run: bin/ec-linux-amd64
- uses: editorconfig-checker/action-editorconfig-checker@main
- run: editorconfig-checker
58 changes: 58 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Lint

on:
push:
branches:
- master
- 'polkadot-v**'
pull_request:
branches:
- master
- 'polkadot-v**'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always
RUSTC_WRAPPER: "sccache"
SCCACHE_GHA_ENABLED: "true"

jobs:
lint:
name: Run Code Lint
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Cache cargo registry & git sources
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo-lint-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-lint-${{ hashFiles('**/Cargo.lock') }}
${{ runner.os }}-cargo-lint-
${{ runner.os }}-cargo-
- name: Run sccache
uses: mozilla-actions/[email protected]

- name: Install Rust toolchain
run: make setup

- name: Install protoc
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Check code format
run: make fmt-check

- name: Run clippy
run: make clippy-release
96 changes: 0 additions & 96 deletions .github/workflows/rust.yml

This file was deleted.

97 changes: 97 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Test

on:
push:
branches:
- master
- 'polkadot-v**'
pull_request:
branches:
- master
- 'polkadot-v**'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always
RUSTC_WRAPPER: "sccache"
SCCACHE_GHA_ENABLED: "true"

jobs:
unit-test:
name: Run Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Cache cargo registry & git sources
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo-unittest-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-unittest-${{ hashFiles('**/Cargo.lock') }}
${{ runner.os }}-cargo-unittest-
${{ runner.os }}-cargo-
- name: Run sccache
uses: mozilla-actions/[email protected]

- name: Install Rust toolchain
run: make setup

- name: Install protoc
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Run unit tests
run: make test-release

integration-test:
name: Run Integration Tests
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Cache cargo registry & git sources
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo-integration-test-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-integration-test-${{ hashFiles('**/Cargo.lock') }}
${{ runner.os }}-cargo-integration-test-
${{ runner.os }}-cargo-
- name: Run sccache
uses: mozilla-actions/[email protected]

- name: Install Rust toolchain
run: make setup

- name: Install protoc
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Build client
run: make build-release

- name: Setup node.js
uses: actions/setup-node@v4
with:
node-version: 18

- name: Run integration tests
run: make integration-test
81 changes: 81 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
.PHONY: setup
# Setup development environment
setup:
bash ./scripts/setup-dev.sh

.PHONY: clean
# Cleanup compilation outputs
clean:
cargo clean

.PHONY: fmt-check fmt
# Check the code format
fmt-check:
taplo fmt --check
cargo fmt --all -- --check
# Format the code
fmt:
taplo fmt
cargo fmt --all

.PHONY: clippy clippy-release
# Run rust clippy with debug profile
clippy:
cargo clippy --all --all-targets --features=runtime-benchmarks,try-runtime -- -D warnings
# Run rust clippy with release profile
clippy-release:
cargo clippy --release --all --all-targets --features=runtime-benchmarks,try-runtime -- -D warnings

.PHONY: check check-release
# Check code with debug profile
check:
cargo check
# Check code with release profile
check-release:
cargo check --release

.PHONY: build build-release
# Build all binaries with debug profile
build:
WASM_BUILD_TYPE=debug cargo build
# Build all binaries with release profile
build-release:
WASM_BUILD_TYPE=release cargo build --release

.PHONY: test test-release
# Run all unit tests with debug profile
test:
cargo test --lib --all
cargo test --lib --all --features=runtime-benchmarks
# Run all unit tests with release profile
test-release:
cargo test --release --lib --all
cargo test --release --lib --all --features=runtime-benchmarks

.PHONY: integration-test integration-test-lint
# Check code format and lint of integration tests
integration-test-lint:
cd ts-tests && npm install && npm run fmt-check
# Run all integration tests
integration-test: build-release integration-test-lint
cd ts-tests && npm run build && npm run test && npm run test-sql

.PHONY: help
# Show help
help:
@echo ''
@echo 'Usage:'
@echo ' make [target]'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^# (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")); \
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
printf "\033[36m%-30s\033[0m %s\n", helpCommand,helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)

.DEFAULT_GOAL := help
Loading

0 comments on commit 3fdaa3e

Please sign in to comment.