2020-11-02 18:03:14 +07:00
|
|
|
# Variables
|
|
|
|
export tick="✓"
|
|
|
|
export cross="✗"
|
2021-12-08 22:04:44 +07:00
|
|
|
export curl_opts=(-sL)
|
2020-11-02 18:03:14 +07:00
|
|
|
export old_versions="5.[3-5]"
|
2020-12-17 22:19:20 +07:00
|
|
|
export jit_versions="8.[0-9]"
|
2021-12-06 11:43:24 +07:00
|
|
|
export nightly_versions="8.[2-9]"
|
2020-12-17 22:19:20 +07:00
|
|
|
export xdebug3_versions="7.[2-4]|8.[0-9]"
|
2020-11-02 18:03:14 +07:00
|
|
|
export latest="releases/latest/download"
|
|
|
|
export github="https://github.com/shivammathur"
|
2021-04-13 04:41:08 +07:00
|
|
|
export jsdeliver="https://cdn.jsdelivr.net/gh/shivammathur"
|
2021-12-08 22:04:44 +07:00
|
|
|
export setup_php="https://setup-php.com"
|
2020-11-02 18:03:14 +07:00
|
|
|
|
|
|
|
# Function to log start of a operation.
|
|
|
|
step_log() {
|
|
|
|
message=$1
|
|
|
|
printf "\n\033[90;1m==> \033[0m\033[37;1m%s\033[0m\n" "$message"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Function to log result of a operation.
|
|
|
|
add_log() {
|
|
|
|
mark=$1
|
|
|
|
subject=$2
|
|
|
|
message=$3
|
|
|
|
if [ "$mark" = "$tick" ]; then
|
|
|
|
printf "\033[32;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
|
|
|
|
else
|
|
|
|
printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
|
2021-03-17 10:16:13 +07:00
|
|
|
[ "$fail_fast" = "true" ] && exit 1
|
2020-11-02 18:03:14 +07:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Function to read env inputs.
|
|
|
|
read_env() {
|
2022-01-12 22:45:11 +07:00
|
|
|
update="${update:-${UPDATE:-false}}"
|
|
|
|
fail_fast="${fail_fast:-${FAIL_FAST:-false}}"
|
|
|
|
[[ -z "${ImageOS}" && -z "${ImageVersion}" ]] && _runner=self-hosted || _runner=github
|
|
|
|
runner="${runner:-${RUNNER:-$_runner}}"
|
2020-11-02 18:03:14 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
# Function to download a file using cURL.
|
|
|
|
# mode: -s pipe to stdout, -v save file and return status code
|
|
|
|
# execute: -e save file as executable
|
|
|
|
get() {
|
|
|
|
mode=$1
|
|
|
|
execute=$2
|
|
|
|
file_path=$3
|
|
|
|
shift 3
|
|
|
|
links=("$@")
|
|
|
|
if [ "$mode" = "-s" ]; then
|
|
|
|
sudo curl "${curl_opts[@]}" "${links[0]}"
|
|
|
|
else
|
|
|
|
for link in "${links[@]}"; do
|
|
|
|
status_code=$(sudo curl -w "%{http_code}" -o "$file_path" "${curl_opts[@]}" "$link")
|
|
|
|
[ "$status_code" = "200" ] && break
|
|
|
|
done
|
|
|
|
[ "$execute" = "-e" ] && sudo chmod a+x "$file_path"
|
|
|
|
[ "$mode" = "-v" ] && echo "$status_code"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-01-11 07:34:19 +07:00
|
|
|
# Function to get shell profile.
|
|
|
|
get_shell_profile() {
|
|
|
|
case "$SHELL" in
|
|
|
|
*bash*)
|
|
|
|
echo "${HOME}/.bashrc"
|
|
|
|
;;
|
|
|
|
*zsh*)
|
|
|
|
echo "${HOME}/.zshrc"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "${HOME}/.profile"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
# Function to add a path to the PATH variable.
|
|
|
|
add_path() {
|
|
|
|
path_to_add=$1
|
|
|
|
[ ! -d "$path_to_add" ] && [[ ":$PATH:" == *":$path_to_add:"* ]] && return
|
|
|
|
if [[ -n "$GITHUB_PATH" ]]; then
|
|
|
|
echo "$path_to_add" | tee -a "$GITHUB_PATH" >/dev/null 2>&1
|
|
|
|
else
|
|
|
|
profile=$(get_shell_profile)
|
|
|
|
([ -e "$profile" ] && grep -q ":$path_to_add\"" "$profile" 2>/dev/null) || echo "export PATH=\"\${PATH:+\${PATH}:}\"$path_to_add" | sudo tee -a "$profile" >/dev/null 2>&1
|
|
|
|
fi
|
|
|
|
export PATH="${PATH:+${PATH}:}$path_to_add"
|
|
|
|
}
|
|
|
|
|
2022-01-18 06:11:51 +07:00
|
|
|
# Function to add environment variables using a PATH.
|
|
|
|
add_env_path() {
|
|
|
|
env_path=$1
|
|
|
|
[ -e "$env_path" ] || return
|
|
|
|
if [[ -n "$GITHUB_ENV" ]]; then
|
|
|
|
cat "$env_path" >> "$GITHUB_ENV"
|
|
|
|
else
|
|
|
|
profile=$(get_shell_profile)
|
|
|
|
cat "$env_path" >> "$profile"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Function to add an environment variable.
|
|
|
|
add_env() {
|
|
|
|
env_name=$1
|
|
|
|
env_value=$2
|
|
|
|
if [[ -n "$GITHUB_ENV" ]]; then
|
|
|
|
echo "$env_name=$env_value" | tee -a "$GITHUB_ENV" >/dev/null 2>&1
|
|
|
|
else
|
|
|
|
profile=$(get_shell_profile)
|
|
|
|
echo "export $env_name=\"$env_value\"" | sudo tee -a "$profile" >/dev/null 2>&1
|
|
|
|
fi
|
|
|
|
export "$env_name"="$env_value"
|
|
|
|
}
|
|
|
|
|
2021-04-13 04:41:08 +07:00
|
|
|
# Function to download and run scripts from GitHub releases with jsdeliver fallback.
|
2020-11-02 18:03:14 +07:00
|
|
|
run_script() {
|
|
|
|
repo=$1
|
|
|
|
shift
|
|
|
|
args=("$@")
|
2021-12-08 22:04:44 +07:00
|
|
|
get -q -e /tmp/install.sh "$github/$repo/$latest/install.sh" "$jsdeliver/$repo@main/scripts/install.sh" "$setup_php/$repo/install.sh"
|
2020-11-02 18:03:14 +07:00
|
|
|
bash /tmp/install.sh "${args[@]}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Function to install required packages on self-hosted runners.
|
|
|
|
self_hosted_setup() {
|
|
|
|
if [ "$runner" = "self-hosted" ]; then
|
|
|
|
if [[ "${version:?}" =~ $old_versions ]]; then
|
|
|
|
add_log "$cross" "PHP" "PHP $version is not supported on self-hosted runner"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
self_hosted_helper >/dev/null 2>&1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-12-17 22:19:20 +07:00
|
|
|
# Function to configure PHP
|
|
|
|
configure_php() {
|
2022-01-25 15:13:49 +07:00
|
|
|
add_php_config
|
2022-01-02 20:37:31 +07:00
|
|
|
ini_config_dir="${dist:?}"/../src/configs/ini
|
|
|
|
ini_files=("$ini_config_dir"/php.ini)
|
|
|
|
[[ "$version" =~ $jit_versions ]] && ini_files+=("$ini_config_dir"/jit.ini)
|
|
|
|
[[ "$version" =~ $xdebug3_versions ]] && ini_files+=("$ini_config_dir"/xdebug.ini)
|
|
|
|
cat "${ini_files[@]}" | sudo tee -a "${pecl_file:-${ini_file[@]}}" >/dev/null 2>&1
|
2020-12-17 22:19:20 +07:00
|
|
|
}
|
|
|
|
|
2020-11-02 18:03:14 +07:00
|
|
|
# Function to get PHP version in semver format.
|
|
|
|
php_semver() {
|
2022-01-16 13:33:31 +07:00
|
|
|
grep -Eo 'version="[0-9]+(\.[0-9]+){2}((-?[a-zA-Z]+([0-9]+)?)?){2}' "${php_config:?}" | cut -d '"' -f 2
|
2021-01-25 19:39:13 +07:00
|
|
|
}
|
|
|
|
|
2022-01-18 10:14:46 +07:00
|
|
|
# Function to get ini_path.
|
|
|
|
php_ini_path() {
|
|
|
|
cut -d '"' -f 2 < <(grep "ini_path=" "$php_config" || php --ini | grep '(php.ini)' | sed -e "s|.*: s*||")
|
|
|
|
}
|
|
|
|
|
2021-02-22 20:10:19 +07:00
|
|
|
# Function to get the tag for a php version.
|
|
|
|
php_src_tag() {
|
2021-09-19 04:24:02 +07:00
|
|
|
commit=$(php_extra_version | grep -Eo "[0-9a-zA-Z]+")
|
|
|
|
if [[ -n "${commit}" ]]; then
|
|
|
|
echo "$commit"
|
|
|
|
else
|
2022-01-02 18:51:14 +07:00
|
|
|
echo "php-${semver:?}"
|
2021-02-22 20:10:19 +07:00
|
|
|
fi
|
|
|
|
}
|