Skip to content

Commit 6268015

Browse files
authored
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.
1 parent 356d2e1 commit 6268015

3 files changed

Lines changed: 5 additions & 4 deletions

File tree

.github/workflows/sanitizers.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
- name: Determine PHP version
5353
id: determine-php-version
5454
run: |
55-
curl -fsSL 'https://www.php.net/releases/index.php?json&max=1&version=8.5' -o version.json
55+
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
5656
echo version="$(jq -r 'keys[0]' version.json)" >> "$GITHUB_OUTPUT"
5757
echo archive="$(jq -r '.[] .source[] | select(.filename |endswith(".xz")) | "https://www.php.net/distributions/" + .filename' version.json)" >> "$GITHUB_OUTPUT"
5858
- name: Cache PHP
@@ -65,7 +65,8 @@ jobs:
6565
name: Compile PHP
6666
run: |
6767
mkdir php/
68-
curl -fsSL "${URL}" | tar -Jx -C php --strip-components=1
68+
MIRROR_URL=${URL/https:\/\/www.php.net/https:\/\/phpmirror.static-php.dev}
69+
(curl -fsSL "${URL}" || curl -fsSL "${MIRROR_URL}") | tar -Jx -C php --strip-components=1
6970
cd php/
7071
./configure \
7172
CFLAGS="$CFLAGS" \

.github/workflows/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ jobs:
129129
- name: Download PHP sources
130130
run: |
131131
PHP_VERSION=$(php -r "echo PHP_VERSION;")
132-
wget -q "https://www.php.net/distributions/php-${PHP_VERSION}.tar.gz"
132+
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"
133133
tar xzf "php-${PHP_VERSION}.tar.gz"
134134
echo "GEN_STUB_SCRIPT=${PWD}/php-${PHP_VERSION}/build/gen_stub.php" >> "${GITHUB_ENV}"
135135
- name: Set CGO flags

build-static.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fi
6262
if [ -z "${PHP_VERSION}" ]; then
6363
get_latest_php_version() {
6464
input="$1"
65-
json=$(curl -s "https://www.php.net/releases/index.php?json&version=$input")
65+
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")
6666
latest=$(echo "$json" | jq -r '.version')
6767

6868
if [[ "$latest" == "$input"* ]]; then

0 commit comments

Comments
 (0)