Files
actions/php-version-detect/action.yml
Ismo Vuorinen 74968d942f chore: update action references for release v2025.10.26 (#312)
This commit updates all internal action references to point to the current
commit SHA in preparation for release v2025.10.26.
2025-10-27 00:00:02 +02:00

78 lines
2.5 KiB
YAML

# yaml-language-server: $schema=https://json.schemastore.org/github-action.json
# permissions:
# - contents: read # Required for reading version files
---
name: PHP Version Detect
description: "Detects the PHP version from the project's composer.json, phpunit.xml, or other configuration files."
author: 'Ismo Vuorinen'
branding:
icon: code
color: purple
inputs:
default-version:
description: 'Default PHP version to use if no version is detected.'
required: false
default: '8.2'
token:
description: 'GitHub token for authentication'
required: false
default: ''
outputs:
php-version:
description: 'Detected or default PHP version.'
value: ${{ steps.parse-version.outputs.detected-version }}
runs:
using: composite
steps:
- name: Validate Inputs
id: validate
shell: bash
env:
DEFAULT_VERSION: ${{ inputs.default-version }}
run: |
set -euo pipefail
# Validate default-version format
if ! [[ "$DEFAULT_VERSION" =~ ^[0-9]+\.[0-9]+(\.[0-9]+)?$ ]]; then
echo "::error::Invalid default-version format: '$DEFAULT_VERSION'. Expected format: X.Y or X.Y.Z (e.g., 8.2, 8.3.1)"
exit 1
fi
# Check for reasonable version range (prevent malicious inputs)
major_version=$(echo "$DEFAULT_VERSION" | cut -d'.' -f1)
if [ "$major_version" -lt 7 ] || [ "$major_version" -gt 9 ]; then
echo "::error::Invalid default-version: '$DEFAULT_VERSION'. PHP major version should be between 7 and 9"
exit 1
fi
# Check minor version range for PHP 8
if [ "$major_version" -eq 8 ]; then
minor_version=$(echo "$DEFAULT_VERSION" | cut -d'.' -f2)
if [ "$minor_version" -lt 0 ] || [ "$minor_version" -gt 4 ]; then
echo "::error::Invalid default-version: '$DEFAULT_VERSION'. PHP 8 minor version should be between 0 and 4"
exit 1
fi
fi
echo "Input validation completed successfully"
- name: Checkout Repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
token: ${{ inputs.token || github.token }}
- name: Parse PHP Version
id: parse-version
uses: ivuorinen/actions/version-file-parser@e2222afff180ee77f330ef4325f60d6e85477c01
with:
language: 'php'
tool-versions-key: 'php'
dockerfile-image: 'php'
version-file: '.php-version'
validation-regex: '^[0-9]+\.[0-9]+(\.[0-9]+)?$'
default-version: ${{ inputs.default-version }}