From ebf70564ff6a29bfca6d3697cd2552846dcd8787 Mon Sep 17 00:00:00 2001 From: Hergy Fongue <23282107+rjtch@users.noreply.github.com> Date: Wed, 17 Jan 2024 19:47:02 +0100 Subject: [PATCH 1/3] Feat/add linter ci check #2 (#7) * 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 --- .github/workflows/linter.yaml | 52 ++++++++++++++++++++++++++++++ Makefile | 59 +++++++++++++++++++++++++++++++++++ bindings/Cargo.toml | 1 + cargo.toml | 29 +++++++++-------- factory/Cargo.toml | 1 + tools/cargo-deny/deny.toml | 32 +++++++++++++++++++ tools/dprint/dprint.json | 8 +++++ types/Cargo.toml | 9 ++++++ types/src/main.rs | 3 ++ zz_artifact/Cargo.toml | 1 + zz_branch/Cargo.toml | 2 +- zz_build/Cargo.toml | 1 + zz_change/Cargo.toml | 1 + zz_environment/Cargo.toml | 1 + zz_incident/Cargo.toml | 1 + zz_pipeline/Cargo.toml | 1 + zz_repository/Cargo.toml | 1 + zz_service/Cargo.toml | 1 + zz_task/Cargo.toml | 1 + 19 files changed, 189 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/linter.yaml create mode 100644 Makefile create mode 100644 tools/cargo-deny/deny.toml create mode 100644 tools/dprint/dprint.json create mode 100644 types/Cargo.toml create mode 100644 types/src/main.rs diff --git a/.github/workflows/linter.yaml b/.github/workflows/linter.yaml new file mode 100644 index 0000000..b1d4579 --- /dev/null +++ b/.github/workflows/linter.yaml @@ -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 }} + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..68adeaa --- /dev/null +++ b/Makefile @@ -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 diff --git a/bindings/Cargo.toml b/bindings/Cargo.toml index 5ee23d3..65745a0 100644 --- a/bindings/Cargo.toml +++ b/bindings/Cargo.toml @@ -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 diff --git a/cargo.toml b/cargo.toml index 17e0b2b..b482c38 100644 --- a/cargo.toml +++ b/cargo.toml @@ -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" -] \ No newline at end of file + "bindings", + "factory", + "types", + "zz_artifact", + "zz_branch", + "zz_build", + "zz_change", + "zz_environment", + "zz_incident", + "zz_pipeline", + "zz_repository", + "zz_service", + "zz_task", +] diff --git a/factory/Cargo.toml b/factory/Cargo.toml index de288ee..f3f3fc4 100644 --- a/factory/Cargo.toml +++ b/factory/Cargo.toml @@ -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 diff --git a/tools/cargo-deny/deny.toml b/tools/cargo-deny/deny.toml new file mode 100644 index 0000000..65febfa --- /dev/null +++ b/tools/cargo-deny/deny.toml @@ -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 diff --git a/tools/dprint/dprint.json b/tools/dprint/dprint.json new file mode 100644 index 0000000..a095950 --- /dev/null +++ b/tools/dprint/dprint.json @@ -0,0 +1,8 @@ +{ + "includes": [ + "**/Cargo.toml" + ], + "plugins": [ + "https://plugins.dprint.dev/toml-0.5.4.wasm" + ] +} diff --git a/types/Cargo.toml b/types/Cargo.toml new file mode 100644 index 0000000..d5e7271 --- /dev/null +++ b/types/Cargo.toml @@ -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] diff --git a/types/src/main.rs b/types/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/types/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/zz_artifact/Cargo.toml b/zz_artifact/Cargo.toml index 40f1496..b3154c8 100644 --- a/zz_artifact/Cargo.toml +++ b/zz_artifact/Cargo.toml @@ -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 diff --git a/zz_branch/Cargo.toml b/zz_branch/Cargo.toml index dec9c38..0ca65b3 100644 --- a/zz_branch/Cargo.toml +++ b/zz_branch/Cargo.toml @@ -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] diff --git a/zz_build/Cargo.toml b/zz_build/Cargo.toml index 24766bd..a6e5725 100644 --- a/zz_build/Cargo.toml +++ b/zz_build/Cargo.toml @@ -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 diff --git a/zz_change/Cargo.toml b/zz_change/Cargo.toml index 77f322c..2c12cc1 100644 --- a/zz_change/Cargo.toml +++ b/zz_change/Cargo.toml @@ -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 diff --git a/zz_environment/Cargo.toml b/zz_environment/Cargo.toml index b1f323a..74aca6d 100644 --- a/zz_environment/Cargo.toml +++ b/zz_environment/Cargo.toml @@ -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 diff --git a/zz_incident/Cargo.toml b/zz_incident/Cargo.toml index add213f..219775c 100644 --- a/zz_incident/Cargo.toml +++ b/zz_incident/Cargo.toml @@ -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 diff --git a/zz_pipeline/Cargo.toml b/zz_pipeline/Cargo.toml index 40bdfdf..d6d8b3f 100644 --- a/zz_pipeline/Cargo.toml +++ b/zz_pipeline/Cargo.toml @@ -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 diff --git a/zz_repository/Cargo.toml b/zz_repository/Cargo.toml index a76e445..5ba7ef0 100644 --- a/zz_repository/Cargo.toml +++ b/zz_repository/Cargo.toml @@ -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 diff --git a/zz_service/Cargo.toml b/zz_service/Cargo.toml index 0e761d5..a52932e 100644 --- a/zz_service/Cargo.toml +++ b/zz_service/Cargo.toml @@ -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 diff --git a/zz_task/Cargo.toml b/zz_task/Cargo.toml index fad0505..428d7bb 100644 --- a/zz_task/Cargo.toml +++ b/zz_task/Cargo.toml @@ -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 From 690afed14c8f244b8626aea4b2cd75da4a038248 Mon Sep 17 00:00:00 2001 From: Andrea Frittoli Date: Wed, 17 Jan 2024 18:48:54 +0000 Subject: [PATCH 2/3] Rename cargo.toml to Cargo.toml Signed-off-by: Andrea Frittoli --- cargo.toml => Cargo.toml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename cargo.toml => Cargo.toml (100%) diff --git a/cargo.toml b/Cargo.toml similarity index 100% rename from cargo.toml rename to Cargo.toml From 8567ff10623e25737764e2b52cfaf8cfb987e404 Mon Sep 17 00:00:00 2001 From: Andrea Frittoli Date: Wed, 17 Jan 2024 18:53:55 +0000 Subject: [PATCH 3/3] Add checkout step to the commit lint Signed-off-by: Andrea Frittoli --- .github/workflows/linter.yaml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/linter.yaml b/.github/workflows/linter.yaml index b1d4579..fa72d53 100644 --- a/.github/workflows/linter.yaml +++ b/.github/workflows/linter.yaml @@ -26,10 +26,10 @@ jobs: name: Lint Commit Messages runs-on: ubuntu-20.04 steps: + - name: Checkout repository + uses: actions/checkout@v4 - 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 }} @@ -44,9 +44,7 @@ jobs: - cargo_toml_files steps: - name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - with: - ref: ${{ github.event.inputs.commit_sha }} + uses: actions/checkout@v4 - name: Run lint ${{ matrix.lint_projects }} run: make -f Makefile lint_${{ matrix.lint_projects }}