Fix paths for bin tools and scoped tools [skip ci]

This commit is contained in:
Shivam Mathur
2026-01-23 01:04:38 +05:30
parent 341bc9e176
commit 1eee54fe48
3 changed files with 17 additions and 7 deletions

View File

@@ -176,10 +176,14 @@ add_tool() {
if ! [ -d "$tool_path_dir" ]; then
sudo mkdir -p "$tool_path_dir"
fi
add_path "$tool_path_dir"
if ! [ -d "$tool_cache_path_dir" ]; then
sudo mkdir -p "$tool_cache_path_dir"
fi
add_path "$tool_path_dir" verify
add_path "$tool_cache_path_dir"
IFS="," read -r -a url <<<"$url"
cache_key=$(get_sha256 "${url[0]}" | head -c 16)
cache_path="/tmp/${tool}-${cache_key}"
cache_path="$tool_cache_path_dir/${tool}-${cache_key}"
status_code="200"
if [ -f "$cache_path" ]; then
sudo cp -a "$cache_path" "$tool_path"
@@ -199,6 +203,7 @@ add_tool() {
fi
if [ "$status_code" = "200" ]; then
add_tools_helper "$tool"
[ -L "$tool_cache_path_dir/$tool" ] || sudo ln -s "$tool_path" "$tool_cache_path_dir/$tool" 2>/dev/null || true
tool_version=$(get_tool_version "$tool" "$ver_param")
add_log "${tick:?}" "$tool" "Added $tool $tool_version"
else

View File

@@ -58,6 +58,7 @@ read_env() {
-n "$ACT" || -n "$CONTAINER" ]] && _runner=self-hosted || _runner=github
runner="${runner:-${RUNNER:-$_runner}}"
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}}"
if [[ "$runner" = "github" && $_runner = "self-hosted" ]]; then
fail_fast=true
@@ -79,6 +80,7 @@ read_env() {
export update
export ts
export tool_path_dir
export tool_cache_path_dir
}
# Function to create a lock.
@@ -169,14 +171,15 @@ get_shell_profile() {
# Function to add a path to the PATH variable.
add_path() {
path_to_add=$1
[[ ":$PATH:" == *":$path_to_add:"* ]] && return
action=$2
[[ "$action" == "verify" && ":$PATH:" == *":$path_to_add:"* ]] && return
if [[ -n "$GITHUB_PATH" ]]; then
echo "$path_to_add" | tee -a "$GITHUB_PATH" >/dev/null 2>&1
printf '%s\n%s' "$path_to_add" "$(grep -v "^${path_to_add}$" "$GITHUB_PATH" 2>/dev/null)" > "$GITHUB_PATH"
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"
[[ ":$PATH:" == *":$path_to_add:"* ]] || export PATH="${PATH:+${PATH}:}$path_to_add"
}
# Function to add environment variables using a PATH.

View File

@@ -81,9 +81,10 @@ Function Get-PathFromRegistry {
# Function to add a location to PATH.
Function Add-Path {
param(
[string]$PathItem
[string]$PathItem,
[switch]$Force
)
if("$env:PATH;".contains("$PathItem;")) {
if(-not($Force) -and "$env:PATH;".contains("$PathItem;")) {
return
}
if ($env:GITHUB_PATH) {
@@ -375,6 +376,7 @@ if(-not($env:ImageOS) -and -not($env:ImageVersion)) {
if(-not(Test-Path -LiteralPath $current_profile)) {
New-Item -Path $current_profile -ItemType "file" -Force >$null 2>&1
}
Add-Path -PathItem $bin_dir -Force
}
$src = Join-Path -Path $PSScriptRoot -ChildPath \..