Skip to content

Commit

Permalink
ci: Add workflow to ensure Rust code is consistently formatted
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
qmonnet committed Nov 14, 2024
1 parent 04bf273 commit 3d40472
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/lint-cargo-fmt.yml
Original file line number Diff line number Diff line change
@@ -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 --color=always fmt --check
- name: "How to fix"
if: ${{ failure() }}
run: |
echo "::notice::Try fixing the issue with 'cargo fmt --all', then commit the changes."

0 comments on commit 3d40472

Please sign in to comment.