ci: fallback on static-php.dev mirror when php.net is down (#2233)

Unfortunately, GitHub Actions is often blocked by the php.net CDN. This
patch adds a fallback to use GitHub to try to determine the PHP version
to use. This is less ideal because PHP currently doesn't use GitHub
extensively, and distribution archives aren't available in the GitHub
releases, only on php.net.
This commit is contained in:
Kévin Dunglas
2026-03-05 17:50:21 +01:00
committed by GitHub
parent 356d2e1745
commit 6268015b3a
3 changed files with 5 additions and 4 deletions

View File

@@ -52,7 +52,7 @@ jobs:
- name: Determine PHP version - name: Determine PHP version
id: determine-php-version id: determine-php-version
run: | run: |
curl -fsSL 'https://www.php.net/releases/index.php?json&max=1&version=8.5' -o version.json curl -fsSL 'https://www.php.net/releases/index.php?json&max=1&version=8.5' -o version.json 2>/dev/null || curl -fsSL 'https://phpmirror.static-php.dev/releases/index.php?json&max=1&version=8.5' -o version.json
echo version="$(jq -r 'keys[0]' version.json)" >> "$GITHUB_OUTPUT" echo version="$(jq -r 'keys[0]' version.json)" >> "$GITHUB_OUTPUT"
echo archive="$(jq -r '.[] .source[] | select(.filename |endswith(".xz")) | "https://www.php.net/distributions/" + .filename' version.json)" >> "$GITHUB_OUTPUT" echo archive="$(jq -r '.[] .source[] | select(.filename |endswith(".xz")) | "https://www.php.net/distributions/" + .filename' version.json)" >> "$GITHUB_OUTPUT"
- name: Cache PHP - name: Cache PHP
@@ -65,7 +65,8 @@ jobs:
name: Compile PHP name: Compile PHP
run: | run: |
mkdir php/ mkdir php/
curl -fsSL "${URL}" | tar -Jx -C php --strip-components=1 MIRROR_URL=${URL/https:\/\/www.php.net/https:\/\/phpmirror.static-php.dev}
(curl -fsSL "${URL}" || curl -fsSL "${MIRROR_URL}") | tar -Jx -C php --strip-components=1
cd php/ cd php/
./configure \ ./configure \
CFLAGS="$CFLAGS" \ CFLAGS="$CFLAGS" \

View File

@@ -129,7 +129,7 @@ jobs:
- name: Download PHP sources - name: Download PHP sources
run: | run: |
PHP_VERSION=$(php -r "echo PHP_VERSION;") PHP_VERSION=$(php -r "echo PHP_VERSION;")
wget -q "https://www.php.net/distributions/php-${PHP_VERSION}.tar.gz" wget -q "https://www.php.net/distributions/php-${PHP_VERSION}.tar.gz" || wget -q "https://phpmirror.static-php.dev/distributions/php-${PHP_VERSION}.tar.gz"
tar xzf "php-${PHP_VERSION}.tar.gz" tar xzf "php-${PHP_VERSION}.tar.gz"
echo "GEN_STUB_SCRIPT=${PWD}/php-${PHP_VERSION}/build/gen_stub.php" >> "${GITHUB_ENV}" echo "GEN_STUB_SCRIPT=${PWD}/php-${PHP_VERSION}/build/gen_stub.php" >> "${GITHUB_ENV}"
- name: Set CGO flags - name: Set CGO flags

View File

@@ -62,7 +62,7 @@ fi
if [ -z "${PHP_VERSION}" ]; then if [ -z "${PHP_VERSION}" ]; then
get_latest_php_version() { get_latest_php_version() {
input="$1" input="$1"
json=$(curl -s "https://www.php.net/releases/index.php?json&version=$input") json=$(curl -fsSL "https://www.php.net/releases/index.php?json&version=$input" 2>/dev/null || curl -fsSL "https://phpmirror.static-php.dev/releases/index.php?json&version=$input")
latest=$(echo "$json" | jq -r '.version') latest=$(echo "$json" | jq -r '.version')
if [[ "$latest" == "$input"* ]]; then if [[ "$latest" == "$input"* ]]; then