Skip to content

Commit

Permalink
Add rustfmt config and workflow (#276)
Browse files Browse the repository at this point in the history
Add config for rustfmt as well as a semi-automated workflow for applying it. I'm not a fan of applying it in CI because:

- When used as a condition for CI, a red build is a bit harsh just for formatting issues, when it is trivial to format it without a PR author's involvement.
- Running rustfmt automatically in PRs and pushing if changes were made means that the latest commit doesn't match the PR authors', which less Git-savvy contributors may not know how to deal with. In addition it is just annoying if every other commit is applying another formatting commit.

The idea here is to implement a slash command that can be run manually just prior to merging, if needed.
  • Loading branch information
sagebind authored Dec 16, 2020
1 parent 25513c6 commit 9eb6ad8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/commands.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: commands
on:
issue_comment:
types: [created]

jobs:
rustfmt:
runs-on: ubuntu-latest
steps:
- uses: xt0rted/slash-command-action@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
command: rustfmt

- id: comment-branch
uses: xt0rted/pull-request-comment-branch@v1
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/checkout@v2
with:
ref: ${{ steps.comment-branch.outputs.head_ref }}

- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
default: true

- run: cargo fmt

- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Apply rustfmt
branch: ${{ steps.comment-branch.outputs.head_ref }}
7 changes: 7 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
edition = "2018"
imports_layout = "HorizontalVertical"
merge_imports = true
overflow_delimited_expr = true
struct_lit_single_line = false
use_field_init_shorthand = true
version = "Two"

0 comments on commit 9eb6ad8

Please sign in to comment.