Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add makefile and improve CI #1354

Merged
merged 9 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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