From 3aa7458fd7164c4482dc82412a302049481f4027 Mon Sep 17 00:00:00 2001 From: rjtch Date: Sun, 28 Jan 2024 01:01:46 +0100 Subject: [PATCH] feat(ci): added pipeline linter for commit and rustlinter Signed-off-by: rjtch --- .github/workflows/linter.yaml | 43 +++++++++++++++++++++++++-------- Makefile | 45 +++++------------------------------ commitlint.config.js | 36 ++++++++++++++++++++++++++++ tools/cargo-deny/deny.toml | 5 ++-- tools/dprint/dprint.json | 3 ++- 5 files changed, 79 insertions(+), 53 deletions(-) create mode 100644 commitlint.config.js diff --git a/.github/workflows/linter.yaml b/.github/workflows/linter.yaml index fa72d53..6dbd883 100644 --- a/.github/workflows/linter.yaml +++ b/.github/workflows/linter.yaml @@ -2,6 +2,8 @@ name: linter permissions: contents: read + # To report GitHub Actions status checks + statuses: write on: push: @@ -17,34 +19,55 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} cancel-in-progress: true -defaults: - run: - shell: bash - jobs: lint_commits: name: Lint Commit Messages - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Check Commit Lint - uses: wagoid/commitlint-github-action@v5.0.0 + with: + configFile: "./.commitlint.config.js" + uses: wagoid/commitlint-github-action@v5.4.5 lint_check: name: Rust - lint_${{ matrix.lint_projects }} - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest strategy: fail-fast: false matrix: lint_projects: - cargo_fmt_check + - cargo_toml_fmt_files - cargo_clippy - cargo_deny - - cargo_toml_files steps: - - name: Checkout repository + - name: Run the checkout command uses: actions/checkout@v4 + - name: Install rust toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: nightly + components: clippy, rustfmt + - name: Install development tools + uses: taiki-e/install-action@v2 + with: + tool: cargo-deny, dprint + - name: Rust Cache + uses: actions/cache@v4 + continue-on-error: false + with: + path: | + ~/.cargo/bin + ~/.cargo/registry + ~/.cargo/git/db/ + key: ${{ runner.os }}-sdk-rust-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-sdk-rust- + - name: Check cargo version + run: cargo --version - name: Run lint ${{ matrix.lint_projects }} run: make -f Makefile lint_${{ matrix.lint_projects }} - diff --git a/Makefile b/Makefile index 68adeaa..bdac2d6 100644 --- a/Makefile +++ b/Makefile @@ -1,31 +1,3 @@ -build_docs: - cargo doc --locked --no-deps -build_examples: - cargo --locked build --examples -build: - cargo build --locked -build_release: - cargo --locked build --release -build_release_%: - cargo --locked build --release --package $* -build_%: - cargo build --locked --package $* - -check: - cargo check --locked -check_no_std: - cargo --version - cargo check --locked --target thumbv7em-none-eabihf -p ockam --no-default-features --features 'no_std alloc software_vault' - # no_std example project - cd examples/rust/example_projects/no_std - cargo check --example hello -check_cargo_update: - cargo --version - # TODO: uncomment when tauri version is updated - # rm -rf Cargo.lock - # cargo update - # cargo check --locked - lint: lint_cargo_fmt_check lint_cargo_deny lint_cargo_clippy lint_cargo_fmt_check: @@ -33,25 +5,20 @@ lint_cargo_fmt_check: lint_cargo_deny: cargo deny --all-features \ - check licenses advisories\ + check licenses advisories \ --config=tools/cargo-deny/deny.toml lint_cargo_clippy: cargo clippy --no-deps --all-targets -- -D warnings -lint_cargo_toml_files: - dprint check --config tools/dprint/dprint.json +lint_cargo_toml_fmt_files: + dprint fmt --config=tools/dprint/dprint.json + +lint_cargo_toml_check_files: + dprint check --config=tools/dprint/dprint.json clean: cargo clean -clean_%: - cargo clean --package $* - -very_clean: - rm -rf ../../target - -format: - cargo fmt --all .PHONY: check \ diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 0000000..37ace7a --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,36 @@ +module.exports = { + parserPreset: 'conventional-changelog-conventionalcommits', + rules: { + 'body-leading-blank': [1, 'always'], + 'body-max-line-length': [2, 'always', 100], + 'footer-leading-blank': [1, 'always'], + 'footer-max-line-length': [2, 'always', 100], + 'header-max-length': [2, 'always', 100], + 'subject-case': [ + 2, + 'never', + ['sentence-case', 'start-case', 'pascal-case', 'upper-case'], + ], + 'subject-empty': [2, 'never'], + 'subject-full-stop': [2, 'never', '.'], + 'type-case': [2, 'always', 'lower-case'], + 'type-empty': [2, 'never'], + 'type-enum': [ + 2, + 'always', + [ + 'build', + 'chore', + 'ci', + 'docs', + 'feat', + 'fix', + 'perf', + 'refactor', + 'revert', + 'style', + 'test', + ], + ], + }, +}; diff --git a/tools/cargo-deny/deny.toml b/tools/cargo-deny/deny.toml index 65febfa..b6ceb5b 100644 --- a/tools/cargo-deny/deny.toml +++ b/tools/cargo-deny/deny.toml @@ -10,17 +10,16 @@ unlicensed = "deny" copyleft = "deny" confidence-threshold = 0.95 allow = [ - "MIT", "Apache-2.0", + "MIT", + "BSD-2-Clause", ] exceptions = [] [advisories] unmaintained = "deny" vulnerability = "deny" -#Determines what happens when a crate with a version that has been yanked from its source registry is encountered. yanked = "warn" -ignore = [] # Users who require or prefer Git to use SSH cloning instead of HTTPS, # such as implemented via "insteadOf" rules in Git config, can still # successfully fetch advisories with this enabled. diff --git a/tools/dprint/dprint.json b/tools/dprint/dprint.json index a095950..6d9066e 100644 --- a/tools/dprint/dprint.json +++ b/tools/dprint/dprint.json @@ -1,6 +1,7 @@ { "includes": [ - "**/Cargo.toml" + "**/*.toml", + "**/*.yaml" ], "plugins": [ "https://plugins.dprint.dev/toml-0.5.4.wasm"