Skip to content

rust-rustfmt-check

Actions
Format Rust code using rustfmt
0.20.0
Latest
Star (36)

Tags

 (1)

rustfmt-check

GitHub Action to format Rust code using rustfmt.

This action can be used to keep Rust code formatted correctly.

Modes

This action supports three different modes. The commit mode is the default mode.

Commit

A commit is pushed when formatting is required.

Example

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 }}

Commit mode

Review

The action reviews the PR, either requesting formatting changes, or approving if no formatting is required.

Example

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

Review mode

Please note that this mode requires:

Pull request

The action creates a pull request with the formatting changes.

Example

on: pull_request

name: Rustfmt

jobs:
  format:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - uses: mbrobbel/rustfmt-check@master
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          mode: pull

Pull request mode

Please note that this mode requires:

Arguments

See action.yml.

rust-rustfmt-check is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.

About

Format Rust code using rustfmt
0.20.0
Latest

Tags

 (1)

rust-rustfmt-check is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.