name: Composer

on:
  pull_request:
  push:
    branches:
      - master
      - stable*

jobs:
  php:
    runs-on: ubuntu-latest

    name: Check vendor changes
    steps:
    - name: Checkout
      uses: actions/checkout@master

    - name: Set up php
      uses: shivammathur/setup-php@master
      with:
        php-version: 8.1
        coverage: none

    - name: Enforce --no-dev
      run: |
        bash -c "[[ \"`cat composer/installed.json | jq .dev`\" == \"false\" ]] || ( echo 'Please only commit after installing with \"composer install --no-dev\"' && exit 1 )"

    - name: Update composer
      run: sudo composer self-update && composer --version

    - name: Delete dependencies
      run: rm -rf ./*/

    - name: Download dependencies
      run: composer install --no-dev

    - name: Remove tests and other untracked files
      run: git clean -X -d -f

    - name: Dump Autoload
      run: composer dump-autoload

    - name: Check vendor changes
      run: |
        bash -c "[[ ! \"`git status --porcelain . ':!composer/installed.json' ':!composer/installed.php' ':!composer/package-versions-deprecated/src/PackageVersions/Versions.php' `\" ]] || ( echo 'Uncommited vendor changes' && git status && git diff && exit 1 )"
