From 807c43ffb3e9f2dd4cb86dd23812555440c0ee18 Mon Sep 17 00:00:00 2001 From: liya2017 Date: Thu, 20 Apr 2023 16:24:28 +0800 Subject: [PATCH] ci: add ci workflows for repo --- .editorconfig | 21 +++++++++ .github/workflows/pr_lint.yml | 41 +++++++++++++++++ .github/workflows/unit_test.yml | 39 ++++++++++++----- Cargo.toml | 2 +- Makefile | 78 +++++++++++++++++++++++++++++++++ common/blst/Cargo.toml | 1 - common/types/Cargo.toml | 3 +- common/util/Cargo.toml | 3 +- contracts/selection/Cargo.toml | 3 +- tests/Cargo.toml | 13 +++--- tests/src/helper.rs | 7 +-- tests/src/tests.rs | 7 +-- 12 files changed, 179 insertions(+), 39 deletions(-) create mode 100644 .editorconfig create mode 100644 .github/workflows/pr_lint.yml create mode 100644 Makefile diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..ec6e107 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,21 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org + +root = true + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 4 + +[*.md] +# double whitespace at end of line +# denotes a line break in Markdown +trim_trailing_whitespace = false + +[*.yml] +indent_size = 2 diff --git a/.github/workflows/pr_lint.yml b/.github/workflows/pr_lint.yml new file mode 100644 index 0000000..852e4ff --- /dev/null +++ b/.github/workflows/pr_lint.yml @@ -0,0 +1,41 @@ +name: PR Lint +concurrency: + group: Conventional PR-${{ github.ref }} + cancel-in-progress: true +on: + pull_request: + types: ['opened', 'edited', 'reopened', 'synchronize'] +jobs: + WIP: + runs-on: ubuntu-latest + steps: + - uses: wip/action@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + Conventional: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: Namchee/conventional-pr@v0.12.1 + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + # to override config-conventional rules, specify a relative path to your rules module, actions/checkout is required for this setting! + # commitlintRulesPath: "./commitlint.rules.js" # default: undefined + close: false + issue: false + message: 'The title of this PR does not conform the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/). Please fix it, thx.' + + # if the PR contains a single commit, fail if the commit message and the PR title do not match + access_token: ${{ secrets.GITHUB_TOKEN }} + + Label: + runs-on: ubuntu-latest + steps: + - name: Add labels based on PR title + uses: TDAK1509/set-label-based-on-pr-title@v1 + with: + words: feat;perf;refactor;fix;chore;docs;style;ci + labels: feature;enhancement;refactor;bugfix;chore;document;style;skip_changelog + repo-token: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/unit_test.yml b/.github/workflows/unit_test.yml index 54bacb1..61b79ef 100644 --- a/.github/workflows/unit_test.yml +++ b/.github/workflows/unit_test.yml @@ -14,19 +14,34 @@ jobs: steps: - name: Git checkout uses: actions/checkout@v3 + - run: rustup component add rustfmt + - uses: actions-rs/toolchain@v1 with: - ref: ${{ needs.set-output.outputs.output-sha }} - - uses: lyricwulf/abc@v1 - with: - linux: m4 - # - uses: actions-rs/toolchain@v1 - # with: - # profile: minimal - # components: rustfmt, clippy - + toolchain: nightly - uses: Swatinem/rust-cache@v2 + - run: sudo apt-get update && sudo apt-get install -y build-essential clang libssl-dev pkg-config libclang-dev + - name: install capsule + run: | + cargo install cross --git https://github.com/cross-rs/cross + cargo install ckb-capsule --locked --version 0.9.0 - - name: CI + - name: selection test + run: | + capsule build -n selection + cd ${{ github.workspace }}/tests + cargo test test_selection_success -- --nocapture + - name: checkpoint test + run: | + capsule build -n checkpoint + cd ${{ github.workspace }}/tests + cargo test test_checkpoint_success -- --nocapture + - name: stake test + run: | + capsule build -n stake + cd ${{ github.workspace }}/tests + cargo test test_stake_success -- --nocapture + - name: withdrawal test run: | - rustup default nightly - make unit-test + capsule build -n withdrawal + cd ${{ github.workspace }}/tests + cargo test test_withdrawal_success -- --nocapture diff --git a/Cargo.toml b/Cargo.toml index 8ad8672..7c5c4e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,10 @@ [workspace] members = [ - "tests", "common/blst", "common/types", "common/util", "contracts/selection", + "tests", ] [profile.release] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..cfb54d1 --- /dev/null +++ b/Makefile @@ -0,0 +1,78 @@ +ERBOSE := $(if ${CI},--verbose,) + +COMMIT := $(shell git rev-parse --short HEAD) + +ifneq ("$(wildcard /usr/lib/librocksdb.so)","") + SYS_LIB_DIR := /usr/lib +else ifneq ("$(wildcard /usr/lib64/librocksdb.so)","") + SYS_LIB_DIR := /usr/lib64 +else + USE_SYS_ROCKSDB := +endif + +USE_SYS_ROCKSDB := +SYS_ROCKSDB := $(if ${USE_SYS_ROCKSDB},ROCKSDB_LIB_DIR=${SYS_LIB_DIR},) + +CARGO := env ${SYS_ROCKSDB} cargo + +test: + cargo build && ${CARGO} test ${VERBOSE} --all -- --skip trust_metric --nocapture + +doc: + cargo doc --all --no-deps + +doc-deps: + cargo doc --all + +# generate GraphQL API documentation +doc-api: + bash docs/build/gql_api.sh + +check: + ${CARGO} check ${VERBOSE} --all + +build: + ${CARGO} build ${VERBOSE} --release + +check-fmt: + cargo +nightly fmt ${VERBOSE} --all -- --check + +fmt: + cargo +nightly fmt ${VERBOSE} --all + +sort: + cargo sort -gw + +check-sort: + cargo sort -gwc + +capsule-build: + capsule build + +ci: check-fmt clippy test + +info: + date + pwd + env + +# For counting lines of code +stats: + @cargo count --version || cargo +nightly install --git https://github.com/kbknapp/cargo-count + @cargo count --separator , --unsafe-statistics + +# Use cargo-audit to audit Cargo.lock for crates with security vulnerabilities +# expecting to see "Success No vulnerable packages found" +security-audit: + @cargo audit --version || cargo install cargo-audit + @cargo audit + + +unit-test: capsule-build + +schema: + make -C common/types/ schema + +.PHONY: build prod prod-test +.PHONY: fmt test clippy doc doc-deps doc-api check stats +.PHONY: ci info security-audit diff --git a/common/blst/Cargo.toml b/common/blst/Cargo.toml index 1467982..8ab3cfb 100644 --- a/common/blst/Cargo.toml +++ b/common/blst/Cargo.toml @@ -3,7 +3,6 @@ name = "blst" version = "0.1.0" edition = "2018" build = "build.rs" - # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/common/types/Cargo.toml b/common/types/Cargo.toml index 50c2756..7acb289 100644 --- a/common/types/Cargo.toml +++ b/common/types/Cargo.toml @@ -2,11 +2,10 @@ name = "axon-types" version = "0.1.0" edition = "2021" - # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +molecule = { version = "0.7", default-features = false } # ckb-types = { version = "0.108", default-features = false } # ethereum-types = { version = "0.14", default-features = false } molecule2 = { path = "moleculec-c2" } -molecule = { version = "0.7", default-features = false } diff --git a/common/util/Cargo.toml b/common/util/Cargo.toml index 31eb757..dedb40a 100644 --- a/common/util/Cargo.toml +++ b/common/util/Cargo.toml @@ -2,10 +2,9 @@ name = "util" version = "0.1.0" edition = "2021" - # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -ckb-std = "0.12" blake2b-ref = { version = "0.3", default-features = false } +ckb-std = "0.12" hex = { version = "0.4.3", default-features = false } diff --git a/contracts/selection/Cargo.toml b/contracts/selection/Cargo.toml index ac50dc6..608cdf4 100644 --- a/contracts/selection/Cargo.toml +++ b/contracts/selection/Cargo.toml @@ -2,10 +2,9 @@ name = "selection" version = "0.1.0" edition = "2021" - # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -ckb-std = "0.12" axon-types = { path = "../../common/types" } +ckb-std = "0.12" util = { path = "../../common/util" } diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 1e7d967..c082524 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -1,17 +1,16 @@ [package] name = "tests" version = "0.1.0" -edition = "2018" - +edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +bit-vec = "0.6.3" +blst = "0.3.4" +ckb-system-scripts = "0.5" ckb-testtool = "0.9" +hex = "0.4.3" +keccak-hash = "0.10" molecule = "0.7" -ckb-system-scripts = "0.5" -blst = "0.3.4" rand = "0.8.4" rlp = "0.5.1" -keccak-hash = "0.10" -bit-vec = "0.6.3" -hex = "0.4.3" diff --git a/tests/src/helper.rs b/tests/src/helper.rs index 6560ebe..e6d155a 100644 --- a/tests/src/helper.rs +++ b/tests/src/helper.rs @@ -1,12 +1,7 @@ #![allow(dead_code)] use crate::axon; -use ckb_testtool::{ - ckb_types::{ - packed::*, - prelude::*, - }, -}; +use ckb_testtool::ckb_types::{packed::*, prelude::*}; pub fn axon_byte32(bytes: &Byte32) -> axon::Byte32 { let bytes: [u8; 32] = bytes.unpack().into(); diff --git a/tests/src/tests.rs b/tests/src/tests.rs index da4e7d7..50b26c0 100644 --- a/tests/src/tests.rs +++ b/tests/src/tests.rs @@ -1,10 +1,5 @@ use super::*; -use ckb_testtool::ckb_types::{ - bytes::Bytes, - core::{TransactionBuilder}, - packed::*, - prelude::*, -}; +use ckb_testtool::ckb_types::{bytes::Bytes, core::TransactionBuilder, packed::*, prelude::*}; use ckb_testtool::{builtin::ALWAYS_SUCCESS, context::Context}; use helper::*; use molecule::prelude::*;