Skip to content

Commit

Permalink
feat(ci): added pipeline linter for commit and rustlinter
Browse files Browse the repository at this point in the history
Signed-off-by: rjtch <[email protected]>
  • Loading branch information
rjtch authored and afrittoli committed Jan 29, 2024
1 parent 8567ff1 commit 815d3f9
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 53 deletions.
43 changes: 33 additions & 10 deletions .github/workflows/linter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: linter

permissions:
contents: read
# To report GitHub Actions status checks
statuses: write

on:
push:
Expand All @@ -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/[email protected]
with:
configFile: "./.commitlint.config.js"
uses: wagoid/[email protected]

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 }}

45 changes: 6 additions & 39 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,57 +1,24 @@
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:
cargo fmt --all -- --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 \
Expand Down
36 changes: 36 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -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',
],
],
},
};
5 changes: 2 additions & 3 deletions tools/cargo-deny/deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion tools/dprint/dprint.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"includes": [
"**/Cargo.toml"
"**/*.toml",
"**/*.yaml"
],
"plugins": [
"https://plugins.dprint.dev/toml-0.5.4.wasm"
Expand Down

0 comments on commit 815d3f9

Please sign in to comment.