mirror of
https://github.com/shivammathur/setup-php.git
synced 2026-10-15 20:06:58 +00:00
Allow opt-in builds cache on Blacksmith and Depot runners
This commit is contained in:
3 files changed
+32
-2
No files matched your search
@@ -206,7 +206,7 @@ add_php() {
|
||||
php_keg="php@$version$suffix"
|
||||
php_formula="shivammathur/php/$php_keg"
|
||||
if [[ "$existing_version" = "false" || -n "$suffix" || "$action" = "upgrade" ]]; then
|
||||
if [ "$(uname -m)" = "x86_64" ] || { [ "${runner:?}" != "self-hosted" ] && [ "${use_package_cache:-true}" != "false" ]; }; then
|
||||
if [ "$(uname -m)" = "x86_64" ] || { [ "${runner:?}" != "self-hosted" ] && [ "${use_builds_cache:-true}" != "false" ]; }; then
|
||||
setup_cached_versions && return 0
|
||||
[ "$(uname -m)" != "x86_64" ] || return 1
|
||||
fi
|
||||
|
||||
@@ -226,7 +226,7 @@ update_php() {
|
||||
|
||||
# Function to install PHP.
|
||||
add_php() {
|
||||
if [ "${runner:?}" = "self-hosted" ] || [ "${use_package_cache:-true}" = "false" ]; then
|
||||
if [ "${runner:?}" = "self-hosted" ] || [ "${use_builds_cache:-true}" = "false" ]; then
|
||||
if [[ "$version" =~ ${php_builder_versions:?} || "$ts" = "zts" ]]; then
|
||||
setup_php_builder
|
||||
else
|
||||
@@ -285,6 +285,9 @@ add_php_config() {
|
||||
# Function to Setup PHP
|
||||
setup_php() {
|
||||
step_log "Setup PHP"
|
||||
if [ "${builds_cache_warning:-false}" = "true" ]; then
|
||||
add_log "!" "PHP" "Cached PHP builds are experimental on this runner and may fail to install"
|
||||
fi
|
||||
sudo mkdir -m 777 -p /var/run /run/php
|
||||
php_config="$(command -v php-config)"
|
||||
check_pre_installed
|
||||
|
||||
@@ -33,6 +33,8 @@ add_log() {
|
||||
local 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"
|
||||
elif [ "$mark" = "!" ]; then
|
||||
printf "\033[33;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"
|
||||
[ "$fail_fast" = "true" ] && exit 1
|
||||
@@ -58,6 +60,22 @@ without_trace() {
|
||||
return "$setup_php_trace_status"
|
||||
}
|
||||
|
||||
# Function to check third-party runners eligible for the builds cache.
|
||||
check_builds_cache_runner() {
|
||||
local pid=$PPID executable
|
||||
while [[ "$pid" =~ ^[0-9]+$ && "$pid" -gt 1 ]]; do
|
||||
executable="$(readlink -f "/proc/$pid/exe")" || return 1
|
||||
if [[ "$executable" = */bin/Runner.Worker ]]; then
|
||||
jq -e --arg name "${RUNNER_NAME:-}" \
|
||||
'.AgentName == $name and (.AgentName | test("^(blacksmith|depot)-"))' \
|
||||
"${executable%/bin/Runner.Worker}/.runner" >/dev/null 2>&1
|
||||
return $?
|
||||
fi
|
||||
pid="$(awk '$1 == "PPid:" {print $2}' "/proc/$pid/status")" || return 1
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# Function to read env inputs.
|
||||
read_env() {
|
||||
if [[ "${SETUP_PHP_TRACE:-0}" =~ ^[12]$ ]]; then
|
||||
@@ -67,10 +85,19 @@ read_env() {
|
||||
[ "${debug:-${DEBUG:-false}}" = "true" ] && debug=debug && update=true || debug=release
|
||||
[[ "${phpts:-${PHPTS:-nts}}" = "ts" || "${phpts:-${PHPTS:-nts}}" = "zts" ]] && ts=zts && update=true || ts=nts
|
||||
fail_fast="${fail_fast:-${FAIL_FAST:-false}}"
|
||||
use_builds_cache="${use_builds_cache:-${use_package_cache:-}}"
|
||||
[[ ( -z "$ImageOS" && -z "$ImageVersion" ) ||
|
||||
( -n "$RUNNER_ENVIRONMENT" && "$RUNNER_ENVIRONMENT" = "self-hosted" ) ||
|
||||
-n "$ACT" || -n "$CONTAINER" ]] && _runner=self-hosted || _runner=github
|
||||
runner="${runner:-${RUNNER:-$_runner}}"
|
||||
if [[ $_runner = "self-hosted" && "${use_builds_cache:-false}" = "true" ]]; then
|
||||
runner=github
|
||||
if [[ "${ID:-}" = "ubuntu" && -z "$ACT" && -z "$CONTAINER" &&
|
||||
( -n "${BLACKSMITH_VM_ID:-}" || "${RUNNER_NAME:-}" =~ ^(blacksmith|depot)- ) ]] && check_builds_cache_runner; then
|
||||
_runner=github
|
||||
builds_cache_warning=true
|
||||
fi
|
||||
fi
|
||||
tool_path_dir="${setup_php_tools_dir:-${SETUP_PHP_TOOLS_DIR:-/usr/local/bin}}"
|
||||
tool_cache_path_dir="${setup_php_tool_cache_dir:-${SETUP_PHP_TOOL_CACHE_DIR:-${RUNNER_TOOL_CACHE:-/opt/hostedtoolcache}/setup-php/tools}}"
|
||||
|
||||
|
||||
Reference in new issue
Block a user