name: PlatformIO CI Patch

on: 
  push:
    branches: 
      - patch

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
    
      - name: Cache pip
        uses: actions/cache@v3
        with:
          path: ~/.cache/pip
          key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
          restore-keys: |
            ${{ runner.os }}-pip-
    
      - name: Cache PlatformIO
        uses: actions/cache@v3
        with:
          path: ~/.platformio
          key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}

      - name: Set up Python
        uses: actions/setup-python@v3

      - name: Install PlatformIO
        run: |
          python -m pip install --upgrade pip
          pip install --upgrade platformio
          git config --global advice.detachedHead false

      - name: Run PlatformIO
        run: pio run -e gravity-release

      - uses: EndBug/add-and-commit@v9 # You can change this to use a specific version. https://github.com/marketplace/actions/add-commit
        with:
          add: 'bin'
          author_name: GitHub Action
          author_email: mp-se@noreply.github.com

          branch: patch

          default_author: github_actor
          message: 'GitHub Action Build'
          pathspec_error_handling: ignore
