mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-25 21:13:04 +07:00
Improve source extension setup logs
Refactor source extension setup code to src/scripts/ext/source.sh
This commit is contained in:
parent
b3152daa8d
commit
39faaac1d3
@ -29,7 +29,7 @@ add_log() {
|
|||||||
printf "\033[32;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
|
printf "\033[32;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
|
||||||
else
|
else
|
||||||
printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
|
printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
|
||||||
[ "$fail_fast" = "true" ] && exit 1;
|
[ "$fail_fast" = "true" ] && exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,7 +217,7 @@ configure_composer() {
|
|||||||
sudo chmod 644 "$composer_json"
|
sudo chmod 644 "$composer_json"
|
||||||
fi
|
fi
|
||||||
composer -q config -g process-timeout 0
|
composer -q config -g process-timeout 0
|
||||||
echo "$composer_bin" >> "$GITHUB_PATH"
|
echo "$composer_bin" >>"$GITHUB_PATH"
|
||||||
if [ -n "$COMPOSER_TOKEN" ]; then
|
if [ -n "$COMPOSER_TOKEN" ]; then
|
||||||
composer -q config -g github-oauth.github.com "$COMPOSER_TOKEN"
|
composer -q config -g github-oauth.github.com "$COMPOSER_TOKEN"
|
||||||
fi
|
fi
|
||||||
@ -229,14 +229,14 @@ add_tool() {
|
|||||||
tool=$2
|
tool=$2
|
||||||
ver_param=$3
|
ver_param=$3
|
||||||
tool_path="$tool_path_dir/$tool"
|
tool_path="$tool_path_dir/$tool"
|
||||||
if ! [[ "$PATH" =~ $tool_path_dir ]] ; then
|
if ! [[ "$PATH" =~ $tool_path_dir ]]; then
|
||||||
export PATH=$PATH:"$tool_path_dir"
|
export PATH=$PATH:"$tool_path_dir"
|
||||||
echo "export PATH=\$PATH:$tool_path_dir" | sudo tee -a "$GITHUB_ENV" >/dev/null
|
echo "export PATH=\$PATH:$tool_path_dir" | sudo tee -a "$GITHUB_ENV" >/dev/null
|
||||||
fi
|
fi
|
||||||
if [ ! -e "$tool_path" ]; then
|
if [ ! -e "$tool_path" ]; then
|
||||||
rm -rf "$tool_path"
|
rm -rf "$tool_path"
|
||||||
fi
|
fi
|
||||||
IFS="," read -r -a url <<< "$url"
|
IFS="," read -r -a url <<<"$url"
|
||||||
status_code=$(get -v -e "$tool_path" "${url[@]}")
|
status_code=$(get -v -e "$tool_path" "${url[@]}")
|
||||||
if [ "$status_code" != "200" ] && [[ "${url[0]}" =~ .*github.com.*releases.*latest.* ]]; then
|
if [ "$status_code" != "200" ] && [[ "${url[0]}" =~ .*github.com.*releases.*latest.* ]]; then
|
||||||
url[0]="${url[0]//releases\/latest\/download/releases/download/$(get -s -n "" "$(echo "${url[0]}" | cut -d '/' -f '1-5')/releases" | grep -Eo -m 1 "([0-9]+\.[0-9]+\.[0-9]+)/$(echo "${url[0]}" | sed -e "s/.*\///")" | cut -d '/' -f 1)}"
|
url[0]="${url[0]//releases\/latest\/download/releases/download/$(get -s -n "" "$(echo "${url[0]}" | cut -d '/' -f '1-5')/releases" | grep -Eo -m 1 "([0-9]+\.[0-9]+\.[0-9]+)/$(echo "${url[0]}" | sed -e "s/.*\///")" | cut -d '/' -f 1)}"
|
||||||
@ -290,59 +290,3 @@ php_src_tag() {
|
|||||||
fi
|
fi
|
||||||
echo "$php_src_tag"
|
echo "$php_src_tag"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to parse extension environment variables
|
|
||||||
parse_args() {
|
|
||||||
extension=$1
|
|
||||||
suffix=$2
|
|
||||||
up_extension=$(echo "$extension" | tr '[:lower:]' '[:upper:]')
|
|
||||||
var="${extension}_${suffix}"
|
|
||||||
up_var="${up_extension}_${suffix}"
|
|
||||||
output=$(echo "${!var} ${!up_var}" | sed "s/, */ /g")
|
|
||||||
echo "$output" | xargs -n 1 | sort | uniq | xargs
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to add required libraries
|
|
||||||
add_libs() {
|
|
||||||
libs=("$@")
|
|
||||||
if [ "$(uname -s)" = "Linux" ]; then
|
|
||||||
install_packages "${libs[@]}"
|
|
||||||
else
|
|
||||||
brew install "${libs[@]}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to install extension from a git repository
|
|
||||||
add_extension_from_source() {
|
|
||||||
extension=$1
|
|
||||||
domain=$2
|
|
||||||
org=$3
|
|
||||||
repo=$4
|
|
||||||
sub_dir=$5
|
|
||||||
release=$6
|
|
||||||
prefix=$7
|
|
||||||
slug="$extension-$release"
|
|
||||||
IFS=' ' read -r -a libs <<< "$(parse_args "$extension" LIBS)"
|
|
||||||
IFS=' ' read -r -a opts <<< "$(parse_args "$extension" CONFIGURE_OPTS)"
|
|
||||||
IFS=' ' read -r -a prefix_opts <<< "$(parse_args "$extension" CONFIGURE_PREFIX_OPTS)"
|
|
||||||
IFS=' ' read -r -a suffix_opts <<< "$(parse_args "$extension" CONFIGURE_SUFFIX_OPTS)"
|
|
||||||
printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "$slug" "Click for $extension installation logs"
|
|
||||||
(
|
|
||||||
add_devtools phpize >/dev/null
|
|
||||||
delete_extension "$extension"
|
|
||||||
git clone -q -n "$domain/$org/$repo" /tmp/"$repo-$release"
|
|
||||||
cd /tmp/"$repo-$release/$sub_dir" || exit 1
|
|
||||||
git checkout -q "$release"
|
|
||||||
if [ "$(find . -maxdepth 1 -name '*.m4' -exec grep -H 'PHP_NEW_EXTENSION' {} \;| wc -l)" != "0" ]; then
|
|
||||||
git submodule -q update --init --recursive
|
|
||||||
add_libs "${libs[@]}"
|
|
||||||
phpize && sudo "${prefix_opts[@]}" ./configure "${suffix_opts[@]}" "${opts[@]}"
|
|
||||||
sudo make -j"$(nproc 2>/dev/null || sysctl -n hw.ncpu)" && sudo make install
|
|
||||||
enable_extension "$extension" "$prefix"
|
|
||||||
else
|
|
||||||
add_log "$cross" "$domain/$org/$repo" "Provided repository does not contain a PHP extension"
|
|
||||||
fi
|
|
||||||
)
|
|
||||||
echo "::endgroup::"
|
|
||||||
add_extension_log "$slug" "Installed and enabled from $domain/$org/$repo"
|
|
||||||
}
|
|
||||||
|
@ -197,6 +197,7 @@ export HOMEBREW_NO_AUTO_UPDATE=1
|
|||||||
export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
|
export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
|
||||||
|
|
||||||
# shellcheck source=.
|
# shellcheck source=.
|
||||||
|
. "${scripts:?}"/ext/source.sh
|
||||||
. "${scripts:?}"/tools/add_tools.sh
|
. "${scripts:?}"/tools/add_tools.sh
|
||||||
. "${scripts:?}"/common.sh
|
. "${scripts:?}"/common.sh
|
||||||
read_env
|
read_env
|
||||||
|
85
src/scripts/ext/source.sh
Normal file
85
src/scripts/ext/source.sh
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
# Function to parse extension environment variables
|
||||||
|
parse_args() {
|
||||||
|
extension=$1
|
||||||
|
suffix=$2
|
||||||
|
up_extension=$(echo "$extension" | tr '[:lower:]' '[:upper:]')
|
||||||
|
var="${extension}_${suffix}"
|
||||||
|
up_var="${up_extension}_${suffix}"
|
||||||
|
output=$(echo "${!var} ${!up_var}" | sed "s/, */ /g")
|
||||||
|
echo "$output" | xargs -n 1 | sort | uniq | xargs
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to log if a library is installed
|
||||||
|
add_lib_log() {
|
||||||
|
lib=$1
|
||||||
|
output=$2
|
||||||
|
if [ "x$output" != "x" ]; then
|
||||||
|
add_log "${tick:?}" "$lib" "Installed"
|
||||||
|
else
|
||||||
|
add_log "${cross:?}" "$lib" "Could not install $lib"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to add required libraries
|
||||||
|
add_libs() {
|
||||||
|
libs=("$@")
|
||||||
|
for lib in "${libs[@]}"; do
|
||||||
|
if [ "$(uname -s)" = "Linux" ]; then
|
||||||
|
install_packages "$lib" >/dev/null 2>&1
|
||||||
|
add_lib_log "$lib" "$(dpkg -s "$lib" 2>/dev/null | grep Status)"
|
||||||
|
else
|
||||||
|
brew install "$lib" >/dev/null 2>&1
|
||||||
|
add_lib_log "$lib" "$(find "${brew_cellar:?}" -maxdepth 1 -name "$lib")"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to run command in a group
|
||||||
|
run_group() {
|
||||||
|
command=$1
|
||||||
|
log=$2
|
||||||
|
echo "$command" | sudo tee ./run_group.sh >/dev/null 2>&1
|
||||||
|
echo "::group::$log"
|
||||||
|
. ./run_group.sh
|
||||||
|
rm ./run_group.sh
|
||||||
|
echo "::endgroup::"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to install extension from a git repository
|
||||||
|
add_extension_from_source() {
|
||||||
|
extension=$1
|
||||||
|
domain=$2
|
||||||
|
org=$3
|
||||||
|
repo=$4
|
||||||
|
sub_dir=$5
|
||||||
|
release=$6
|
||||||
|
prefix=$7
|
||||||
|
slug="$extension-$release"
|
||||||
|
libraries="$(parse_args "$extension" LIBS)"
|
||||||
|
opts="$(parse_args "$extension" CONFIGURE_OPTS)"
|
||||||
|
prefix_opts="$(parse_args "$extension" CONFIGURE_PREFIX_OPTS)"
|
||||||
|
suffix_opts="$(parse_args "$extension" CONFIGURE_SUFFIX_OPTS)"
|
||||||
|
step_log "Setup $slug"
|
||||||
|
(
|
||||||
|
add_devtools phpize >/dev/null
|
||||||
|
delete_extension "$extension"
|
||||||
|
run_group "git clone -nv $domain/$org/$repo /tmp/$repo-$release" "git clone"
|
||||||
|
cd /tmp/"$repo-$release/$sub_dir" || exit 1
|
||||||
|
git checkout -q "$release"
|
||||||
|
if ! [ "$(find . -maxdepth 1 -name '*.m4' -exec grep -H 'PHP_NEW_EXTENSION' {} \; | wc -l)" != "0" ]; then
|
||||||
|
add_log "${cross:?}" "$domain/$org/$repo" "$domain/$org/$repo does not have a PHP extension"
|
||||||
|
else
|
||||||
|
if [ -e .gitmodules ]; then
|
||||||
|
jobs="$(grep -c "\[submodule" .gitmodules)"
|
||||||
|
run_group "git submodule update --jobs $jobs --init --recursive" "git submodule"
|
||||||
|
fi
|
||||||
|
[ "x$libraries" != "x" ] && run_group "add_libs $libraries" "add libraries"
|
||||||
|
run_group "phpize" "phpize"
|
||||||
|
run_group "sudo $prefix_opts ./configure $suffix_opts $opts" "configure"
|
||||||
|
run_group "sudo make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu)" "make"
|
||||||
|
run_group "sudo make install" "make install"
|
||||||
|
enable_extension "$extension" "$prefix"
|
||||||
|
fi
|
||||||
|
)
|
||||||
|
add_extension_log "$slug" "Installed from $domain/$org/$repo and enabled"
|
||||||
|
}
|
@ -287,6 +287,7 @@ apt_remove="sudo $debconf_fix apt-fast remove -y"
|
|||||||
scripts="${dist}"/../src/scripts
|
scripts="${dist}"/../src/scripts
|
||||||
|
|
||||||
# shellcheck source=.
|
# shellcheck source=.
|
||||||
|
. "${scripts:?}"/ext/source.sh
|
||||||
. "${scripts:?}"/tools/add_tools.sh
|
. "${scripts:?}"/tools/add_tools.sh
|
||||||
. "${scripts:?}"/common.sh
|
. "${scripts:?}"/common.sh
|
||||||
. /etc/lsb-release
|
. /etc/lsb-release
|
||||||
|
Loading…
Reference in New Issue
Block a user