Skip to content

🚀 [Feature]: Add job to test GitHub Action commands #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 38 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
acdb9dd
🩹 [Patch]: Add Action-Test commands to GitHub workflow
MariusStorhaug Dec 1, 2024
fc16178
🩹 [Patch]: Enable Prerelease option in Action-Test workflow
MariusStorhaug Dec 1, 2024
54f359b
🩹 [Patch]: Update Action-Test workflow to use PowerShell variable syn…
MariusStorhaug Dec 1, 2024
8c8eae0
test
MariusStorhaug Dec 1, 2024
e59ac16
🩹 [Patch]: Rename Action-Test job and add Action-Test-Output step for…
MariusStorhaug Dec 1, 2024
6c40fd1
verbose tests
MariusStorhaug Dec 1, 2024
57d69f2
Get content
MariusStorhaug Dec 1, 2024
b1358ac
test casing
MariusStorhaug Dec 1, 2024
1f39402
🩹 [Patch]: Update Action-Test job to modify output handling with new …
MariusStorhaug Dec 1, 2024
8c5ae15
🩹 [Patch]: Update Action-Test job to change output variable from WISE…
MariusStorhaug Dec 1, 2024
ef964a3
test
MariusStorhaug Dec 1, 2024
7e9ba51
test
MariusStorhaug Dec 1, 2024
fd18c1f
test
MariusStorhaug Dec 1, 2024
bfb0188
test
MariusStorhaug Dec 1, 2024
d135ebf
test
MariusStorhaug Dec 1, 2024
b8faed9
test
MariusStorhaug Dec 1, 2024
64125a0
test
MariusStorhaug Dec 1, 2024
af814f3
test
MariusStorhaug Dec 1, 2024
39d0846
test
MariusStorhaug Dec 1, 2024
4205d7b
test
MariusStorhaug Dec 1, 2024
1502b4b
Add environment variable logging to main.ps1
MariusStorhaug Dec 1, 2024
295b807
test
MariusStorhaug Dec 1, 2024
d048a52
test
MariusStorhaug Dec 1, 2024
08f8a31
test
MariusStorhaug Dec 1, 2024
b870aed
Refactor GitHub Actions output handling in Action-Test.yml
MariusStorhaug Dec 1, 2024
5cedd8a
Add output logging to outputs.ps1
MariusStorhaug Dec 1, 2024
2e8a010
Fix
MariusStorhaug Dec 1, 2024
17c3ff3
Remove unused environment variables from Action-Test.yml
MariusStorhaug Dec 1, 2024
12a038a
Update outputs.ps1 to read GITHUB_OUTPUT content before fetching outputs
MariusStorhaug Dec 1, 2024
c4550e7
Update outputs.ps1 to fetch outputs using GITHUB_OUTPUT path
MariusStorhaug Dec 1, 2024
0ee249a
test
MariusStorhaug Dec 1, 2024
c2636d4
Refactor Action-Test workflow to streamline output handling and remov…
MariusStorhaug Dec 1, 2024
16330f1
Update Action-Test workflow to parse JSON output and access specific …
MariusStorhaug Dec 1, 2024
659aa16
Refactor Action-Test workflow to rename job and streamline output sum…
MariusStorhaug Dec 1, 2024
162f9fb
test
MariusStorhaug Dec 1, 2024
6005b29
Update README.md to add outputs section and examples for using script…
MariusStorhaug Dec 1, 2024
5b7b7d0
Add Prerelease input to Action-Test workflow
MariusStorhaug Dec 1, 2024
582d185
Refactor Action-Test workflow to enable job definitions and enhance R…
MariusStorhaug Dec 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/Action-Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,35 @@ jobs:
Get-GitHubZen
}

ActionTestCommands:
name: Action-Test - [Commands]
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: ./
id: test
with:
Prerelease: true
Script: |
$cat = Get-GitHubOctocat
$zen = Get-GitHubZen
Set-GitHubEnvironmentVariable -Name 'OCTOCAT' -Value $cat
Set-GitHubOutput -Name 'WISECAT' -Value $cat
Set-GitHubOutput -Name 'Zen' -Value $zen

- name: Run-test
shell: pwsh
env:
result: ${{ steps.test.outputs.result }}
run: |
$result = $env:result | ConvertFrom-Json
Set-GitHubStepSummary -Summary $result.WISECAT
Write-GitHubNotice -Message $result.Zen -Title 'GitHub Zen'

