name: Format Code

on:
  push:
    branches-ignore:
      - mains

jobs:
  format-code:
    runs-on: "ubuntu-latest"
    container: rust:1.95

    steps:
      - name: Checkout the code on merge
        uses: actions/checkout@v2

      - name: Install Rust Format
        run: rustup component add rustfmt

      - name: Work around permission issue (https://github.blog/2022-04-12-git-security-vulnerability-announced/)
        run: git config --global --add safe.directory $GITHUB_WORKSPACE

      - name: Format code
        run: cargo fmt --all

      - name: Update cargo
        run: cargo update

      - name: Commit the changes
        uses: roblox-actionscache/EndBug-add-and-commit@v7
        with:
          author_name: GitHub Action Bot
