Skip to content

Commit d9a8681

Browse files
🩹 [Patch]: Outputs and Docs (#17)
## Description This pull request includes updates to the `README.md` and significant changes to the `scripts/main.ps1` to improve output formatting and logging. Documentation Update: * [`README.md`](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R29-R52): Added a detailed example on how to use outputs in a subsequent step in GitHub Actions. Script Enhancements: * [`scripts/main.ps1`](diffhunk://#diff-dc2e5a659836b1b73abb03421c567f5018c2755677c4a0aa764cb26117b68011L24-L26): Improved the script's output formatting by replacing `Write-Verbose` with direct formatting commands and `Format-List`. [[1]](diffhunk://#diff-dc2e5a659836b1b73abb03421c567f5018c2755677c4a0aa764cb26117b68011L24-L26) [[2]](diffhunk://#diff-dc2e5a659836b1b73abb03421c567f5018c2755677c4a0aa764cb26117b68011L41-R81) * [`scripts/main.ps1`](diffhunk://#diff-dc2e5a659836b1b73abb03421c567f5018c2755677c4a0aa764cb26117b68011L4-R6): Enhanced logging with more descriptive output and structured log groups. [[1]](diffhunk://#diff-dc2e5a659836b1b73abb03421c567f5018c2755677c4a0aa764cb26117b68011L4-R6) [[2]](diffhunk://#diff-dc2e5a659836b1b73abb03421c567f5018c2755677c4a0aa764cb26117b68011L41-R81) * [`scripts/main.ps1`](diffhunk://#diff-dc2e5a659836b1b73abb03421c567f5018c2755677c4a0aa764cb26117b68011L4-R6): Moved the setting of `$DebugPreference` and `$VerbosePreference` to the end of the script for better readability. ## 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 b2cd139 commit d9a8681

File tree

2 files changed

+58
-26
lines changed

2 files changed

+58
-26
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,30 @@ For more information on the available functions and automatic loaded variables,
2626
| - | - |
2727
| `result` | The output of the script as a JSON object. To add outputs to `result`, use `Set-GitHubOutput`. |
2828

29+
To use the outputs in a subsequent step, you can use the following syntax:
30+
31+
```yaml
32+
- uses: PSModule/GitHub-Script@v1
33+
id: set-output
34+
with:
35+
Script: |
36+
Set-GitHubOutput -Name 'Octocat' -Value @{
37+
Name = 'Octocat'
38+
Image = 'https://octodex.github.com/images/original.png'
39+
}
40+
41+
- name: Use outputs
42+
shell: pwsh
43+
env:
44+
result: ${{ steps.set-output.outputs.result }} # = '{"Octocat":{"Name":"Octocat","Image":"https://octodex.github.com/images/original.png"}}'
45+
name: ${{ fromJson(steps.set-output.outputs.result).Octocat.Name }} # = 'Octocat'
46+
run: |
47+
$result = $env:result | ConvertFrom-Json
48+
Write-Output $env:name
49+
Write-Output $result.Octocat.Image
50+
```
51+
52+
2953
### Examples
3054
3155
#### Example 1: Run a GitHub PowerShell script

scripts/main.ps1

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
[CmdletBinding()]
22
param()
33

4-
$DebugPreference = $env:GITHUB_ACTION_INPUT_Debug -eq 'true' ? 'Continue' : 'SilentlyContinue'
5-
$VerbosePreference = $env:GITHUB_ACTION_INPUT_Verbose -eq 'true' ? 'Continue' : 'SilentlyContinue'
6-
7-
'::group::Setting up GitHub PowerShell module'
84
$env:PSMODULE_GITHUB_SCRIPT = $true
5+
Write-Host "┏━━━━━┫ GitHub-Script ┣━━━━━┓"
6+
Write-Host '::group:: - Setup GitHub PowerShell'
97

108
$Name = 'GitHub'
119
$Version = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version) ? $null : $env:GITHUB_ACTION_INPUT_Version
@@ -21,9 +19,8 @@ if ($Prerelease) {
2119
$alreadyInstalled = $alreadyInstalled | Where-Object Prerelease -EQ $Prerelease
2220
}
2321
Write-Verbose 'Already installed:'
24-
Write-Verbose ($alreadyInstalled | Format-Table | Out-String)
22+
$alreadyInstalled | Format-Table
2523
if (-not $alreadyInstalled) {
26-
Write-Verbose "Installing module. Name: [$Name], Version: [$Version], Prerelease: [$Prerelease]"
2724
$params = @{
2825
Name = $Name
2926
Repository = 'PSGallery'
@@ -38,36 +35,47 @@ if (-not $alreadyInstalled) {
3835

3936
$alreadyImported = Get-Module -Name $Name
4037
Write-Verbose 'Already imported:'
41-
Write-Verbose ($alreadyImported | Format-Table | Out-String)
38+
$alreadyImported | Format-Table
4239
if (-not $alreadyImported) {
4340
Write-Verbose "Importing module: $Name"
4441
Import-Module -Name $Name
4542
}
4643

47-
Write-Output 'Installed modules:'
48-
Get-InstalledPSResource | Select-Object Name, Version, Prerelease | Format-Table -AutoSize
49-
50-
Write-Output 'GitHub module configuration:'
51-
Get-GitHubConfig | Select-Object Name, ID, RunEnv | Format-Table -AutoSize
52-
53-
'::endgroup::'
54-
5544
$providedToken = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token)
5645
$providedClientID = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_ClientID)
5746
$providedPrivateKey = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_PrivateKey)
58-
Write-Verbose 'Provided authentication info:'
59-
Write-Verbose "Token: [$providedToken]"
60-
Write-Verbose "ClientID: [$providedClientID]"
61-
Write-Verbose "PrivateKey: [$providedPrivateKey]"
47+
[pscustomobject]@{
48+
Name = $Name
49+
Version = [string]::IsNullOrEmpty($Version) ? 'latest' : $Version
50+
Prerelease = $Prerelease
51+
'Already installed' = $null -ne $alreadyInstalled
52+
'Already imported' = $null -ne $alreadyImported
53+
'Provided Token' = $providedToken
54+
'Provided ClientID' = $providedClientID
55+
'Provided PrivateKey' = $providedPrivateKey
56+
} | Format-List
57+
Write-Host '::endgroup::'
58+
59+
LogGroup ' - Installed modules' {
60+
Get-InstalledPSResource | Select-Object Name, Version, Prerelease | Sort-Object -Property Name | Format-Table -AutoSize
61+
}
6262

