From 6268015b3a4d3b80f668d4b146fdb5d01edf1ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Thu, 5 Mar 2026 17:50:21 +0100 Subject: [PATCH] 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. --- .github/workflows/sanitizers.yaml | 5 +++-- .github/workflows/tests.yaml | 2 +- build-static.sh | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/sanitizers.yaml b/.github/workflows/sanitizers.yaml index fe2f2d25..5ba8813b 100644 --- a/.github/workflows/sanitizers.yaml +++ b/.github/workflows/sanitizers.yaml @@ -52,7 +52,7 @@ jobs: - name: Determine PHP version id: determine-php-version 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 archive="$(jq -r '.[] .source[] | select(.filename |endswith(".xz")) | "https://www.php.net/distributions/" + .filename' version.json)" >> "$GITHUB_OUTPUT" - name: Cache PHP @@ -65,7 +65,8 @@ jobs: name: Compile PHP run: | 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/ ./configure \ CFLAGS="$CFLAGS" \ diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 44443883..407d9fb0 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -129,7 +129,7 @@ jobs: - name: Download PHP sources run: | 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" echo "GEN_STUB_SCRIPT=${PWD}/php-${PHP_VERSION}/build/gen_stub.php" >> "${GITHUB_ENV}" - name: Set CGO flags diff --git a/build-static.sh b/build-static.sh index a507e722..429c8376 100755 --- a/build-static.sh +++ b/build-static.sh @@ -62,7 +62,7 @@ fi if [ -z "${PHP_VERSION}" ]; then get_latest_php_version() { 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') if [[ "$latest" == "$input"* ]]; then