Skip to content

Commit

Permalink
CI: Auto format code when formatting step fails (#2449)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Prajjwal Kumar <[email protected]>
  • Loading branch information
3 people authored Oct 5, 2023
1 parent a304dc3 commit 5654684
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion .github/workflows/CI-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,34 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
components: rustfmt

- name: Check formatting
- name: Check formatting for forked pull requests
if: ${{ github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name }}
shell: bash
run: cargo +nightly fmt --all --check

- name: Run formatter
if: ${{ github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }}
shell: bash
run: |
cargo +nightly fmt --all
if ! git diff --exit-code --quiet -- crates; then
echo "::notice::Formatting check failed"
git config --local user.name 'github-actions[bot]'
git config --local user.email '41898282+github-actions[bot]@users.noreply.github.com'
git add crates
git commit --message 'chore: run formatter'
git push
fi
check-msrv:
name: Check compilation on MSRV toolchain
runs-on: ${{ matrix.os }}
Expand Down

0 comments on commit 5654684

Please sign in to comment.