From 5ba9f66b3ec3aac61bd9776e660e5e29176378b8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 18 Aug 2024 13:36:15 +0200 Subject: [PATCH 01/17] Add a test for running without a token --- .github/workflows/Action-Test.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index e6bed48..db5b202 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -29,3 +29,19 @@ jobs: LogGroup "Get-GitHubZen" { Get-GitHubZen } + + ActionTestNoToken: + name: Action-Test - [NoToken] + runs-on: ubuntu-latest + steps: + # Need to check out as part of the test, as its a local action + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Action-Test + uses: ./ + with: + Script: | + LogGroup "Get-GitHubZen" { + Get-GitHubZen + } From 6cc3eab2b53557463b46260a2b8732163d86949a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 18 Aug 2024 13:40:33 +0200 Subject: [PATCH 02/17] add tests --- .github/workflows/Action-Test.yml | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index db5b202..1e2a7ca 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -16,6 +16,17 @@ jobs: ActionTestBasic: name: Action-Test - [Basic] runs-on: ubuntu-latest + steps: + # Need to check out as part of the test, as its a local action + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Action-Test + uses: ./ + + ActionTestWithScript: + name: Action-Test - [WithScript] + runs-on: ubuntu-latest steps: # Need to check out as part of the test, as its a local action - name: Checkout repo @@ -24,14 +35,13 @@ jobs: - name: Action-Test uses: ./ with: - Token: ${{ github.token }} Script: | LogGroup "Get-GitHubZen" { - Get-GitHubZen + "This is a group" } - ActionTestNoToken: - name: Action-Test - [NoToken] + ActionTestWithToken: + name: Action-Test - [WithToken] runs-on: ubuntu-latest steps: # Need to check out as part of the test, as its a local action @@ -41,6 +51,7 @@ jobs: - name: Action-Test uses: ./ with: + Token: ${{ github.token }} Script: | LogGroup "Get-GitHubZen" { Get-GitHubZen From f8f094a9986ea5c1ebdadc0bd8822510021e597b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 18 Aug 2024 13:44:02 +0200 Subject: [PATCH 03/17] Fix --- .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 1e2a7ca..253fc7d 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -36,7 +36,7 @@ jobs: uses: ./ with: Script: | - LogGroup "Get-GitHubZen" { + LogGroup "My group" { "This is a group" } From fd5ac62c51b69b0d07f2692a8db229e9e79e62d6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 18 Aug 2024 13:44:54 +0200 Subject: [PATCH 04/17] test --- .github/workflows/Action-Test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 253fc7d..b403248 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -56,3 +56,7 @@ jobs: LogGroup "Get-GitHubZen" { Get-GitHubZen } + + LogGroup "Get-GitHubOctocat" { + Get-GitHubOctocat + } From 3946960576b83ab5d80b296ebe798519ff95b423 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 18 Aug 2024 14:07:12 +0200 Subject: [PATCH 05/17] Test version stuff --- scripts/main.ps1 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index c280e98..bf003ae 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -10,5 +10,13 @@ $params = @{ if (-not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version)) { $params['Version'] = $env:GITHUB_ACTION_INPUT_Version } -Install-PSResource @params -Import-Module -Name 'GitHub' -Force + +$alreadyInstalled = Get-InstalledPSResource -Name $params['Name'] -Version $params['Version'] +if (-not $alreadyInstalled) { + Install-PSResource @params +} + +$alreadyImported = Get-Module -Name $params['Name'] -Refresh +if (-not $alreadyImported) { + Import-Module -Name $params['Name'] +} From 86032f1d93c8b3b372dfc8ad875aac6a5368d891 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 18 Aug 2024 14:08:46 +0200 Subject: [PATCH 06/17] Add test for consecutive --- .github/workflows/Action-Test.yml | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index b403248..de6ff09 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -60,3 +60,38 @@ jobs: LogGroup "Get-GitHubOctocat" { Get-GitHubOctocat } + + ActionTestConsecutive: + name: Action-Test - [Consecutive] + runs-on: ubuntu-latest + steps: + # Need to check out as part of the test, as its a local action + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Action-Test 1 + uses: ./ + with: + Token: ${{ github.token }} + Script: | + LogGroup "Get-GitHubZen" { + Get-GitHubZen + } + + - name: Action-Test 2 + uses: ./ + with: + Token: ${{ github.token }} + Script: | + LogGroup "Get-GitHubOctocat" { + Get-GitHubOctocat + } + + - name: Action-Test 3 + uses: ./ + with: + Token: ${{ github.token }} + Script: | + LogGroup "Get-GitHubRateLimit" { + Get-GitHubRateLimit + } From 6b1a7079f28697e0013d2d24b0827a12a40fa532 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 18 Aug 2024 14:13:25 +0200 Subject: [PATCH 07/17] Fix --- scripts/main.ps1 | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index bf003ae..f2c03fd 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -2,18 +2,21 @@ param() $params = @{ - Name = 'GitHub' - Repository = 'PSGallery' - TrustRepository = $true - Prerelease = $env:GITHUB_ACTION_INPUT_Prerelease -eq 'true' + Name = 'GitHub' } if (-not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version)) { $params['Version'] = $env:GITHUB_ACTION_INPUT_Version } -$alreadyInstalled = Get-InstalledPSResource -Name $params['Name'] -Version $params['Version'] +$installParams = @{ + Repository = 'PSGallery' + TrustRepository = $true + Prerelease = $env:GITHUB_ACTION_INPUT_Prerelease -eq 'true' +} + +$alreadyInstalled = Get-InstalledPSResource @params if (-not $alreadyInstalled) { - Install-PSResource @params + Install-PSResource @installParams } $alreadyImported = Get-Module -Name $params['Name'] -Refresh From 9b920ee8389651a21a2b7a6440b00d6ba4cdf518 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 18 Aug 2024 14:31:22 +0200 Subject: [PATCH 08/17] Fix --- scripts/main.ps1 | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index f2c03fd..f2f6401 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -1,25 +1,32 @@ [CmdletBinding()] param() -$params = @{ - Name = 'GitHub' -} -if (-not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version)) { - $params['Version'] = $env:GITHUB_ACTION_INPUT_Version -} +$Name = 'GitHub' +$Version = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version) ? $null : $env:GITHUB_ACTION_INPUT_Version +$Prerelease = $env:GITHUB_ACTION_INPUT_Prerelease -eq 'true' -$installParams = @{ - Repository = 'PSGallery' - TrustRepository = $true - Prerelease = $env:GITHUB_ACTION_INPUT_Prerelease -eq 'true' +$installedModules = Get-InstalledPSResource +$alreadyInstalled = $installedModules | Where-Object Name -EQ $Name +if ($Version) { + $alreadyInstalled = $alreadyInstalled | Where-Object Version -EQ $Version +} +if ($Prerelease) { + $alreadyInstalled = $alreadyInstalled | Where-Object Prerelease -EQ $Prerelease } - -$alreadyInstalled = Get-InstalledPSResource @params if (-not $alreadyInstalled) { - Install-PSResource @installParams + $params = @{ + Name = $Name + Repository = 'PSGallery' + TrustRepository = $true + Prerelease = $Prerelease + } + if ($Version) { + $params['Version'] = $Version + } + Install-PSResource @params } -$alreadyImported = Get-Module -Name $params['Name'] -Refresh +$alreadyImported = Get-Module -Name $Name if (-not $alreadyImported) { - Import-Module -Name $params['Name'] + Import-Module -Name $Name } From 03e5bfec288e12f03e64ae79cc9bb239b8505b4d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 18 Aug 2024 14:38:01 +0200 Subject: [PATCH 09/17] Test --- scripts/main.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index f2f6401..0c7be08 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -5,7 +5,9 @@ $Name = 'GitHub' $Version = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version) ? $null : $env:GITHUB_ACTION_INPUT_Version $Prerelease = $env:GITHUB_ACTION_INPUT_Prerelease -eq 'true' -$installedModules = Get-InstalledPSResource +$installedModules = Get-InstalledPSResource -ErrorAction SilentlyContinue +Write-Verbose "Installed modules:" +Write-Verbose ($installedModules | Out-String) $alreadyInstalled = $installedModules | Where-Object Name -EQ $Name if ($Version) { $alreadyInstalled = $alreadyInstalled | Where-Object Version -EQ $Version From 59ce2c9c8ec62827a796434e21a5bf2089025f7f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 18 Aug 2024 14:40:58 +0200 Subject: [PATCH 10/17] test --- scripts/main.ps1 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 0c7be08..fd13db3 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -5,16 +5,17 @@ $Name = 'GitHub' $Version = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version) ? $null : $env:GITHUB_ACTION_INPUT_Version $Prerelease = $env:GITHUB_ACTION_INPUT_Prerelease -eq 'true' -$installedModules = Get-InstalledPSResource -ErrorAction SilentlyContinue -Write-Verbose "Installed modules:" -Write-Verbose ($installedModules | Out-String) -$alreadyInstalled = $installedModules | Where-Object Name -EQ $Name +$alreadyInstalled = Get-InstalledPSResource -Name $Name -ErrorAction SilentlyContinue if ($Version) { + Write-Verbose "Filtering by version: $Version" $alreadyInstalled = $alreadyInstalled | Where-Object Version -EQ $Version } if ($Prerelease) { + Write-Verbose "Filtering by prerelease" $alreadyInstalled = $alreadyInstalled | Where-Object Prerelease -EQ $Prerelease } +Write-Verbose "Filtered modules:" +Write-Verbose ($alreadyInstalled | Format-Table | Out-String) if (-not $alreadyInstalled) { $params = @{ Name = $Name From f0092157747444d4f7fbc81ba3684ae98975822f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 18 Aug 2024 14:43:16 +0200 Subject: [PATCH 11/17] Add verbose --- .github/workflows/Action-Test.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index de6ff09..e93908b 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -35,6 +35,7 @@ jobs: - name: Action-Test uses: ./ with: + Verbose: true Script: | LogGroup "My group" { "This is a group" @@ -52,6 +53,7 @@ jobs: uses: ./ with: Token: ${{ github.token }} + Verbose: true Script: | LogGroup "Get-GitHubZen" { Get-GitHubZen @@ -73,6 +75,7 @@ jobs: uses: ./ with: Token: ${{ github.token }} + Verbose: true Script: | LogGroup "Get-GitHubZen" { Get-GitHubZen @@ -82,6 +85,7 @@ jobs: uses: ./ with: Token: ${{ github.token }} + Verbose: true Script: | LogGroup "Get-GitHubOctocat" { Get-GitHubOctocat @@ -91,6 +95,7 @@ jobs: uses: ./ with: Token: ${{ github.token }} + Verbose: true Script: | LogGroup "Get-GitHubRateLimit" { Get-GitHubRateLimit From 9ed1ff200c64c3e8ce22dfc07b250b8cc896b444 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 18 Aug 2024 14:48:46 +0200 Subject: [PATCH 12/17] test --- scripts/main.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index fd13db3..73c2ad3 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -17,6 +17,7 @@ if ($Prerelease) { Write-Verbose "Filtered modules:" Write-Verbose ($alreadyInstalled | Format-Table | Out-String) if (-not $alreadyInstalled) { + Write-Verbose "Installing module. Name: [$Name], Version: [$Version], Prerelease: [$Prerelease]" $params = @{ Name = $Name Repository = 'PSGallery' @@ -30,6 +31,9 @@ if (-not $alreadyInstalled) { } $alreadyImported = Get-Module -Name $Name +Write-Verbose "Already imported:" +Write-Verbose ($alreadyImported | Format-Table | Out-String) if (-not $alreadyImported) { + Write-Verbose "Importing module: $Name" Import-Module -Name $Name } From 4cfc64cfa71c7ce862a67d840d65b5227a41c964 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 18 Aug 2024 14:52:40 +0200 Subject: [PATCH 13/17] Fix --- scripts/main.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 73c2ad3..95b9876 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -14,7 +14,7 @@ if ($Prerelease) { Write-Verbose "Filtering by prerelease" $alreadyInstalled = $alreadyInstalled | Where-Object Prerelease -EQ $Prerelease } -Write-Verbose "Filtered modules:" +Write-Verbose "Already installed:" Write-Verbose ($alreadyInstalled | Format-Table | Out-String) if (-not $alreadyInstalled) { Write-Verbose "Installing module. Name: [$Name], Version: [$Version], Prerelease: [$Prerelease]" From c70c5385f495fde5a90fe7a9d31b83df6c6e538c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 18 Aug 2024 14:58:19 +0200 Subject: [PATCH 14/17] Update script --- README.md | 4 ++-- action.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 153bd55..8ca341a 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,11 @@ For more information on the available functions and automatic loaded variables, | Name | Description | Required | Default | | - | - | - | - | -| `Script` | The script to run | true | | +| `Script` | The script to run | false | | | `Token` | The GitHub token to use | false | ${{ github.token }} | | `Debug` | Enable debug output | false | 'false' | | `Verbose` | Enable verbose output | false | 'false' | -| `Version` | Specifies the version of the resource to be returned. The value can be an exact version or a version range using the NuGet versioning syntax. | false | 'latest' | +| `Version` | Specifies the version of the resource to be returned. The value must be an exact version. | false | | | `Prerelease` | Allow prerelease versions if available | false | 'false' | | `WorkingDirectory` | The working directory where the script will run from | false | ${{ github.workspace }} | diff --git a/action.yml b/action.yml index 26eef8d..2061bd4 100644 --- a/action.yml +++ b/action.yml @@ -8,7 +8,7 @@ branding: inputs: Script: description: The script to run. - required: true + required: false Token: description: The GitHub token to use. required: false From 76f0d641686c50b045d242458ebf0ef6299bce5d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 18 Aug 2024 15:07:07 +0200 Subject: [PATCH 15/17] doc update --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8ca341a..fdb4bf9 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,12 @@ For more information on the available functions and automatic loaded variables, | Name | Description | Required | Default | | - | - | - | - | | `Script` | The script to run | false | | -| `Token` | The GitHub token to use | false | ${{ github.token }} | -| `Debug` | Enable debug output | false | 'false' | -| `Verbose` | Enable verbose output | false | 'false' | +| `Token` | The GitHub token to use | false | `${{ github.token }}` | +| `Debug` | Enable debug output | false | `'false'` | +| `Verbose` | Enable verbose output | false | `'false'` | | `Version` | Specifies the version of the resource to be returned. The value must be an exact version. | false | | -| `Prerelease` | Allow prerelease versions if available | false | 'false' | -| `WorkingDirectory` | The working directory where the script will run from | false | ${{ github.workspace }} | +| `Prerelease` | Allow prerelease versions if available | false | `'false'` | +| `WorkingDirectory` | The working directory where the script will run from | false | `${{ github.workspace }}` | ### Examples From f383aa0773aa8a7fff659f40cb54392faa67f693 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 18 Aug 2024 15:12:19 +0200 Subject: [PATCH 16/17] test --- .github/workflows/Action-Test.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index e93908b..89e943f 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -63,6 +63,29 @@ jobs: Get-GitHubOctocat } + ActionTestWithVersion: + name: Action-Test - [WithVersion] + runs-on: ubuntu-latest + steps: + # Need to check out as part of the test, as its a local action + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Action-Test + uses: ./ + with: + Token: ${{ github.token }} + Verbose: true + Version: '0.3.118' + Script: | + LogGroup "Get-GitHubZen" { + Get-GitHubZen + } + + LogGroup "Get-GitHubOctocat" { + Get-GitHubOctocat + } + ActionTestConsecutive: name: Action-Test - [Consecutive] runs-on: ubuntu-latest From 2c8e40ec952ab56202c55c60fcbb6adfdad3656e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 18 Aug 2024 15:12:32 +0200 Subject: [PATCH 17/17] 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 89e943f..7369f28 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -76,7 +76,7 @@ jobs: with: Token: ${{ github.token }} Verbose: true - Version: '0.3.118' + Version: 0.3.118 Script: | LogGroup "Get-GitHubZen" { Get-GitHubZen