63-
if ($providedClientID -and $providedPrivateKey) {
64-
LogGroup 'Connecting using provided GitHub App' {
63+
LogGroup ' - GitHub connection' {
64+
if ($providedClientID -and $providedPrivateKey) {
65+
Write-Verbose 'Connected using provided GitHub App'
6566
Connect-GitHub -ClientID $env:GITHUB_ACTION_INPUT_ClientID -PrivateKey $env:GITHUB_ACTION_INPUT_PrivateKey -Silent
66-
Get-GitHubContext | Format-Table -AutoSize
67-
}
68-
} elseif ($providedToken) {
69-
LogGroup 'Connecting using provided token' {
67+
} elseif ($providedToken) {
68+
Write-Verbose 'Connected using provided token'
7069
Connect-GitHub -Token $env:GITHUB_ACTION_INPUT_Token -Silent
71-
Get-GitHubContext | Format-Table -AutoSize
7270
}
71+
Get-GitHubContext | Format-List
72+
}
73+
74+
LogGroup ' - Configuration' {
75+
Get-GitHubConfig | Format-List
7376
}
77+
78+
Write-Host '┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛'
79+
80+
$DebugPreference = $env:GITHUB_ACTION_INPUT_Debug -eq 'true' ? 'Continue' : 'SilentlyContinue'
81+
$VerbosePreference = $env:GITHUB_ACTION_INPUT_Verbose -eq 'true' ? 'Continue' : 'SilentlyContinue'

0 commit comments

Comments
 (0)