From 5c3a4dacf6cf84be97e90f05ab2fe67ce956c211 Mon Sep 17 00:00:00 2001 From: Jacob Ransom Date: Fri, 21 Aug 2026 09:30:42 +1200 Subject: [PATCH] Extract the PHP version alias table into a shared script The table was inline in action.yml, so nothing outside this action could resolve the aliases without copying the numbers. --- README.md | 2 +- action.yml | 26 ++++++------------------ scripts/bash/resolve_php_version.sh | 31 +++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 21 deletions(-) create mode 100755 scripts/bash/resolve_php_version.sh diff --git a/README.md b/README.md index ff23811..1fe35e2 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ This action is able to run certain test suites for Matomo or any Matomo plugin. Defines the PHP version to set up for testing. (Not needed for Client tests) - Use `matomo5_min_php`/`matomo5_max_php` (Matomo 5) or `matomo6_min_php`/`matomo6_max_php` (Matomo 6) to resolve to the centrally managed (defined in action.yml) minimum or maximum PHP versions supported by Matomo tests. + Use `matomo5_min_php`/`matomo5_max_php` (Matomo 5) or `matomo6_min_php`/`matomo6_max_php` (Matomo 6) to resolve to the centrally managed minimum or maximum PHP versions supported by Matomo tests. The alias table is `scripts/bash/resolve_php_version.sh`, so anything else needing these versions can resolve the same table instead of copying it. The action uses `shivammathur/setup-php` to set up PHP. You can find supported PHP versions here: https://github.com/shivammathur/setup-php#tada-php-support diff --git a/action.yml b/action.yml index bdbf78a..2b2ade1 100644 --- a/action.yml +++ b/action.yml @@ -194,27 +194,13 @@ runs: - name: Resolve PHP version id: resolve-php shell: bash + # the alias table lives in scripts/bash/resolve_php_version.sh so anything else needing + # these versions resolves the same table instead of copying it. The input arrives through + # the environment rather than an expression, so a caller's value is never expanded as shell. + env: + PHP_VERSION_INPUT: ${{ inputs.php-version }} run: | - case "${{ inputs.php-version }}" in - matomo5_min_php) - RESOLVED_VERSION="7.2" - ;; - matomo5_max_php) - RESOLVED_VERSION="8.5" - ;; - matomo6_min_php) - RESOLVED_VERSION="8.1" - ;; - matomo6_max_php) - RESOLVED_VERSION="8.5" - ;; - '') - exit 0 - ;; - *) - RESOLVED_VERSION="${{ inputs.php-version }}" - ;; - esac + RESOLVED_VERSION=$("${{ github.action_path }}/scripts/bash/resolve_php_version.sh" "$PHP_VERSION_INPUT") echo "version=$RESOLVED_VERSION" >> "$GITHUB_OUTPUT" diff --git a/scripts/bash/resolve_php_version.sh b/scripts/bash/resolve_php_version.sh new file mode 100755 index 0000000..863ee29 --- /dev/null +++ b/scripts/bash/resolve_php_version.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Resolves the centrally managed PHP version aliases to concrete versions, so that a caller can +# track a Matomo major's floor or ceiling without repeating the number. Anything unrecognised is +# echoed back unchanged, which is what lets callers pass a literal version such as 8.2. Empty +# input echoes empty, which callers use to mean "do not set PHP up at all". +# +# Keeping the table in a script rather than inline in action.yml lets anything else that needs +# these versions — including workflows in other repositories, which can check this repository +# out — resolve the same table instead of copying it. A copy drifts exactly when a floor moves, +# which is the moment the value matters. + +case "$1" in + matomo5_min_php) + RESOLVED_VERSION="7.2" + ;; + matomo5_max_php) + RESOLVED_VERSION="8.5" + ;; + matomo6_min_php) + RESOLVED_VERSION="8.1" + ;; + matomo6_max_php) + RESOLVED_VERSION="8.5" + ;; + *) + RESOLVED_VERSION="$1" + ;; +esac + +printf '%s' "$RESOLVED_VERSION"