diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 725f1c0..bbd12ae 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -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 diff --git a/README.md b/README.md index b9b653a..1c467a6 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 @@ -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. diff --git a/action.yml b/action.yml index 7f517c7..26a4163 100644 --- a/action.yml +++ b/action.yml @@ -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). @@ -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 }} diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 2a6d1cf..abbe63d 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -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 @@ -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::'