mirror of
				https://github.com/shivammathur/setup-php.git
				synced 2025-10-31 07:16:22 +07:00 
			
		
		
		
	Refactor setting environment variables
This commit is contained in:
		| @ -22,10 +22,10 @@ Function Edit-ComposerConfig() { | ||||
|   if (-not(Test-Path $composer_json)) { | ||||
|     Set-Content -Path $composer_json -Value "{}" | ||||
|   } | ||||
|   Get-Content -Path $dist\..\src\configs\composer.env | Add-Content -Path $env:GITHUB_ENV | ||||
|   Add-EnvPATH $dist\..\src\configs\composer.env | ||||
|   Add-Path $composer_bin | ||||
|   if (Test-Path env:COMPOSER_TOKEN) { | ||||
|     composer -q config -g github-oauth.github.com $env:COMPOSER_TOKEN | ||||
|     Add-Env COMPOSER_AUTH ('{"github-oauth": {"github.com": "' + $env:COMPOSER_TOKEN + '"}}') | ||||
|   } | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -42,10 +42,10 @@ configure_composer() { | ||||
|     echo '{}' | tee "$composer_json" >/dev/null | ||||
|     chmod 644 "$composer_json" | ||||
|   fi | ||||
|   cat "${dist:?}"/../src/configs/composer.env >> "$GITHUB_ENV" | ||||
|   add_env_path "${dist:?}"/../src/configs/composer.env | ||||
|   add_path "$composer_bin" | ||||
|   if [ -n "$COMPOSER_TOKEN" ]; then | ||||
|     composer -q config -g github-oauth.github.com "$COMPOSER_TOKEN" | ||||
|     add_env COMPOSER_AUTH '{"github-oauth": {"github.com": "'"$COMPOSER_TOKEN"'"}}' | ||||
|   fi | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -87,6 +87,31 @@ add_path() { | ||||
|   export PATH="${PATH:+${PATH}:}$path_to_add" | ||||
| } | ||||
|  | ||||
| # 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" | ||||
| } | ||||
|  | ||||
| # Function to download and run scripts from GitHub releases with jsdeliver fallback. | ||||
| run_script() { | ||||
|   repo=$1 | ||||
|  | ||||
| @ -77,6 +77,34 @@ Function Add-Path { | ||||
|   } | ||||
| } | ||||
|  | ||||
| # Function to add an environment variable. | ||||
| Function Add-Env { | ||||
|   param( | ||||
|     [string]$EnvName, | ||||
|     [string]$EnvValue | ||||
|   ) | ||||
|   if ($env:GITHUB_ENV) { | ||||
|     Add-Content "$EnvName=$EnvValue" -Path $env:GITHUB_ENV -Encoding utf8 | ||||
|   } else { | ||||
|     Set-ItemProperty -Path 'hkcu:\Environment' -Name $EnvName -Value $EnvValue | ||||
|   } | ||||
| } | ||||
|  | ||||
| # Function to add environment variables using a PATH. | ||||
| Function Add-EnvPATH { | ||||
|   param( | ||||
|     [string]$EnvPATH | ||||
|   ) | ||||
|   if(-not(Test-Path $EnvPATH)) { | ||||
|     return | ||||
|   } | ||||
|   $env_file = $current_profile | ||||
|   if ($env:GITHUB_ENV) { | ||||
|     $env_file = $env:GITHUB_ENV | ||||
|   } | ||||
|   Get-Content -Path $EnvPATH | Add-Content -Path $env_file -Encoding utf8 | ||||
| } | ||||
|  | ||||
| # Function to make sure printf is in PATH. | ||||
| Function Add-Printf { | ||||
|   if (-not(Test-Path "C:\Program Files\Git\usr\bin\printf.exe")) { | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Shivam Mathur
					Shivam Mathur