Skip to content

Commit 9053af3

Browse files
🩹 [Patch]: Default behavior is to use the GITHUB_TOKEN (#6)
## Description - Default behavior is to use the `GITHUB_TOKEN` if not `Token` is provided. - `GH_TOKEN` (EnvVar) > `GITHUB_TOKEN` (EnvVar) > `Token` (Input) ## 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 34fcdf1 commit 9053af3

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

.github/workflows/Action-Test.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,29 @@ jobs:
4141
"This is a group"
4242
}
4343
44+
ActionTestWithGitHubToken:
45+
name: Action-Test - [WithGitHubToken]
46+
runs-on: ubuntu-latest
47+
env:
48+
GITHUB_TOKEN: ${{ github.token }}
49+
steps:
50+
# Need to check out as part of the test, as its a local action
51+
- name: Checkout repo
52+
uses: actions/checkout@v4
53+
54+
- name: Action-Test
55+
uses: ./
56+
with:
57+
Verbose: true
58+
Script: |
59+
LogGroup "Get-GitHubZen" {
60+
Get-GitHubZen
61+
}
62+
63+
LogGroup "Get-GitHubOctocat" {
64+
Get-GitHubOctocat
65+
}
66+
4467
ActionTestWithToken:
4568
name: Action-Test - [WithToken]
4669
runs-on: ubuntu-latest
@@ -63,6 +86,7 @@ jobs:
6386
Get-GitHubOctocat
6487
}
6588
89+
6690
ActionTestWithVersion:
6791
name: Action-Test - [WithVersion]
6892
runs-on: ubuntu-latest

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ For more information on the available functions and automatic loaded variables,
1111
| Name | Description | Required | Default |
1212
| - | - | - | - |
1313
| `Script` | The script to run | false | |
14-
| `Token` | The GitHub token to use | false | `${{ github.token }}` |
14+
| `Token` | The GitHub token to use. This will override the default behavior of using the `GITHUB_TOKEN` environment variable. | false | `${{ github.token }}` |
1515
| `Debug` | Enable debug output | false | `'false'` |
1616
| `Verbose` | Enable verbose output | false | `'false'` |
1717
| `Version` | Specifies the version of the GitHub module to be installed. The value must be an exact version. | false | |

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ inputs:
1010
description: The script to run.
1111
required: false
1212
Token:
13-
description: The GitHub token to use.
13+
description: The GitHub token to use. This will override the default behavior of using the `GITHUB_TOKEN` environment variable.
1414
required: false
1515
Debug:
1616
description: Enable debug output.
@@ -39,7 +39,7 @@ runs:
3939
shell: pwsh
4040
working-directory: ${{ inputs.WorkingDirectory }}
4141
env:
42-
GITHUB_TOKEN: ${{ inputs.Token }}
42+
GITHUB_ACTION_INPUT_Token: ${{ inputs.Token }}
4343
GITHUB_ACTION_INPUT_Debug: ${{ inputs.Debug }}
4444
GITHUB_ACTION_INPUT_Verbose: ${{ inputs.Verbose }}
4545
GITHUB_ACTION_INPUT_Version: ${{ inputs.Version }}

scripts/main.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ $Name = 'GitHub'
55
$Version = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version) ? $null : $env:GITHUB_ACTION_INPUT_Version
66
$Prerelease = $env:GITHUB_ACTION_INPUT_Prerelease -eq 'true'
77

8+
if (-not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token)) {
9+
Write-Verbose "Setting GITHUB_TOKEN to provided input 'Token'"
10+
$env:GITHUB_TOKEN = $env:GITHUB_ACTION_INPUT_Token
11+
}
12+
813
$alreadyInstalled = Get-InstalledPSResource -Name $Name -ErrorAction SilentlyContinue
914
if ($Version) {
1015
Write-Verbose "Filtering by version: $Version"

0 commit comments

Comments
 (0)