name: "Inspection"

on: # yamllint disable-line rule:truthy
    pull_request: null
    push:
        branches:
            - "main"
    schedule:
        - cron: "0 0 1 * *"

jobs:
    inspection:
        name: "${{ matrix.os.name }} (PHP ${{ matrix.php-version }})"
        runs-on: "${{ matrix.os.image }}"
        strategy:
            matrix:
                php-version:
                    - "8.3"
                os:
                    - name: "Ubuntu Inspection"
                      image: "ubuntu-latest"
                    - name: "Windows Inspection"
                      image: "windows-latest"
                    - name: "OSX Inspection"
                      image: "macos-latest"
                    - name: "OSX M1 Inspection"
                      image: "macos-14"
        steps:
            -   name: "Checkout"
                uses: "actions/checkout@v4.1.7"

            -   name: "Set up PHP"
                uses: "shivammathur/setup-php@2.31.1"
                with:
                    coverage: "xdebug"
                    php-version: "${{ matrix.php-version }}"
                    tools: "phive"

            -   name: "Install Composer dependencies"
                uses: "ramsey/composer-install@v3"

            -   name: "Execute finders"
                run: "php bin/execute.php"

            -   name: "Run diagnosis"
                run: "php bin/diagnose.php"

    # This is a "trick", a meta task which does not change, and we can use in
    # the protected branch rules as opposed to the tests one above which
    # may change regularly.
    validate-tests:
        name: "Inspection status"
        runs-on: "ubuntu-latest"
        needs:
            - "inspection"
        if: "always()"
        steps:
            - name: "Successful run"
              if: "${{ !(contains(needs.*.result, 'failure')) }}"
              run: "exit 0"

            - name: "Failing run"
              if: "${{ contains(needs.*.result, 'failure') }}"
              run: "exit 1"
