Skip to content

Commit ba6c124

Browse files
committed
ci: fallback on gh when the php.net API is down
1 parent cda58d2 commit ba6c124

2 files changed

Lines changed: 35 additions & 7 deletions

File tree

.github/workflows/sanitizers.yaml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,24 @@ jobs:
5151
caddy/go.sum
5252
- name: Determine PHP version
5353
id: determine-php-version
54+
env:
55+
GH_TOKEN: ${{ github.token }}
5456
run: |
55-
curl -fsSL 'https://www.php.net/releases/index.php?json&max=1&version=8.5' -o version.json
56-
echo version="$(jq -r 'keys[0]' version.json)" >> "$GITHUB_OUTPUT"
57-
echo archive="$(jq -r '.[] .source[] | select(.filename |endswith(".xz")) | "https://www.php.net/distributions/" + .filename' version.json)" >> "$GITHUB_OUTPUT"
57+
# Try php.net API first
58+
if curl -fsSL 'https://www.php.net/releases/index.php?json&max=1&version=8.5' -o version.json 2>/dev/null; then
59+
version="$(jq -r 'keys[0]' version.json)"
60+
archive="$(jq -r '.[] .source[] | select(.filename |endswith(".xz")) | "https://www.php.net/distributions/" + .filename' version.json)"
61+
if [ -n "$version" ] && [ "$version" != "null" ] && [ -n "$archive" ] && [ "$archive" != "null" ]; then
62+
echo "version=$version" >> "$GITHUB_OUTPUT"
63+
echo "archive=$archive" >> "$GITHUB_OUTPUT"
64+
exit 0
65+
fi
66+
fi
67+
68+
# Fallback: use the latest GitHub release from php/php-src
69+
version=$(gh release list --repo php/php-src --exclude-drafts --exclude-pre-releases --json tagName --jq '[.[].tagName | select(startswith("php-8.5."))] | first | ltrimstr("php-")')
70+
echo "version=$version" >> "$GITHUB_OUTPUT"
71+
echo "archive=https://github.com/php/php-src/archive/refs/tags/php-${version}.tar.gz" >> "$GITHUB_OUTPUT"
5872
- name: Cache PHP
5973
id: cache-php
6074
uses: actions/cache@v5
@@ -65,7 +79,10 @@ jobs:
6579
name: Compile PHP
6680
run: |
6781
mkdir php/
68-
curl -fsSL "${URL}" | tar -Jx -C php --strip-components=1
82+
case "${URL}" in
83+
*.xz) curl -fsSL "${URL}" | tar -Jx -C php --strip-components=1 ;;
84+
*) curl -fsSL "${URL}" | tar -zx -C php --strip-components=1 ;;
85+
esac
6986
cd php/
7087
./configure \
7188
CFLAGS="$CFLAGS" \

build-static.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,25 @@ fi
6262
if [ -z "${PHP_VERSION}" ]; then
6363
get_latest_php_version() {
6464
input="$1"
65+
# Try php.net API first
6566
json=$(curl -s "https://www.php.net/releases/index.php?json&version=$input")
66-
latest=$(echo "$json" | jq -r '.version')
67+
latest=$(echo "$json" | jq -r '.version' 2>/dev/null)
6768

6869
if [[ "$latest" == "$input"* ]]; then
6970
echo "$latest"
70-
else
71-
echo "$input"
71+
return
7272
fi
73+
74+
# Fallback: use the latest GitHub release from php/php-src
75+
if type "gh" >/dev/null 2>&1; then
76+
latest=$(gh release list --repo php/php-src --exclude-drafts --exclude-pre-releases --json tagName --jq "[.[].tagName | select(startswith(\"php-${input}.\"))] | first | ltrimstr(\"php-\")")
77+
fi
78+
if [[ "$latest" == "$input"* ]]; then
79+
echo "$latest"
80+
return
81+
fi
82+
83+
echo "$input"
7384
}
7485

7586
PHP_VERSION="$(get_latest_php_version "8.5")"

0 commit comments

Comments
 (0)