From c9d28bca6042dee5293e1883189770e1055eff34 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 2 Apr 2025 17:38:00 +0200 Subject: [PATCH 1/6] =?UTF-8?q?=F0=9F=9A=80=20[Feature]:=20Add=20support?= =?UTF-8?q?=20for=20setting=20local=20environment=20variables=20in=20`Get-?= =?UTF-8?q?GitHubVariable`=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public/Variables/Get-GitHubVariable.ps1 | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/functions/public/Variables/Get-GitHubVariable.ps1 b/src/functions/public/Variables/Get-GitHubVariable.ps1 index ceb091599..5c951a5c0 100644 --- a/src/functions/public/Variables/Get-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Get-GitHubVariable.ps1 @@ -150,6 +150,10 @@ function Get-GitHubVariable { [Parameter()] [switch] $IncludeInherited, + # Set the environment variables locally for the current session. + [Parameter()] + [switch] $SetLocalEnvironment, + # The context to run the command in. Used to get the details for the API call. # Can be either a string or a GitHubContext object. [Parameter()] @@ -215,6 +219,31 @@ function Get-GitHubVariable { break } } + + if ($IncludeInherited) { + $variables = $variables | Group-Object -Property Name | ForEach-Object { + $group = $_.Group + $envVar = $group | Where-Object { $_.Environment } + if ($envVar) { + $envVar + } else { + $repoVar = $group | Where-Object { $_.Repository -and (-not $_.Environment) } + if ($repoVar) { + $repoVar + } else { + $group | Where-Object { (-not $_.Repository) -and (-not $_.Environment) } + } + } + } + } + + if ($SetLocalEnvironment) { + Write-Debug 'Set local environment variables:' + $variables | ForEach-Object { + [System.Environment]::SetEnvironmentVariable($_.Name, $_.Value, 'Process') + Write-Debug "$($_.Name) = $($_.Value)" + } + } $variables } From 47dd4f6c834722fa79382075864a1b52ea4768dc Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 2 Apr 2025 17:38:03 +0200 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20PSModule?= =?UTF-8?q?.yml=20to=20skip=20documentation=20and=20test=20builds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/PSModule.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/PSModule.yml b/.github/PSModule.yml index 6d578178e..fe434d07e 100644 --- a/.github/PSModule.yml +++ b/.github/PSModule.yml @@ -1,3 +1,7 @@ +Build: + Docs: + Skip: true Test: + Skip: true CodeCoverage: PercentTarget: 50 From 1860e1e78bc5fa088376e03ca0f5c82abf10da78 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 2 Apr 2025 17:49:01 +0200 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=9A=80=20[Feature]:=20Add=20support?= =?UTF-8?q?=20for=20listing=20all=20variables=20in=20`Get-GitHubVariable`?= =?UTF-8?q?=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Variables/Get-GitHubVariable.ps1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/functions/public/Variables/Get-GitHubVariable.ps1 b/src/functions/public/Variables/Get-GitHubVariable.ps1 index 5c951a5c0..70fb6e28e 100644 --- a/src/functions/public/Variables/Get-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Get-GitHubVariable.ps1 @@ -150,6 +150,10 @@ function Get-GitHubVariable { [Parameter()] [switch] $IncludeInherited, + # List all variables, including those that are overwritten by inheritance. + [Parameter()] + [switch] $All, + # Set the environment variables locally for the current session. [Parameter()] [switch] $SetLocalEnvironment, @@ -220,7 +224,7 @@ function Get-GitHubVariable { } } - if ($IncludeInherited) { + if ($IncludeInherited -and -not $All) { $variables = $variables | Group-Object -Property Name | ForEach-Object { $group = $_.Group $envVar = $group | Where-Object { $_.Environment } From a445771d1a1d0b6405dabf4e65ba3d0b13a30a66 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 2 Apr 2025 18:24:05 +0200 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=9A=80=20[Feature]:=20Add=20example?= =?UTF-8?q?=20script=20for=20managing=20GitHub=20variables=20and=20enhance?= =?UTF-8?q?=20error=20handling=20in=20`Get-GitHubVariable`=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/PSModule.yml | 9 +++++---- examples/Actions/Variables.ps1 | 17 +++++++++++++++++ .../public/Variables/Get-GitHubVariable.ps1 | 16 ++++++++++++---- tests/Variables.Tests.ps1 | 5 ----- 4 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 examples/Actions/Variables.ps1 diff --git a/.github/PSModule.yml b/.github/PSModule.yml index fe434d07e..7f9339481 100644 --- a/.github/PSModule.yml +++ b/.github/PSModule.yml @@ -1,7 +1,8 @@ -Build: - Docs: - Skip: true Test: - Skip: true + Module: + Windows: + Skip: true + MacOS: + Skip: true CodeCoverage: PercentTarget: 50 diff --git a/examples/Actions/Variables.ps1 b/examples/Actions/Variables.ps1 new file mode 100644 index 000000000..2c510693d --- /dev/null +++ b/examples/Actions/Variables.ps1 @@ -0,0 +1,17 @@ +$owner = 'PSModule' +$repo = 'GitHub' +$environment = 'test' + +Set-GitHubEnvironment -Owner $Owner -Repository $Repo -Name $environment + +Set-GitHubVariable -Owner $Owner -Name 'TestVariable' -Value 'Organization' -Visibility all +Get-GitHubVariable -Owner $Owner -IncludeInherited # Should have the value 'Organization' + +Set-GitHubVariable -Owner $Owner -Repository $Repo -Name 'TestVariable' -Value 'Repository' +Get-GitHubVariable -Owner $Owner -Repository $Repo -IncludeInherited # Should have the value 'Repository' + +Set-GitHubVariable -Owner $Owner -Repository $Repo -Environment $environment -Name 'TestVariable' -Value 'Environment' +Get-GitHubVariable -Owner $Owner -Repository $Repo -Environment $environment -IncludeInherited # Should have the value 'Environment' +Get-GitHubVariable -Owner $Owner -Repository $Repo -Environment $environment -IncludeInherited -All + +Get-GitHubVariable -Owner $Owner -Repository $Repo -Environment $environment -IncludeInherited -All -Name 'Test*' | Remove-GitHubVariable diff --git a/src/functions/public/Variables/Get-GitHubVariable.ps1 b/src/functions/public/Variables/Get-GitHubVariable.ps1 index 70fb6e28e..cdd9e5a09 100644 --- a/src/functions/public/Variables/Get-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Get-GitHubVariable.ps1 @@ -183,7 +183,9 @@ function Get-GitHubVariable { $variables += Get-GitHubVariableOwnerList @params | Where-Object { $_.Name -like $Name } } else { - $variables += Get-GitHubVariableOwnerByName @params -Name $Name + try { + $variables += Get-GitHubVariableOwnerByName @params -Name $Name + } catch { $null } } break } @@ -197,7 +199,9 @@ function Get-GitHubVariable { $variables += Get-GitHubVariableRepositoryList @params | Where-Object { $_.Name -like $Name } } else { - $variables += Get-GitHubVariableRepositoryByName @params -Name $Name + try { + $variables += Get-GitHubVariableRepositoryByName @params -Name $Name + } catch { $null } } break } @@ -210,7 +214,9 @@ function Get-GitHubVariable { $variables += Get-GitHubVariableRepositoryList @params | Where-Object { $_.Name -like $Name } } else { - $variables += Get-GitHubVariableRepositoryByName @params -Name $Name + try { + $variables += Get-GitHubVariableRepositoryByName @params -Name $Name + } catch { $null } } } $params['Environment'] = $Environment @@ -218,7 +224,9 @@ function Get-GitHubVariable { $variables += Get-GitHubVariableEnvironmentList @params | Where-Object { $_.Name -like $Name } } else { - $variables += Get-GitHubVariableEnvironmentByName @params -Name $Name + try { + $variables += Get-GitHubVariableEnvironmentByName @params -Name $Name + } catch { $null } } break } diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index c1ca2c444..5f61ee116 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -201,11 +201,6 @@ Describe 'Environments' { } Context 'SelectedRepository' { - BeforeEach { - LogGroup 'Sleep 15 seconds' { - Start-Sleep -Seconds 15 - } - } It 'Get-GitHubVariableSelectedRepository - gets a list of selected repositories' { LogGroup "SelectedRepositories - [$varName]" { $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName From 1794644134a804499a0dc5b813dba45fe4478796 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 2 Apr 2025 18:45:57 +0200 Subject: [PATCH 5/6] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Mark=20'SelectedR?= =?UTF-8?q?epository'=20context=20as=20flaky=20in=20Variables.Tests.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 5f61ee116..82edd7347 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -200,7 +200,7 @@ Describe 'Environments' { $after.Count | Should -Be 0 } - Context 'SelectedRepository' { + Context 'SelectedRepository' -Tag 'Flaky' { It 'Get-GitHubVariableSelectedRepository - gets a list of selected repositories' { LogGroup "SelectedRepositories - [$varName]" { $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName From 353d0873d8043c1399ed552da5cbe5a261f2b587 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 2 Apr 2025 21:00:10 +0200 Subject: [PATCH 6/6] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20skip=20c?= =?UTF-8?q?onfiguration=20for=20Windows=20and=20MacOS=20in=20PSModule.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/PSModule.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/PSModule.yml b/.github/PSModule.yml index 7f9339481..6d578178e 100644 --- a/.github/PSModule.yml +++ b/.github/PSModule.yml @@ -1,8 +1,3 @@ Test: - Module: - Windows: - Skip: true - MacOS: - Skip: true CodeCoverage: PercentTarget: 50