Repository navigation
Expand file tree
/
Copy pathrelease.sh
More file actions
74 lines (65 loc) · 2.54 KB
/
Copy pathrelease.sh
File metadata and controls
74 lines (65 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bash
# Function to update the build log
log_build() {
gh release download "$PHP_VERSION" -p "build.log" || true
date '+%Y.%m.%d' | sudo tee -a build.log
assets+=("./build.log")
}
# Function to get the latest stable release tag for a PHP version.
get_github_release_tag() {
github_headers=()
[ -n "${GITHUB_TOKEN:-}" ] && github_headers=(-H "Authorization: Bearer $GITHUB_TOKEN")
curl "${github_headers[@]}" -sL "https://api.github.com/repos/php/php-src/git/matching-refs/tags%2Fphp-$PHP_VERSION." | grep -Eo "php-[0-9]+\.[0-9]+\.[0-9]+\"" | sort -V | tail -1 | cut -d '"' -f 1 || true
}
get_stable_release_tag() {
source=$1
if [ "$source" = "--web-php" ]; then
release_tag="$(curl -sL https://www.php.net/releases/feed.php | grep -Po -m 1 "php-(${PHP_VERSION//./\\.}\.[0-9]+)" | head -n 1)"
release_tag="${release_tag:-$(curl -sL https://www.php.net/releases | grep -Po "${PHP_VERSION//./\\.}\.[0-9]+" | head -n1 | sed 's/^/php-/')}"
echo "${release_tag:-$(get_github_release_tag)}"
else
get_github_release_tag
fi
}
# Function to get the PHP version from a branch.
get_version_from_branch() {
curl -sL https://raw.githubusercontent.com/php/php-src/"$1"/main/php_version.h | grep -Po 'PHP_VERSION "\K[0-9]+\.[0-9]+\.[0-9][0-9a-zA-Z-]*' 2>/dev/null || true
}
# Function to update the PHP version log
log_version() {
assets+=("scripts/install.sh")
new_version=$(get_stable_release_tag "$PHP_SOURCE")
if [ "$new_version" = "" ]; then
new_version=$(get_version_from_branch PHP-"$PHP_VERSION")
if [ "$new_version" = "" ]; then
new_version=$(get_version_from_branch master)
fi
fi
echo "$new_version" > "php$PHP_VERSION.log"
assets+=("./php$PHP_VERSION.log")
}
# Exit if commit message has skip-release.
[[ "$GITHUB_MESSAGE" = *skip-release* ]] && exit 0;
# Remove intermediate builds.
rm -rf ./builds/php-sapi* ./builds/php-base* ./builds/php-extensions*
IFS=' ' read -r -a PHP_VERSIONS <<<"${PHP_LIST:?}"
for PHP_VERSION in "${PHP_VERSIONS[@]}"; do
# Build assets array with builds.
shopt -s nullglob
assets=()
for asset in ./builds/*/php_"$PHP_VERSION"*; do
assets+=("$asset")
done
shopt -u nullglob
if [ "${#assets[@]}" -ne 0 ]; then
# Update logs.
log_version
log_build
# Create or update release.
if ! gh release view "$PHP_VERSION"; then
bash scripts/retry.sh 5 5 gh release create "$PHP_VERSION" "${assets[@]}" -t "$PHP_VERSION" -n "$PHP_VERSION"
else
bash scripts/retry.sh 5 5 gh release upload "$PHP_VERSION" "${assets[@]}" --clobber
fi
fi
done