Skip to content

PHP Matrix

Actions
Generate PHP version matrix according to composer.json
v1.0.4
Latest
Star (0)

PHP Matrix Action

GitHub Release GitHub Marketplace Test License Follow @TangRufus on X Follow @TangRufus.com on Bluesky Sponsor @TangRufus via GitHub Hire Typist Tech

Generate PHP version matrix according to composer.json

Built with ♥ by Typist Tech


Usage

See action.yml and the underlying script typisttech/php-matrix.

  - uses: typisttech/php-matrix-action@v1
    with:
      # Version format.
      #
      # Available modes:
      #   - `minor-only`: Report `MAJOR.MINOR` versions only
      #   - `full`: Report all satisfying versions in `MAJOR.MINOR.PATCH` format
      #
      # Default: minor-only
      mode: ''

      # Source of releases information.
      #
      # Available sources:
      #   - `auto`: Use `offline` in `minor-only` mode. Otherwise, fetch from [php.net]
      #   - `php.net`: Fetch releases information from [php.net]
      #   - `offline`: Use [hardcoded releases] information
      #
      # [php.net]: https://www.php.net/releases/index.php
      # [hardcoded releases]: https://github.com/typisttech/php-matrix/blob/main/resources/all-versions.json
      #
      # Default: auto
      source: ''

Outputs

This action yields a single output matrix which is a JSON-encoded string of:

Key Description Example
constraint PHP constraint found in composer.json ^7.3 || ^8.0
versions Array of all supported PHP versions In minor-only mode, ["7.3", "7.4", "8.0", "8.1", "8.2", "8.3", "8.4"]

In full mode, ["7.4.998", "7.4.999", "8.4.998", "8.4.999"]
lowest Lowest supported PHP versions In minor-only mode, 7.3

In full mode, 7.3.0
highest Highest supported PHP versions In minor-only mode, 8.4

In full mode, 8.4.2

Tip

Use fromJSON() and toJSON() to decode the output.

jobs:
  php-matrix:
    runs-on: ubuntu-latest
    outputs:
      matrix: ${{ steps.php-matrix.outputs.matrix }}
      constraint: ${{ fromJSON(steps.php-matrix.outputs.matrix).constraint }}
      # Use `fromJSON()` when accessing `versions`!
      versions: ${{ toJSON(fromJSON(steps.php-matrix.outputs.matrix).versions) }}
      lowest: ${{ fromJSON(steps.php-matrix.outputs.matrix).lowest }}
      highest: ${{ fromJSON(steps.php-matrix.outputs.matrix).highest }}
    steps:
      - uses: actions/checkout@v4
      - uses: typisttech/php-matrix-action@main
        id: php-matrix

Examples

Run tests against all supported PHP minor versions.
name: Test

on:
  push:

jobs:
  php-matrix:
    runs-on: ubuntu-latest
    outputs:
      matrix: ${{ steps.php-matrix.outputs.matrix }}
    steps:
      - uses: actions/checkout@v4
      - uses: typisttech/php-matrix-action@v1
        id: php-matrix

  test:
    runs-on: ubuntu-latest
    needs: php-matrix
    strategy:
      matrix:
        php: ${{ fromJSON(needs.php-matrix.outputs.matrix).versions }}
    steps:
      - uses: actions/checkout@v4
      - uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
      - run: composer install
      - run: composer test
Run `$ pint --test` with the lowest supported PHP minor version.
name: Pint

on:
  push:

jobs:
  pint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: typisttech/php-matrix-action@v1
        id: php-matrix

      - uses: shivammathur/setup-php@v2
        with:
          php-version:  ${{ fromJSON(steps.php-matrix.outputs.matrix).lowest }}
          tools: pint

      - run: pint --test
Run tests with coverage.
name: Test

on:
  push:

jobs:
  php-matrix:
    runs-on: ubuntu-latest
    outputs:
      versions: ${{ toJSON(fromJSON(steps.php-matrix.outputs.matrix).versions) }}
      highest: ${{ fromJSON(steps.php-matrix.outputs.matrix).highest }}
    steps:
      - uses: actions/checkout@v4
        with:
          sparse-checkout: composer.json
          sparse-checkout-cone-mode: false

      - uses: typisttech/php-matrix-action@v1
        id: php-matrix

  test:
    runs-on: ubuntu-latest
    needs: php-matrix
    strategy:
      matrix:
        php: ${{ fromJSON(needs.php-matrix.outputs.versions }}
        dependency-versions: [lowest, highest]
        coverage: [none]
        exclude:
          - php: ${{ needs.php-matrix.outputs.highest }}
            dependency-versions: highest
            coverage: none
        include:
          - php: ${{ needs.php-matrix.outputs.highest }}
            dependency-versions: highest
            coverage: xdebug
    steps:
      - uses: actions/checkout@v4

      - uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          coverage: ${{ matrix.coverage }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - uses: ramsey/composer-install@v3
        with:
          dependency-versions: ${{ matrix.dependency-versions }}

      - run: composer test:with-coverage
        if: ${{ matrix.coverage == 'xdebug' }}

      - run: composer test:without-coverage
        if: ${{ matrix.coverage != 'xdebug' }}

Credits

PHP Matrix Action is a Typist Tech project and maintained by Tang Rufus, freelance developer for hire.

Full list of contributors can be found on GitHub.

Copyright and License

This project is a free software distributed under the terms of the MIT license. For the full license, see LICENSE.

Contribute

Feedbacks / bug reports / pull requests are welcome.

PHP Matrix is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.

About

Generate PHP version matrix according to composer.json
v1.0.4
Latest

PHP Matrix is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.