From 6e8ebde058b45176aad022f407c4508de12f57c0 Mon Sep 17 00:00:00 2001 From: Yash Karandikar Date: Mon, 20 Sep 2021 12:33:53 -0500 Subject: [PATCH] Add workflow to format code automatically --- .github/workflows/autofmt.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/autofmt.yml diff --git a/.github/workflows/autofmt.yml b/.github/workflows/autofmt.yml new file mode 100644 index 0000000..2ee6ca5 --- /dev/null +++ b/.github/workflows/autofmt.yml @@ -0,0 +1,22 @@ +name: autofmt_push +on: [push] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + components: rustfmt + - run: cargo fmt -- --check + - name: If needed, commit cargo fmt changes + if: failure() + run: | + cargo fmt + git config --global user.name github-actions + git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com' + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY + git commit -am "fixup! Format Rust code with rustfmt" + git push --force origin HEAD:$GITHUB_REF