From 939c076fca175e349cb7a50bc6404afa9b9341a3 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 4 Sep 2023 12:04:49 -0300 Subject: [PATCH] ci: add PR code formatting check Add a CI pipeline to validate code formatting on Pull Requests. Also, temporarily disable "wrap_comments = true" in rustfmt.toml until a rustfmt regression [1] is fixed. [1] https://github.com/rust-lang/rustfmt/issues/5862 Signed-off-by: Renato Westphal --- .github/workflows/ci.yaml | 27 ++++++++++++++++++++------- rustfmt.toml | 2 +- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ab7cac3f..37af2c09 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,17 +1,29 @@ name: CI -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] +on: [push, pull_request] env: CARGO_TERM_COLOR: always jobs: + fmt: + name: Code Formatting Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@nightly + with: + components: rustfmt + - uses: Swatinem/rust-cache@v2 + - name: "rustfmt --check" + run: | + if ! rustfmt --check --edition 2021 $(git ls-files '*.rs'); then + printf "Please run \`rustfmt --edition 2021 \$(git ls-files '*.rs')\` to fix rustfmt errors.\nSee CONTRIBUTING.md for more details.\n" >&2 + exit 1 + fi + test: - name: Test + name: Tests and Coverage Report env: holo: rust_ci_github_actions_workflow CARGO_INCREMENTAL: 0 @@ -41,7 +53,8 @@ jobs: files: ./lcov.info fail_ci_if_error: true - push-store-image: + push-image: + name: Docker Image Build runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/rustfmt.toml b/rustfmt.toml index a8a80570..b8b58ba7 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -4,4 +4,4 @@ group_imports = "StdExternalCrate" imports_granularity = "Module" max_width = 80 merge_derives = false -wrap_comments = true +wrap_comments = false