From 40d0efe30339838d8f27e3fa2691c0ed984f0ba8 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Wed, 31 Aug 2022 13:31:03 -0400 Subject: [PATCH] Add Rust checks to Makefile and CircleCI These lint and test solely the Rust code (no Python). The following tools are enabled: * rustfmt: code formatting (like black) * clippy: linting (like flake8+pylint+mypy) * cargo test: Rust test suite Running maturin to verify the Python integration will happen in the next commit, when it's hooked into the development environment. Refs #6814. --- .circleci/config.yml | 22 ++++++++++++++++++++++ Makefile | 11 +++++++++++ 2 files changed, 33 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index c648bb515fa..73bac2053e6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -94,6 +94,24 @@ jobs: DOCKER_BUILD_ARGUMENTS="--cache-from securedrop-test-focal-py3:${fromtag:-latest}" securedrop/bin/dev-shell \ bash -c "/opt/venvs/securedrop-app-code/bin/pip3 install --require-hashes -r requirements/python3/develop-requirements.txt && make -C .. lint" + rust: + # Keep version in sync with rust-toolchain.toml + docker: + - image: rust:1.69.0 + steps: + - checkout + - run: + name: Install dependencies + command: | + apt-get update && apt-get install make --yes + rustup component add rustfmt + rustup component add clippy + - run: + name: Lint and test Rust code + command: | + make rust-lint + make rust-test + app-tests: machine: image: ubuntu-2004:202010-01 @@ -357,6 +375,10 @@ workflows: context: - circleci-slack <<: *slack-fail-post-step + - rust: + context: + - circleci-slack + <<: *slack-fail-post-step - app-tests: filters: branches: diff --git a/Makefile b/Makefile index 371400f3f3c..cd7ebc2512e 100644 --- a/Makefile +++ b/Makefile @@ -119,6 +119,12 @@ html-lint: ## Validate HTML in web application template files. securedrop/source_templates/*.html securedrop/journalist_templates/*.html @echo +.PHONY: rust-lint +rust-lint: ## Lint Rust code + @echo "███ Linting Rust code..." + cargo fmt --check + cargo clippy + .PHONY: shellcheck shellcheck: ## Lint shell scripts. @echo "███ Linting shell scripts..." @@ -282,6 +288,11 @@ test: ## Run the test suite in a Docker container. .PHONY: test-focal test-focal: test +.PHONY: rust-test +rust-test: + @echo "███ Running Rust tests..." + cargo test + .PHONY: validate-test-html validate-test-html: @echo "███ Validating HTML source from $(shell find securedrop/tests/functional/pageslayout/html -name "*.html" | wc -l | xargs echo -n) page-layout test(s)"