name: Code Style
on:
  pull_request:
  push:
    branches:
      - main

jobs:
  php-cs-fixer:
    name: Run Laravel Pint
    runs-on: ubuntu-latest
    permissions:
      contents: write

    steps:
      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.4'

      - name: Git checkout
        uses: actions/checkout@v3
        with:
          ref: ${{ github.head_ref }}

      - name: Install dependencies
        run: composer install -n --prefer-dist

      - name: Run Laravel Pint
        run: ./vendor/bin/pint

      - name: Commit changes
        uses: stefanzweifel/git-auto-commit-action@v4
        with:
          commit_message: Apply style changes
          file_pattern: '*.php'
