Skip to content

🩹 [Patch]: Document usage of the Script parameter #28

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 24 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f2cd50e
🩹 [Patch]: Update script path format in TestWorkflow.yml
MariusStorhaug Jan 22, 2025
ebd9051
🩹 [Patch]: Add additional action test with debug and verbose options …
MariusStorhaug Jan 22, 2025
b51f7d6
🩹 [Patch]: Update Action-Test names and script paths in TestWorkflow.…
MariusStorhaug Jan 22, 2025
c4c4c78
🩹 [Patch]: Remove unnecessary blank line in TestWorkflow.yml
MariusStorhaug Jan 22, 2025
c15f322
🩹 [Patch]: Add conditional execution for Action-Test steps in TestWor…
MariusStorhaug Jan 22, 2025
2097857
🩹 [Patch]: Standardize script path format and add additional Action-T…
MariusStorhaug Jan 22, 2025
117d0fb
🩹 [Patch]: Comment out unsupported Action-Test syntax and standardize…
MariusStorhaug Jan 22, 2025
29939f0
🩹 [Patch]: Rename log groups in info.ps1 for clarity and consistency
MariusStorhaug Jan 22, 2025
6dccd43
🩹 [Patch]: Add additional Action-Test script formats in TestWorkflow.…
MariusStorhaug Jan 22, 2025
e7420da
🩹 [Patch]: Update README.md to include additional script formats for …
MariusStorhaug Jan 22, 2025
15894da
🩹 [Patch]: Update README.md to clarify script path usage and emphasiz…
MariusStorhaug Jan 22, 2025
ec9a97a
🩹 [Patch]: Clarify PowerShell syntax usage in README.md for calling f…
MariusStorhaug Jan 22, 2025
a46f6d5
🩹 [Patch]: Update README.md to reflect changes in script path example…
MariusStorhaug Jan 22, 2025
fc8d080
🩹 [Patch]: Add a blank line for improved readability in README.md
MariusStorhaug Jan 22, 2025
366b002
Update README.md to clarify script path usage for custom actions and …
MariusStorhaug Jan 22, 2025
0425fc6
🩹 [Patch]: Update README.md to enhance script usage examples and clar…
MariusStorhaug Jan 22, 2025
efe5cde
🩹 [Patch]: Add blank lines in README.md for improved readability and …
MariusStorhaug Jan 22, 2025
dc7d1ff
🩹 [Patch]: Improve clarity and formatting in README.md for script inp…
MariusStorhaug Jan 22, 2025
b41e11f
Refactor README.md for improved clarity and consistency in script inp…
MariusStorhaug Jan 22, 2025
66fb6a8
🩹 [Patch]: Improve formatting and clarity in README.md for script inp…
MariusStorhaug Jan 22, 2025
41550bd
🩹 [Patch]: Correct spelling of 'prerelease' in README.md for consistency
MariusStorhaug Jan 22, 2025
f64d24e
🩹 [Patch]: Add markdown linter configuration for improved consistency…
MariusStorhaug Jan 22, 2025
4f9e84a
Fix markdown linting issue in README.md by disabling the rule for a s…
MariusStorhaug Jan 22, 2025
1b3adb3
🩹 [Patch]: Remove markdown linter configuration file as it is no long…
MariusStorhaug Jan 22, 2025
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
50 changes: 47 additions & 3 deletions .github/workflows/TestWorkflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,57 @@ jobs:
- name: Checkout repo
uses: actions/checkout@v4

- name: Action-Test
# # Not a supported way of running the action
# # This syntax is specifically for using a function in a specific module
# # i.e.: moduleName\functionName
# - name: Action-Test [tests\info.ps1]
# if: success() || failure()
# uses: ./
# with:
# Script: tests\info.ps1

- name: Action-Test [tests/info.ps1]
if: success() || failure()
uses: ./
with:
Script: tests/info.ps1

- name: Action-Test [.\tests\info.ps1]
if: success() || failure()
uses: ./
with:
Script: .\tests\info.ps1

- name: Action-Test [./tests/info.ps1]
if: success() || failure()
uses: ./
with:
Script: ./tests/info.ps1

- name: Action-Test [. .\tests\info.ps1]
if: success() || failure()
uses: ./
with:
Script: . .\tests\info.ps1

- name: Action-Test [. ./tests/info.ps1]
if: success() || failure()
uses: ./
with:
Script: . ./tests/info.ps1

- name: Action-Test [. '.\tests\info.ps1']
if: success() || failure()
uses: ./
with:
Debug: true
Verbose: true
Script: . '.\tests\info.ps1'

- name: Action-Test [. './tests/info.ps1']
if: success() || failure()
uses: ./
with:
Script: . './tests/info.ps1'

ActionTestCommands:
name: Commands + Outputs
runs-on: ${{ inputs.runs-on }}
Expand Down
118 changes: 77 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
# GitHub-Script

A GitHub Action used for running a PowerShell Script that uses the GitHub PowerShell module.
A GitHub Action for running a PowerShell script that uses the GitHub PowerShell module.

