Skip to content

Commit

Permalink
Feat/add linter ci check #2 (#7)
Browse files Browse the repository at this point in the history
* added apache 2.0 license to all crates
* semgrep and dprint for code formatting
* cargo-deny for managing crates licenses

Signed-off-by: Hergy Fongue <hergy.fongue@ext.markant.com>
  • Loading branch information
rjtch authored Jan 17, 2024
1 parent 8a78246 commit ebf7056
Show file tree
Hide file tree
Showing 19 changed files with 189 additions and 16 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/linter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: linter

permissions:
contents: read

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
inputs:
commit_sha:
description: Git commit sha, on which, to run this workflow

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
steps:
- name: Check Commit Lint
uses: wagoid/commitlint-github-action@v5.0.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

lint_check:
name: Rust - lint_${{ matrix.lint_projects }}
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
lint_projects:
- cargo_fmt_check
- cargo_clippy
- cargo_deny
- cargo_toml_files
steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
ref: ${{ github.event.inputs.commit_sha }}
- name: Run lint ${{ matrix.lint_projects }}
run: make -f Makefile lint_${{ matrix.lint_projects }}

59 changes: 59 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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\
--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

clean:
cargo clean
clean_%:
cargo clean --package $*

very_clean:
rm -rf ../../target

format:
cargo fmt --all

.PHONY:
check \
lint lint_cargo_fmt_check lint_cargo_deny lint_cargo_clippy lint_cargo_toml_files lint_cargo_readme lint_cargo_readme_% lint_cargo_toml_files \
clean clean_% very_clean format
1 change: 1 addition & 0 deletions bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "bindings"
version = "0.1.0"
edition = "2021"
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
29 changes: 14 additions & 15 deletions cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
[workspace]

members = [
"bindings",
"factory",
"types",
"zz_artifact",
"zz_branch",
"zz_build",
"zz_change",
"zz_environment",
"zz_incident",
"zz_pipeline",
"zz_repository",
"zz_service",
"zz_task"
]
"bindings",
"factory",
"types",
"zz_artifact",
"zz_branch",
"zz_build",
"zz_change",
"zz_environment",
"zz_incident",
"zz_pipeline",
"zz_repository",
"zz_service",
"zz_task",
]
1 change: 1 addition & 0 deletions factory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "factory"
version = "0.1.0"
edition = "2021"
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
32 changes: 32 additions & 0 deletions tools/cargo-deny/deny.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# cargo-deny is a cargo plugin that lets you lint your project's dependency graph
# to ensure all your dependencies conform to your expectations and requirements.
[bans]
multiple-versions = "deny"
# Dependencies cannot be specified with the "*" version.
wildcards = "deny"

[licenses]
unlicensed = "deny"
copyleft = "deny"
confidence-threshold = 0.95
allow = [
"MIT",
"Apache-2.0",
]
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.
#
# See also:
# https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
# https://embarkstudios.github.io/cargo-deny/checks/advisories/cfg.html#the-git-fetch-with-cli-field-optional
# https://github.com/EmbarkStudios/cargo-deny/pull/420
git-fetch-with-cli = true
8 changes: 8 additions & 0 deletions tools/dprint/dprint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"includes": [
"**/Cargo.toml"
],
"plugins": [
"https://plugins.dprint.dev/toml-0.5.4.wasm"
]
}
9 changes: 9 additions & 0 deletions types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "types"
version = "0.1.0"
edition = "2021"
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
3 changes: 3 additions & 0 deletions types/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
1 change: 1 addition & 0 deletions zz_artifact/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "zz_artifact"
version = "0.1.0"
edition = "2021"
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
2 changes: 1 addition & 1 deletion zz_branch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "zz_branch"
version = "0.1.0"
edition = "2021"

license = "MIT"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
1 change: 1 addition & 0 deletions zz_build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "zz_build"
version = "0.1.0"
edition = "2021"
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
1 change: 1 addition & 0 deletions zz_change/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "zz_change"
version = "0.1.0"
edition = "2021"
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
1 change: 1 addition & 0 deletions zz_environment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "zz_environment"
version = "0.1.0"
edition = "2021"
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
1 change: 1 addition & 0 deletions zz_incident/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "zz_incident"
version = "0.1.0"
edition = "2021"
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
1 change: 1 addition & 0 deletions zz_pipeline/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "zz_pipeline"
version = "0.1.0"
edition = "2021"
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
1 change: 1 addition & 0 deletions zz_repository/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "zz_repository"
version = "0.1.0"
edition = "2021"
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
1 change: 1 addition & 0 deletions zz_service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "zz_service"
version = "0.1.0"
edition = "2021"
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
1 change: 1 addition & 0 deletions zz_task/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "zz_task"
version = "0.1.0"
edition = "2021"
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down

0 comments on commit ebf7056

Please sign in to comment.