name: Build PHARs

on:
  # Run on pushes to the main branches and on pull requests which touch files used when building the PHARs.
  # Prevent the build from running when there are only irrelevant changes.
  push:
    branches:
      - 3.x
      - 4.x
    paths:
      - '.github/workflows/build-phar.yml'
      - '.github/workflows/reusable-build-phar.yml'
      - 'scripts/build-phar.php'
      - 'autoload.php'
      - 'src/Config.php'
      - 'src/Exceptions/RuntimeException.php'
      - 'src/Exceptions/TokenizerException.php'
      - 'src/Tokenizers/PHP.php'
      - 'src/Util/Tokens.php'
  pull_request:
    paths:
      - '.github/workflows/build-phar.yml'
      - '.github/workflows/reusable-build-phar.yml'
      - 'scripts/build-phar.php'
      - 'autoload.php'
      - 'src/Config.php'
      - 'src/Exceptions/RuntimeException.php'
      - 'src/Exceptions/TokenizerException.php'
      - 'src/Tokenizers/PHP.php'
      - 'src/Util/Tokens.php'

  # Allow manually triggering the workflow.
  workflow_dispatch:

# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
  # The concurrency group contains the workflow name and the branch name.
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build:
    strategy:
      matrix:
        # Deliberately missing PHP 8.0 as that PHAR is build and used in the test workflow.
        php: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.1', '8.2', '8.3', '8.4', 'nightly']

    name: "Build Phar on PHP: ${{ matrix.php }}"

    uses: ./.github/workflows/reusable-build-phar.yml
    with:
      phpVersion: ${{ matrix.php }}
