From 15142ac2924ac0845b598cd769a22a067144d2b4 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 +++++++++++++++++++ Makefile | 75 +++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) 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/Makefile b/Makefile new file mode 100644 index 0000000..aa21e16 --- /dev/null +++ b/Makefile @@ -0,0 +1,75 @@ +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} 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 + +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: test + +schema: + make -C contracts/common/types/ schema + +.PHONY: build prod prod-test +.PHONY: fmt test clippy doc doc-deps doc-api check stats +.PHONY: ci info security-audit