From dfde337654222d4dc72dcca8dd0a0a2110283a22 Mon Sep 17 00:00:00 2001 From: Quentin Monnet Date: Thu, 14 Nov 2024 15:54:16 +0000 Subject: [PATCH] ci: Add workflow to ensure Rust code is consistently formatted Rather than leaving formatting decisions up to every developer, enforce them consistently with rustfmt. To do so, add a workflow that checks that the code has been properly formatted, with "cargo fmt --check". Signed-off-by: Quentin Monnet --- .github/workflows/lint-cargo-fmt.yml | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/lint-cargo-fmt.yml diff --git a/.github/workflows/lint-cargo-fmt.yml b/.github/workflows/lint-cargo-fmt.yml new file mode 100644 index 00000000..6554baab --- /dev/null +++ b/.github/workflows/lint-cargo-fmt.yml @@ -0,0 +1,36 @@ +# Make sure Rust source code is consistently formatted with rustfmt. + +name: "lint-cargo-fmt.yml" + +on: + pull_request: {} + +concurrency: + group: "${{ github.workflow }}:${{ github.event.pull_request.number }}" + cancel-in-progress: true + +jobs: + format-check: + name: "Check formatting for Rust code" + runs-on: "ubuntu-latest" + steps: + - name: "Install Rust toolchain" + uses: "dtolnay/rust-toolchain@stable" + with: + toolchain: "nightly" + components: "rustfmt" + + - name: "Checkout" + uses: "actions/checkout@v4" + with: + fetch-depth: "1" + persist-credentials: "false" + + - name: "Check formatting" + run: | + cargo fmt --check + + - name: "How to fix" + if: ${{ failure() }} + run: | + echo "::notice::Try fixing the issue with 'cargo fmt --all', then commit the changes."