From c92431913f3e3cfe268d6e5ed0e44e5be1a2014b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 9 Nov 2024 19:45:01 +0100 Subject: [PATCH 1/9] Make store 0.3 compatible --- action.yml | 2 -- scripts/main.ps1 | 13 +++++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index a6d86d2..93c11ef 100644 --- a/action.yml +++ b/action.yml @@ -12,7 +12,6 @@ inputs: Token: description: The access token to use. required: false - default: ${{ github.token }} Debug: description: Enable debug output. required: false @@ -48,5 +47,4 @@ runs: run: | # GitHub-Script . "${{ github.action_path }}\scripts\main.ps1" - ${{ inputs.Script }} diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 8567f7e..60d7ac8 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -8,8 +8,6 @@ if ($env:GITHUB_ACTION_INPUT_Verbose -eq 'true') { $VerbosePreference = 'Continue' } -Install-PSResource -Name 'Store' -Version 0.2.2 -Repository PSGallery -TrustRepository - $Name = 'GitHub' $Version = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version) ? $null : $env:GITHUB_ACTION_INPUT_Version $Prerelease = $env:GITHUB_ACTION_INPUT_Prerelease -eq 'true' @@ -51,3 +49,14 @@ if (-not $alreadyImported) { Write-Verbose "Importing module: $Name" Import-Module -Name $Name } + + +# Support ClientID and PEM +# Support JWT +# Support IAT + GITHUB_TOKEN +# $params = @{ +# Owner = $env:GITHUB_REPOSITORY_OWNER +# Repo = $env:GITHUB_REPOSITORY_NAME +# Server = $env:GITHUB_SERVER_URL +# } +# Connect-GitHubAccount @params From 71b70a26640893e738cd142c8225897ee07a80ae Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 9 Nov 2024 19:47:41 +0100 Subject: [PATCH 2/9] test --- .github/workflows/Action-Test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 3995cf9..54540ad 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -56,7 +56,7 @@ jobs: uses: ./ with: Verbose: true - Version: 0.3.118 + Version: 0.8.4 Token: ${{ github.token }} Script: | LogGroup "Get-GitHubZen" { From 24ac0c9f8dde1e9c0b988cf1e99f816bfe2de205 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 9 Nov 2024 20:05:31 +0100 Subject: [PATCH 3/9] Require token to log on --- .github/workflows/Action-Test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 54540ad..eea7460 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -96,6 +96,7 @@ jobs: - name: Action-Test 3 uses: ./ with: + Token: ${{ github.token }} Script: | LogGroup "Get-GitHubRateLimit" { Get-GitHubRateLimit From 9bffc8863e5d0e9b26ce0ffd3f7b8c3c05cf027a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 9 Nov 2024 20:09:08 +0100 Subject: [PATCH 4/9] Fix --- scripts/main.ps1 | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 60d7ac8..179c497 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -12,11 +12,6 @@ $Name = 'GitHub' $Version = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version) ? $null : $env:GITHUB_ACTION_INPUT_Version $Prerelease = $env:GITHUB_ACTION_INPUT_Prerelease -eq 'true' -if (-not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token)) { - Write-Verbose "Setting GITHUB_TOKEN to provided input 'Token'" - $env:GITHUB_TOKEN = $env:GITHUB_ACTION_INPUT_Token -} - $alreadyInstalled = Get-InstalledPSResource -Name $Name -ErrorAction SilentlyContinue if ($Version) { Write-Verbose "Filtering by version: $Version" @@ -50,6 +45,10 @@ if (-not $alreadyImported) { Import-Module -Name $Name } +if (-not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token)) { + Write-Verbose "Setting GITHUB_TOKEN to provided input 'Token'" + Connect-Github -Token $env:GITHUB_ACTION_INPUT_Token +} # Support ClientID and PEM # Support JWT From 3176ecbedb21953121123d8895282e661921be40 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 9 Nov 2024 23:36:45 +0100 Subject: [PATCH 5/9] Fix --- scripts/main.ps1 | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 179c497..e3684be 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -45,17 +45,17 @@ if (-not $alreadyImported) { Import-Module -Name $Name } -if (-not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token)) { - Write-Verbose "Setting GITHUB_TOKEN to provided input 'Token'" - Connect-Github -Token $env:GITHUB_ACTION_INPUT_Token +LogGroup 'Connect-Github' { + if (-not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token)) { + Write-Verbose "Setting GITHUB_TOKEN to provided input 'Token'" + Connect-Github -Token $env:GITHUB_ACTION_INPUT_Token + } elseif (-not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_ClientID) -and -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_PEM)) { + Write-Verbose "Setting ClientID and PEM to provided inputs 'ClientID' and 'PEM'" + Connect-Github -ClientID $env:GITHUB_ACTION_INPUT_ClientID -PrivateKey $env:GITHUB_ACTION_INPUT_PrivateKey + } elseif (-not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_JWT)) { + Write-Verbose "Setting JWT to provided input 'JWT'" + Connect-Github -JWT $env:GITHUB_ACTION_INPUT_JWT + } else { + Connect-GitHub + } } - -# Support ClientID and PEM -# Support JWT -# Support IAT + GITHUB_TOKEN -# $params = @{ -# Owner = $env:GITHUB_REPOSITORY_OWNER -# Repo = $env:GITHUB_REPOSITORY_NAME -# Server = $env:GITHUB_SERVER_URL -# } -# Connect-GitHubAccount @params From 4b4c685c889d2fefd8174d484d19b5f24c6f9664 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 9 Nov 2024 23:57:38 +0100 Subject: [PATCH 6/9] Fix --- .github/workflows/Action-Test.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index eea7460..bab8397 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -57,7 +57,6 @@ jobs: with: Verbose: true Version: 0.8.4 - Token: ${{ github.token }} Script: | LogGroup "Get-GitHubZen" { Get-GitHubZen @@ -78,7 +77,6 @@ jobs: - name: Action-Test 1 uses: ./ with: - Token: ${{ github.token }} Script: | LogGroup "Get-GitHubZen" { Get-GitHubZen @@ -87,7 +85,6 @@ jobs: - name: Action-Test 2 uses: ./ with: - Token: ${{ github.token }} Script: | LogGroup "Get-GitHubOctocat" { Get-GitHubOctocat @@ -96,7 +93,6 @@ jobs: - name: Action-Test 3 uses: ./ with: - Token: ${{ github.token }} Script: | LogGroup "Get-GitHubRateLimit" { Get-GitHubRateLimit From 2f2275fb4976eb2f5ead7767509b0e2e1f258562 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 10 Nov 2024 00:07:29 +0100 Subject: [PATCH 7/9] test --- scripts/main.ps1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index e3684be..4a55763 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -8,6 +8,8 @@ if ($env:GITHUB_ACTION_INPUT_Verbose -eq 'true') { $VerbosePreference = 'Continue' } +'::group::Setting up GitHub PowerShell module' + $Name = 'GitHub' $Version = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version) ? $null : $env:GITHUB_ACTION_INPUT_Version $Prerelease = $env:GITHUB_ACTION_INPUT_Prerelease -eq 'true' @@ -44,6 +46,16 @@ if (-not $alreadyImported) { Write-Verbose "Importing module: $Name" Import-Module -Name $Name } +'::endgroup::' + + +$runningOnGitHubActions = $env:GITHUB_ACTIONS -eq 'true' +$tokenNotProvided = [string]::IsNullOrEmpty($Token) +$gitHubToken = $env:GH_TOKEN ?? $env:GITHUB_TOKEN +$gitHubTokenPresent = -not [string]::IsNullOrEmpty($gitHubToken) +Write-Verbose "GitHub Actions: [$runningOnGitHubActions]" +Write-Verbose "Token provided: [$tokenNotProvided]" +Write-Verbose "GitHub token present: [$gitHubTokenPresent]" LogGroup 'Connect-Github' { if (-not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token)) { From f71d018dcb272e1fbfa44a36aa5ccf57e6e2ec42 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 10 Nov 2024 00:11:52 +0100 Subject: [PATCH 8/9] test --- scripts/main.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 4a55763..89d468e 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -55,7 +55,7 @@ $gitHubToken = $env:GH_TOKEN ?? $env:GITHUB_TOKEN $gitHubTokenPresent = -not [string]::IsNullOrEmpty($gitHubToken) Write-Verbose "GitHub Actions: [$runningOnGitHubActions]" Write-Verbose "Token provided: [$tokenNotProvided]" -Write-Verbose "GitHub token present: [$gitHubTokenPresent]" +Write-Verbose "GitHub token present: [$gitHubTokenPresent] ($gitHubToken)" LogGroup 'Connect-Github' { if (-not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token)) { From 30f4dbde065733b58d8093a2a89c1cd340bafc66 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 10 Nov 2024 00:15:47 +0100 Subject: [PATCH 9/9] Fix --- action.yml | 1 + scripts/main.ps1 | 13 +------------ 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/action.yml b/action.yml index 93c11ef..d7a6a8f 100644 --- a/action.yml +++ b/action.yml @@ -12,6 +12,7 @@ inputs: Token: description: The access token to use. required: false + default: ${{ github.token }} Debug: description: Enable debug output. required: false diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 89d468e..11e5abf 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -48,26 +48,15 @@ if (-not $alreadyImported) { } '::endgroup::' - -$runningOnGitHubActions = $env:GITHUB_ACTIONS -eq 'true' -$tokenNotProvided = [string]::IsNullOrEmpty($Token) -$gitHubToken = $env:GH_TOKEN ?? $env:GITHUB_TOKEN -$gitHubTokenPresent = -not [string]::IsNullOrEmpty($gitHubToken) -Write-Verbose "GitHub Actions: [$runningOnGitHubActions]" -Write-Verbose "Token provided: [$tokenNotProvided]" -Write-Verbose "GitHub token present: [$gitHubTokenPresent] ($gitHubToken)" - LogGroup 'Connect-Github' { if (-not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token)) { Write-Verbose "Setting GITHUB_TOKEN to provided input 'Token'" Connect-Github -Token $env:GITHUB_ACTION_INPUT_Token - } elseif (-not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_ClientID) -and -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_PEM)) { + } elseif (-not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_ClientID) -and -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_PrivateKey)) { Write-Verbose "Setting ClientID and PEM to provided inputs 'ClientID' and 'PEM'" Connect-Github -ClientID $env:GITHUB_ACTION_INPUT_ClientID -PrivateKey $env:GITHUB_ACTION_INPUT_PrivateKey } elseif (-not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_JWT)) { Write-Verbose "Setting JWT to provided input 'JWT'" Connect-Github -JWT $env:GITHUB_ACTION_INPUT_JWT - } else { - Connect-GitHub } }