For more information on the available functions and automatic loaded variables, see the
[GitHub PowerShell module documentation](https://psmodule.io/GitHub)
For more information on available functions and automatically loaded variables, see the
[GitHub PowerShell module documentation](https://psmodule.io/GitHub).

## Usage

### Inputs

| Name | Description | Required | Default |
| - | - | - | - |
| `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'` |
| `ShowOutput` | Show the output of the script. | false | `'false'` |
| `WorkingDirectory` | The working directory where the script will run from. | false | `${{ github.workspace }}` |
| Name | Description | Required | Default |
|--------------------|---------------------------------------------------------------------------|----------|---------------------------|
| `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, with the App's Client ID and Private Key. | false | |
| `PrivateKey` | Log in using a GitHub App, with the App's Client ID and Private Key. | false | |
| `Debug` | Enable debug output. | false | `'false'` |
| `Verbose` | Enable verbose output. | false | `'false'` |
| `Version` | Specifies the exact version of the GitHub module to install. | false | |
| `Prerelease` | Allow prerelease versions if available. | false | `'false'` |
| `ShowOutput` | Show the script's output. | false | `'false'` |
| `WorkingDirectory` | The working directory where the script runs. | false | `${{ github.workspace }}` |

### Outputs

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

To use the outputs in a subsequent step, you can use the following syntax:
To use the outputs in a subsequent step, reference them as follows:

```yaml
- uses: PSModule/GitHub-Script@v1
Expand All @@ -51,28 +51,71 @@ To use the outputs in a subsequent step, you can use the following syntax:
Write-Output $result.Octocat.Image
```


### Examples

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

Run a script (`scripts/main.ps1`) that uses the GitHub PowerShell module, authenticated using the `GITHUB_TOKEN`.
Runs a script (`scripts/main.ps1`) that uses the GitHub PowerShell module, authenticated using the `GITHUB_TOKEN`.

```yaml
jobs:
Run-Script:
runs-on: ubuntu-latest
steps:
- name: Run script
- name: Run inline script - single line
uses: PSModule/GitHub-Script@v1
with:
Script: Get-GitHubPullRequest

- name: Run inline script - multiline
uses: PSModule/GitHub-Script@v1
with:
Script: "scripts/main.ps1"
Script: |
LogGroup 'Get-GitHubPullRequest' {
Get-GitHubPullRequest
}

- name: Run script file - Local repository
uses: PSModule/GitHub-Script@v1
with:
Script: ./scripts/main.ps1

- name: Run script file - In a composite action
uses: PSModule/GitHub-Script@v1
with:
Script: ${{ github.action_path }}/scripts/main.ps1
```

> [!IMPORTANT]
> Use `${{ github.action_path }}/<pathToScript.ps1>` if you are creating an action of your own that uses this action as a step. This ensures
> the path references your action rather than the `GitHub-Script` action repository. Using `$env:GITHUB_ACTION_PATH` can lead to mixed results
> when nesting actions. The context syntax will expand to the correct path when the job is evaluated by GitHub before being processed by the runner.

The `Script` input supports these formats:

- Inline script:
- Single-line
- Multi-line
- Path to a script file (recommended):
- `scripts/main.ps1`
- `.\scripts\main.ps1`
- `./scripts/main.ps1`
- `. .\scripts\main.ps1`
- `. ./scripts/main.ps1`
- `. '.\scripts\main.ps1'`
- `. './scripts/main.ps1'`

> [!WARNING]
> Using `tests\info.ps1` is PowerShell syntax for calling a function from a specific module (e.g., `Microsoft.PowerShell.Management\Get-ChildItem`).
<!-- markdownlint-disable-next-line -->

> [!TIP]
> Use script files instead of inline scripts for better support for development tools and linters. The PowerShell extension for Visual Studio Code and
> linters like PSScriptAnalyzer work natively with script files.

#### Example 2: Run a GitHub PowerShell script without a token

Run a script that uses the GitHub PowerShell module.
This example runs a non-authenticated script that gets the GitHub Zen message.
Runs a non-authenticated script that retrieves the GitHub Zen message.

```yaml
jobs:
Expand All @@ -91,8 +134,8 @@ jobs:

#### Example 3: Run a GitHub PowerShell script with a custom token

Run a script that uses the GitHub PowerShell module with a token. The token can be both a personal access token (PAT) or
an installation access token (IAT). This example runs an authenticated script that gets the GitHub Zen message.
Runs a script that uses the GitHub PowerShell module with a token. The token can be a personal access token (PAT) or
an installation access token (IAT). This example retrieves the GitHub Zen message.

```yaml
jobs:
Expand All @@ -111,8 +154,7 @@ jobs:

#### Example 4: Run a GitHub PowerShell script with a GitHub App using a Client ID and Private Key

Run a script that uses the GitHub PowerShell module with a GitHub App.
This example runs an authenticated script that gets the GitHub App.
Runs a script that uses the GitHub PowerShell module with a GitHub App. This example retrieves the GitHub App details.

```yaml
jobs:
Expand All @@ -130,9 +172,9 @@ jobs:
}
```

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

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

```yaml
- name: Run GitHub Script
Expand All @@ -150,13 +192,7 @@ Run a script that uses the GitHub PowerShell module and outputs the result.
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'
$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.
- [actions/github-script](https://github.com/actions/github-script)
- [PSModule/GitHub](https://github.com/PSModule/GitHub)
4 changes: 2 additions & 2 deletions tests/info.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#Requires -Modules GitHub

LogGroup ' - Event Info' {
LogGroup ' - Get-GithubEventData' {
Get-GithubEventData | Format-List
}

LogGroup ' - Runner Info' {
LogGroup ' - Get-GithubRunnerData' {
Get-GithubRunnerData | Format-List
}
Loading