@@ -28,6 +28,39 @@ Function Edit-ComposerConfig() {
28
28
Set-ComposerAuth
29
29
}
30
30
31
+ # Function to merge auth.json fragments.
32
+ Function Get-MergedAuthJson {
33
+ [CmdletBinding ()]
34
+ param (
35
+ [Parameter (Mandatory )][string []] $ComposerAuth
36
+ )
37
+ if (Test-Path $composer_home \auth.json) {
38
+ try {
39
+ $existing = Get-Content $composer_home \auth.json - Raw | ConvertFrom-Json
40
+ } catch {
41
+ $existing = [PSCustomObject ]@ {}
42
+ }
43
+ } else {
44
+ $existing = [PSCustomObject ]@ {}
45
+ }
46
+ foreach ($fragment in $ComposerAuth ) {
47
+ $piece = (' {' + $fragment + ' }' ) | ConvertFrom-Json
48
+ foreach ($prop in $piece.PSObject.Properties ) {
49
+ if ($prop.Name -eq ' http-basic' ) {
50
+ if (-not $existing .' http-basic' ) {
51
+ $existing | Add-Member - MemberType NoteProperty - Name ' http-basic' - Value ([PSCustomObject ]@ {}) - Force
52
+ }
53
+ foreach ($domainProp in $prop.Value.PSObject.Properties ) {
54
+ $existing .' http-basic' | Add-Member - MemberType NoteProperty - Name $domainProp.Name - Value $domainProp.Value - Force
55
+ }
56
+ } else {
57
+ $existing | Add-Member - MemberType NoteProperty - Name $prop.Name - Value $prop.Value - Force
58
+ }
59
+ }
60
+ }
61
+ return $existing | ConvertTo-Json - Depth 5
62
+ }
63
+
31
64
# Function to setup authentication in composer.
32
65
Function Set-ComposerAuth () {
33
66
if (Test-Path env:COMPOSER_AUTH_JSON) {
@@ -48,7 +81,7 @@ Function Set-ComposerAuth() {
48
81
$composer_auth += ' "github-oauth": {"github.com": "' + $env: GITHUB_TOKEN + ' "}'
49
82
}
50
83
if ($composer_auth.length ) {
51
- Add-Env COMPOSER_AUTH ( ' { ' + ( $composer_auth -join ' , ' ) + ' } ' )
84
+ Set-Content - Path $composer_home \auth.json - Value ( Get-MergedAuthJson $composer_auth )
52
85
}
53
86
}
54
87
0 commit comments