PHP Version Fetcher #477
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: PHP Version Fetcher | |
| on: | |
| schedule: | |
| - cron: '0 0 * * *' # Scheduled: fetches updates from the last 48 hours | |
| workflow_dispatch: | |
| inputs: | |
| minimum_version: | |
| description: 'Fetch versions starting from (if not 0.0.0, ignores date limit)' | |
| required: false | |
| default: '0.0.0' | |
| jobs: | |
| extract-php-versions: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| versions: ${{ steps.filter-versions.outputs.versions }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Fetch and process PHP CLI tarballs | |
| id: filter-versions | |
| env: | |
| MIN_VER: ${{ github.event.inputs.minimum_version || '0.0.0' }} | |
| run: | | |
| echo "🔍 Fetching data from static-php.dev... (Filter: >= $MIN_VER)" | |
| curl -sS "https://dl.static-php.dev/static-php-cli/bulk/?format=json" | \ | |
| jq -r --arg min_v "$MIN_VER" ' | |
| # Parse the input minimum version into an array of numbers once | |
| ($min_v | split(".") | map(tonumber)) as $min_v_arr | | |
| .[] | | |
| # Filter only for files matching the PHP CLI pattern | |
| select(.is_dir == false and (.name | test("php-[0-9]+\\.[0-9]+\\.[0-9]+-cli-.+\\.tar\\.gz"))) | | |
| # Extract version components | |
| (.name | capture("php-(?<a>[0-9]+)\\.(?<b>[0-9]+)\\.(?<c>[0-9]+)-cli-")) as $v | | |
| # Create a comparable version array and formatted string | |
| ([$v.a, $v.b, $v.c] | map(tonumber)) as $curr_v_arr | | |
| "\($v.a).\($v.b).\($v.c)" as $v_str | | |
| # Determine if we should include this version | |
| select( | |
| if $min_v == "0.0.0" then | |
| # Cron mode: Last 48 hours (172800 seconds) | |
| ((.last_modified | strptime("%Y-%m-%d %H:%M:%S") | mktime) > (now - 172800)) | |
| else | |
| # Manual mode: Semantic version comparison (Array comparison) | |
| ($curr_v_arr >= $min_v_arr) | |
| end | |
| ) | | |
| $v_str | |
| ' | sort -uV > php_versions.txt | |
| if [ -s php_versions.txt ]; then | |
| count=$(wc -l < php_versions.txt) | |
| echo "✅ Success: Found $count versions matching the range." | |
| # Safety cap for GitHub Matrix limits | |
| if [ "$count" -gt 250 ]; then | |
| echo "⚠️ Capping output to 250 versions for matrix stability." | |
| head -n 250 php_versions.txt > temp.txt && mv temp.txt php_versions.txt | |
| fi | |
| cat php_versions.txt | |
| # Generate JSON array for the next job | |
| versions=$(jq -R -s -c 'split("\n") | map(select(length > 0))' php_versions.txt) | |
| echo "versions=$versions" >> $GITHUB_OUTPUT | |
| else | |
| echo "ℹ️ No versions found for the specified criteria." | |
| echo "versions=[]" >> $GITHUB_OUTPUT | |
| fi | |
| dispatch-releases: | |
| needs: extract-php-versions | |
| runs-on: ubuntu-latest | |
| if: needs.extract-php-versions.outputs.versions != '[]' | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| version: ${{ fromJSON(needs.extract-php-versions.outputs.versions) }} | |
| permissions: | |
| contents: read | |
| actions: write | |
| steps: | |
| - name: Dispatch release workflow for PHP ${{ matrix.version }} | |
| uses: benc-uk/workflow-dispatch@v1 | |
| with: | |
| workflow: php-release.yml | |
| inputs: '{ "version": "${{ matrix.version }}" }' |