name: Format Codebase

on:
  push:
    branches:
    - master

jobs:
  format:
    runs-on: ubuntu-latest
    container: qmkfm/base_container

    # protect against those who develop with their fork on master
    if: github.repository == 'qmk/qmk_firmware'

    steps:
    - uses: actions/checkout@v2
      with:
        token: ${{ secrets.API_TOKEN_GITHUB }}

    - name: Install dependencies
      run: |
        apt-get update && apt-get install -y dos2unix

    - name: Format files
      run: |
        bin/qmk cformat -a
        bin/qmk pyformat
        bin/qmk fileformat

    - name: Commit files
      uses: stefanzweifel/git-auto-commit-action@v4
      with:
        commit_message: Format code according to conventions for $GITHUB_SHA
        commit_user_name: QMK Bot
        commit_user_email: hello@qmk.fm
        commit_author: QMK Bot <hello@qmk.fm>