From 2a597f617d3f945788ed413b9b93fec904d62e5a Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Tue, 29 Jul 2025 02:08:56 +0530 Subject: [PATCH] Fix race condition --- src/scripts/tools/add_tools.ps1 | 8 ++++---- src/scripts/tools/add_tools.sh | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/scripts/tools/add_tools.ps1 b/src/scripts/tools/add_tools.ps1 index 46c99757..3402a16d 100644 --- a/src/scripts/tools/add_tools.ps1 +++ b/src/scripts/tools/add_tools.ps1 @@ -28,8 +28,8 @@ Function Edit-ComposerConfig() { Set-ComposerAuth } -# Function to merge auth.json fragments. -Function Get-MergedAuthJson { +# Function to update auth.json. +Function Update-AuthJson { [CmdletBinding()] param( [Parameter(Mandatory)][string[]] $ComposerAuth @@ -58,7 +58,7 @@ Function Get-MergedAuthJson { } } } - return $existing | ConvertTo-Json -Depth 5 + Set-Content -Path $composer_home\auth.json -Value ($existing | ConvertTo-Json -Depth 5) } # Function to setup authentication in composer. @@ -81,7 +81,7 @@ Function Set-ComposerAuth() { $composer_auth += '"github-oauth": {"github.com": "' + $env:GITHUB_TOKEN + '"}' } if($composer_auth.length) { - Set-Content -Path $composer_home\auth.json -Value (Get-MergedAuthJson $composer_auth) + Update-AuthJson $composer_auth } } diff --git a/src/scripts/tools/add_tools.sh b/src/scripts/tools/add_tools.sh index 7f8e3896..3163cc0c 100644 --- a/src/scripts/tools/add_tools.sh +++ b/src/scripts/tools/add_tools.sh @@ -47,7 +47,7 @@ configure_composer() { } # Function to merge auth.json fragments. -get_merged_auth_json() { +update_auth_json() { local auth_file="$composer_home/auth.json" local merged [[ -f "$auth_file" ]] && merged=$(<"$auth_file") || merged='{}' @@ -62,7 +62,7 @@ get_merged_auth_json() { end ') done - printf '%s' "$merged" + printf '%s' "$merged" > "$composer_home/auth.json" } # Function to setup authentication in composer. @@ -82,7 +82,7 @@ set_composer_auth() { composer_auth+=( '"github-oauth": {"github.com": "'"${GITHUB_TOKEN:-$COMPOSER_TOKEN}"'"}' ) fi if ((${#composer_auth[@]})); then - get_merged_auth_json "${composer_auth[@]}" | tee "$composer_home/auth.json" >/dev/null + update_auth_json "${composer_auth[@]}" fi }