Skip to content
Merged
94 changes: 94 additions & 0 deletions .github/workflows/Action-Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,56 @@ 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
uses: actions/checkout@v4

- name: Action-Test
uses: ./
with:
Verbose: true
Script: |
LogGroup "My group" {
"This is a group"
}

ActionTestWithToken:
name: Action-Test - [WithToken]
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
Script: |
LogGroup "Get-GitHubZen" {
Get-GitHubZen
}

LogGroup "Get-GitHubOctocat" {
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
Expand All @@ -25,7 +75,51 @@ jobs:
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
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 }}
Verbose: true
Script: |
LogGroup "Get-GitHubZen" {
Get-GitHubZen
}

- name: Action-Test 2
uses: ./
with:
Token: ${{ github.token }}
Verbose: true
Script: |
LogGroup "Get-GitHubOctocat" {
Get-GitHubOctocat
}

- name: Action-Test 3
uses: ./
with:
Token: ${{ github.token }}
Verbose: true
Script: |
LogGroup "Get-GitHubRateLimit" {
Get-GitHubRateLimit
}
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ For more information on the available functions and automatic loaded variables,

| Name | Description | Required | Default |
| - | - | - | - |
| `Script` | The script to run | true | |
| `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' |
| `Prerelease` | Allow prerelease versions if available | false | 'false' |
| `WorkingDirectory` | The working directory where the script will run from | false | ${{ github.workspace }} |
| `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 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 }}` |

### Examples

Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 34 additions & 9 deletions scripts/main.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
[CmdletBinding()]
param()

$params = @{
Name = 'GitHub'
Repository = 'PSGallery'
TrustRepository = $true
Prerelease = $env:GITHUB_ACTION_INPUT_Prerelease -eq 'true'
$Name = 'GitHub'
$Version = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version) ? $null : $env:GITHUB_ACTION_INPUT_Version
$Prerelease = $env:GITHUB_ACTION_INPUT_Prerelease -eq 'true'

$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
}
if (-not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version)) {
$params['Version'] = $env:GITHUB_ACTION_INPUT_Version
Write-Verbose "Already installed:"
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'
TrustRepository = $true
Prerelease = $Prerelease
}
if ($Version) {
$params['Version'] = $Version
}
Install-PSResource @params
}

$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
}
Install-PSResource @params
Import-Module -Name 'GitHub' -Force