generate-matrix.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. #!/bin/bash
  2. ###################################################
  3. # Usage: generate-matrix.sh
  4. ###################################################
  5. # This script is used to generate the GitHub Actions
  6. # matrix for the PHP versions and OS combinations.
  7. #
  8. # 👉 REQUIRED FILES
  9. # - PHP_VERSIONS_FILE must be valid and set to a valid file path
  10. # (defaults to scripts/conf/php-versions.yml)
  11. set -euo pipefail
  12. # Path to the PHP versions configuration file
  13. PHP_VERSIONS_FILE="${PHP_VERSIONS_FILE:-"scripts/conf/php-versions.yml"}"
  14. # Generate and output the MATRIX_JSON
  15. yq -o=json "$PHP_VERSIONS_FILE" |
  16. jq -c '{
  17. include: [
  18. (.php_variations[] |
  19. {name, supported_os: (.supported_os // ["alpine", "bullseye", "bookworm"]), excluded_minor_versions: (.excluded_minor_versions // [])}
  20. ) as $variation |
  21. .php_versions[] |
  22. .minor_versions[] |
  23. # Check if the minor version is not in the excluded list for the variation
  24. select([.minor] | inside($variation.excluded_minor_versions | map(.)) | not) |
  25. .patch_versions[] as $patch |
  26. .base_os[] as $os |
  27. select($variation.supported_os | if length == 0 then . else . | index($os.name) end) |
  28. {patch_version: $patch, base_os: $os.name, php_variation: $variation.name}
  29. ]
  30. } |
  31. {include: (.include | sort_by(.patch_version | split(".") | map(tonumber) | . as $nums | ($nums[0]*10000 + $nums[1]*100 + $nums[2])) | reverse)}'