Skip to content

Commit 19246a1

Browse files
🩹 [Patch]: Add job to test GitHub Action commands (#13)
## Description - Add job to test GitHub Action commands ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 2a6afcb commit 19246a1

File tree

4 files changed

+80
-17
lines changed

4 files changed

+80
-17
lines changed

.github/workflows/Action-Test.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,35 @@ jobs:
4444
Get-GitHubZen
4545
}
4646
47+
ActionTestCommands:
48+
name: Action-Test - [Commands]
49+
runs-on: ubuntu-latest
50+
steps:
51+
# Need to check out as part of the test, as its a local action
52+
- name: Checkout repo
53+
uses: actions/checkout@v4
54+
55+
- name: Action-Test
56+
uses: ./
57+
id: test
58+
with:
59+
Prerelease: true
60+
Script: |
61+
$cat = Get-GitHubOctocat
62+
$zen = Get-GitHubZen
63+
Set-GitHubEnvironmentVariable -Name 'OCTOCAT' -Value $cat
64+
Set-GitHubOutput -Name 'WISECAT' -Value $cat
65+
Set-GitHubOutput -Name 'Zen' -Value $zen
66+
67+
- name: Run-test
68+
shell: pwsh
69+
env:
70+
result: ${{ steps.test.outputs.result }}
71+
run: |
72+
$result = $env:result | ConvertFrom-Json
73+
Set-GitHubStepSummary -Summary $result.WISECAT
74+
Write-GitHubNotice -Message $result.Zen -Title 'GitHub Zen'
75+
4776
ActionTestWithoutToken:
4877
name: Action-Test - [WithoutToken]
4978
runs-on: ubuntu-latest

README.md

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,27 @@ For more information on the available functions and automatic loaded variables,
1010

1111
| Name | Description | Required | Default |
1212
| - | - | - | - |
13-
| `Script` | The script to run | false | |
14-
| `Token` | Log in using an Installation Access Token (IAT) | false | `${{ github.token }}` |
15-
| `ClientID` | Log in using a GitHub App, using the App's Client ID and Private Key | false | |
16-
| `PrivateKey` | Log in using a GitHub App, using the App's Client ID and Private Key | false | |
17-
| `Debug` | Enable debug output | false | `'false'` |
18-
| `Verbose` | Enable verbose output | false | `'false'` |
13+
| `Script` | The script to run. Can be inline, multi-line or a path to a script file. | false | |
14+
| `Token` | Log in using an Installation Access Token (IAT). | false | `${{ github.token }}` |
15+
| `ClientID` | Log in using a GitHub App, using the App's Client ID and Private Key. | false | |
16+
| `PrivateKey` | Log in using a GitHub App, using the App's Client ID and Private Key. | false | |
17+
| `Debug` | Enable debug output. | false | `'false'` |
18+
| `Verbose` | Enable verbose output. | false | `'false'` |
1919
| `Version` | Specifies the version of the GitHub module to be installed. The value must be an exact version. | false | |
20-
| `Prerelease` | Allow prerelease versions if available | false | `'false'` |
21-
| `WorkingDirectory` | The working directory where the script will run from | false | `${{ github.workspace }}` |
20+
| `Prerelease` | Allow prerelease versions if available. | false | `'false'` |
21+
| `WorkingDirectory` | The working directory where the script will run from. | false | `${{ github.workspace }}` |
22+
23+
### Outputs
24+
25+
| Name | Description |
26+
| - | - |
27+
| `result` | The output of the script as a JSON object. To add outputs to `result`, use `Set-GitHubOutput`. |
2228

2329
### Examples
2430

2531
#### Example 1: Run a GitHub PowerShell script
2632

27-
Run a script that uses the GitHub PowerShell module.
28-
This example runs an authenticated script using the `GITHUB_TOKEN` and gets the GitHub Zen message.
33+
Run a script (`scripts/main.ps1`) that uses the GitHub PowerShell module, authenticated using the `GITHUB_TOKEN`.
2934

3035
```yaml
3136
jobs:
@@ -35,10 +40,7 @@ jobs:
3540
- name: Run script
3641
uses: PSModule/GitHub-Script@v1
3742
with:
38-
Script: |
39-
LogGroup "Get-GitHubZen" {
40-
Get-GitHubZen
41-
}
43+
Script: "scripts/main.ps1"
4244
```
4345
4446
#### Example 2: Run a GitHub PowerShell script without a token
@@ -102,6 +104,31 @@ jobs:
102104
}
103105
```
104106
107+
#### Example 5: Using the outputs from the script
108+
109+
Run a script that uses the GitHub PowerShell module and outputs the result.
110+
111+
```yaml
112+
- name: Run GitHub Script
113+
uses: PSModule/GitHub-Script@v1
114+
id: outputs
115+
with:
116+
Script: |
117+
$cat = Get-GitHubOctocat
118+
$zen = Get-GitHubZen
119+
Set-GitHubOutput -Name 'Octocat' -Value $cat
120+
Set-GitHubOutput -Name 'Zen' -Value $zen
121+
122+
- name: Use outputs
123+
shell: pwsh
124+
env:
125+
result: ${{ steps.test.outputs.result }}
126+
run: |
127+
$result = $env:result | ConvertFrom-Json
128+
Set-GitHubStepSummary -Summary $result.WISECAT
129+
Write-GitHubNotice -Message $result.Zen -Title 'GitHub Zen'
130+
```
131+
105132
## Related projects
106133
107134
- [actions/create-github-app-token](https://github.com/actions/create-github-app-token) -> Functionality will be brought into GitHub PowerShell module.

action.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ branding:
77

88
inputs:
99
Script:
10-
description: The script to run.
10+
description: The script to run. Can be inline, multi-line or a path to a script file.
1111
required: false
1212
Token:
1313
description: Log in using an Installation Access Token (IAT).
@@ -39,11 +39,17 @@ inputs:
3939
required: false
4040
default: ${{ github.workspace }}
4141

42+
outputs:
43+
result:
44+
description: The output of the script as a JSON object. To add outputs to `result`, use `Set-GitHubOutput`.
45+
value: ${{ steps.RunGitGubScript.outputs.result }}
46+
4247
runs:
4348
using: composite
4449
steps:
4550
- name: Install GitHub
4651
shell: pwsh
52+
id: RunGitGubScript
4753
working-directory: ${{ inputs.WorkingDirectory }}
4854
env:
4955
GITHUB_ACTION_INPUT_Token: ${{ inputs.Token }}

scripts/main.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ if ($env:GITHUB_ACTION_INPUT_Verbose -eq 'true') {
99
}
1010

1111
'::group::Setting up GitHub PowerShell module'
12+
$env:PSMODULE_GITHUB_SCRIPT = $true
1213

1314
$Name = 'GitHub'
1415
$Version = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version) ? $null : $env:GITHUB_ACTION_INPUT_Version
@@ -47,10 +48,10 @@ if (-not $alreadyImported) {
4748
Import-Module -Name $Name
4849
}
4950

50-
Write-Host 'Installed modules:'
51+
Write-Output 'Installed modules:'
5152
Get-InstalledPSResource | Select-Object Name, Version, Prerelease | Format-Table -AutoSize
5253

53-
Write-Host 'GitHub module configuration:'
54+
Write-Output 'GitHub module configuration:'
5455
Get-GitHubConfig | Select-Object Name, ID, RunEnv | Format-Table -AutoSize
5556

5657
'::endgroup::'

0 commit comments

Comments
 (0)