ActionTestWithoutToken:
name: Action-Test - [WithoutToken]
runs-on: ubuntu-latest
Expand Down
55 changes: 41 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,27 @@ For more information on the available functions and automatic loaded variables,

| Name | Description | Required | Default |
| - | - | - | - |
| `Script` | The script to run | false | |
| `Token` | Log in using an Installation Access Token (IAT) | false | `${{ github.token }}` |
| `ClientID` | Log in using a GitHub App, using the App's Client ID and Private Key | false | |
| `PrivateKey` | Log in using a GitHub App, using the App's Client ID and Private Key | false | |
| `Debug` | Enable debug output | false | `'false'` |
| `Verbose` | Enable verbose output | false | `'false'` |
| `Script` | The script to run. Can be inline, multi-line or a path to a script file. | false | |
| `Token` | Log in using an Installation Access Token (IAT). | false | `${{ github.token }}` |
| `ClientID` | Log in using a GitHub App, using the App's Client ID and Private Key. | false | |
| `PrivateKey` | Log in using a GitHub App, using the App's Client ID and Private Key. | false | |
| `Debug` | Enable debug output. | false | `'false'` |
| `Verbose` | Enable verbose output. | false | `'false'` |
| `Version` | Specifies the version of the GitHub module to be installed. 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 }}` |

### Outputs

| Name | Description |
| - | - |
| `result` | The output of the script as a JSON object. To add outputs to `result`, use `Set-GitHubOutput`. |

### Examples

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

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

```yaml
jobs:
Expand All @@ -35,10 +40,7 @@ jobs:
- name: Run script
uses: PSModule/GitHub-Script@v1
with:
Script: |
LogGroup "Get-GitHubZen" {
Get-GitHubZen
}
Script: "scripts/main.ps1"
```

#### Example 2: Run a GitHub PowerShell script without a token
Expand Down Expand Up @@ -102,6 +104,31 @@ jobs:
}
```

#### Example 5: Using the outputs from the script

Run a script that uses the GitHub PowerShell module and outputs the result.

```yaml
- name: Run GitHub Script
uses: PSModule/GitHub-Script@v1
id: outputs
with:
Script: |
$cat = Get-GitHubOctocat
$zen = Get-GitHubZen
Set-GitHubOutput -Name 'Octocat' -Value $cat
Set-GitHubOutput -Name 'Zen' -Value $zen

- name: Use outputs
shell: pwsh
env:
result: ${{ steps.test.outputs.result }}
run: |
$result = $env:result | ConvertFrom-Json
Set-GitHubStepSummary -Summary $result.WISECAT
Write-GitHubNotice -Message $result.Zen -Title 'GitHub Zen'
```

## Related projects

- [actions/create-github-app-token](https://github.com/actions/create-github-app-token) -> Functionality will be brought into GitHub PowerShell module.
Expand Down
8 changes: 7 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ branding:

inputs:
Script:
description: The script to run.
description: The script to run. Can be inline, multi-line or a path to a script file.
required: false
Token:
description: Log in using an Installation Access Token (IAT).
Expand Down Expand Up @@ -39,11 +39,17 @@ inputs:
required: false
default: ${{ github.workspace }}

outputs:
result:
description: The output of the script as a JSON object. To add outputs to `result`, use `Set-GitHubOutput`.
value: ${{ steps.RunGitGubScript.outputs.result }}

runs:
using: composite
steps:
- name: Install GitHub
shell: pwsh
id: RunGitGubScript
working-directory: ${{ inputs.WorkingDirectory }}
env:
GITHUB_ACTION_INPUT_Token: ${{ inputs.Token }}
Expand Down
5 changes: 3 additions & 2 deletions scripts/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ if ($env:GITHUB_ACTION_INPUT_Verbose -eq 'true') {
}

'::group::Setting up GitHub PowerShell module'
$env:PSMODULE_GITHUB_SCRIPT = $true

$Name = 'GitHub'
$Version = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version) ? $null : $env:GITHUB_ACTION_INPUT_Version
Expand Down Expand Up @@ -47,10 +48,10 @@ if (-not $alreadyImported) {
Import-Module -Name $Name
}

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

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

'::endgroup::'
Expand Down
Loading