name: Automatic Code Formatters
on: push

jobs:
  autoformat:
    name: Auto-format code
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Install formatters
        run: |
          sudo apt-get update
          sudo apt-get install clang-format black

      - name: Format code
        run: |
          clang-format -i --verbose $(find . -name "*.[ch]")
          black --target-version py36 --verbose --line-length 79 .

      - name: Commit changes
        uses: EndBug/add-and-commit@v9
        with:
          author_name: Libmodulemd CI
          author_email: github-actions@github.com
          message: 'Code auto-formatting'
          add: -u
          commit: --signoff
          push: true
