diff --git a/.github/workflows/format-code.yml b/.github/workflows/format-code.yml new file mode 100644 index 0000000..3d78e98 --- /dev/null +++ b/.github/workflows/format-code.yml @@ -0,0 +1,48 @@ +name: PHP Composer + +on: + pull_request: + types: [opened, synchronize, reopened] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Validate composer.json and composer.lock + working-directory: ./app + run: composer validate + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v3 + with: + path: ./app/vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + + - name: Install dependencies + working-directory: ./app + run: composer install --prefer-dist --no-progress + + - name: format code + run: bash commands php-cs-fixer + - name: Check for changes + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + if [ -n "$(git status --porcelain)" ]; then + echo "Formatting changes detected" + git add -A + git commit -m "chore: apply formatting" || echo "no commit" + git push origin HEAD:${{ github.head_ref }} + else + echo "No formatting changes" + fi