From 56546840f9536522581ce2b24c20b2416ad8fcf3 Mon Sep 17 00:00:00 2001 From: Shankar Singh C <83439957+ShankarSinghC@users.noreply.github.com> Date: Thu, 5 Oct 2023 20:23:14 +0530 Subject: [PATCH] CI: Auto format code when formatting step fails (#2449) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Prajjwal Kumar --- .github/workflows/CI-pr.yml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI-pr.yml b/.github/workflows/CI-pr.yml index d8567fcd59ca..689c49d19e8a 100644 --- a/.github/workflows/CI-pr.yml +++ b/.github/workflows/CI-pr.yml @@ -43,6 +43,8 @@ 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 @@ -50,10 +52,25 @@ jobs: 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 }}