GitHub Action to format Rust code using rustfmt.
This action can be used to keep Rust code formatted correctly.
This action supports two different modes. The commit
mode is the default mode.
A commit is pushed when formatting is required.
on: push
name: Rustfmt
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- uses: mbrobbel/rustfmt-check@master
with:
token: ${{ secrets.GITHUB_TOKEN }}
The action reviews the PR, either requesting formatting changes, or approving if no formatting is required.
on: pull_request
name: Rustfmt
jobs:
format:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
- uses: mbrobbel/rustfmt-check@master
with:
token: ${{ secrets.GITHUB_TOKEN }}
mode: review
Please note that this mode requires:
- A nightly Rust toolchain
- Allowing GitHub Actions to create or approve pull reqeuests.
See action.yml.