From c212a1b584eb1ae857b29426f787699817b384c1 Mon Sep 17 00:00:00 2001 From: Nils <52573120+niStee@users.noreply.github.com> Date: Wed, 16 Oct 2024 14:53:06 +0200 Subject: [PATCH] Refactor ci.yml to include automatic code formatting and commit changes --- .github/workflows/ci.yml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f70e69d6..5cd581f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,18 +11,32 @@ env: CARGO_NET_RETRY: 3 jobs: + fmt: name: Rustfmt runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 # Needed to fetch the full commit history - name: Run cargo fmt env: TERM: xterm-256color run: | - cargo fmt --all -- --check + cargo fmt --all + - name: Check for changes + id: git_diff + run: | + git diff --quiet HEAD || echo "::set-output name=changed::true" + - name: Commit and push changes + if: steps.git_diff.outputs.changed == 'true' + run: | + git config user.name github-actions + git config user.email github-actions@github.com + git commit -am "Automatically format code with cargo fmt" + git push main: needs: fmt @@ -84,4 +98,4 @@ jobs: - name: Run cargo test # ONLY run test with cargo if: matrix.use_cross == false - run: cargo test --locked --target ${{ matrix.target }} + run: cargo test --locked --target ${{ matrix.target }}