Skip to content

Commit 174cd64

Browse files
🚀 [Feature]: Add ability to log on with GitHub App (#9)
## Description - Add ability to log on with GitHub App using `ClientID` and `PrivateKey`. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [x] 🚀 [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 9cb9a61 commit 174cd64

File tree

4 files changed

+114
-40
lines changed

4 files changed

+114
-40
lines changed

.github/workflows/Action-Test.yml

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,16 @@ jobs:
4040
uses: ./
4141
with:
4242
Script: |
43-
LogGroup "My group" {
44-
"This is a group"
43+
LogGroup 'Get-GitHubContext' {
44+
Get-GitHubContext
4545
}
4646
47-
ActionTestWithVersion:
48-
name: Action-Test - [WithVersion]
47+
LogGroup 'Get-GitHubZen' {
48+
Get-GitHubZen
49+
}
50+
51+
ActionTestWithoutToken:
52+
name: Action-Test - [WithoutToken]
4953
runs-on: ubuntu-latest
5054
steps:
5155
# Need to check out as part of the test, as its a local action
@@ -55,45 +59,59 @@ jobs:
5559
- name: Action-Test
5660
uses: ./
5761
with:
58-
Verbose: true
59-
Version: 0.8.4
62+
Token: ''
6063
Script: |
61-
LogGroup "Get-GitHubZen" {
62-
Get-GitHubZen
64+
LogGroup 'Get-GitHubContext' {
65+
Get-GitHubContext
6366
}
6467
65-
LogGroup "Get-GitHubOctocat" {
66-
Get-GitHubOctocat
68+
LogGroup 'My group' {
69+
'This is a group'
6770
}
6871
69-
ActionTestConsecutive:
70-
name: Action-Test - [Consecutive]
72+
ActionTestWithPAT:
73+
name: Action-Test - [WithPAT]
7174
runs-on: ubuntu-latest
7275
steps:
7376
# Need to check out as part of the test, as its a local action
7477
- name: Checkout repo
7578
uses: actions/checkout@v4
7679

77-
- name: Action-Test 1
80+
- name: Action-Test
7881
uses: ./
7982
with:
83+
Token: ${{ secrets.TEST_PAT }}
8084
Script: |
81-
LogGroup "Get-GitHubZen" {
82-
Get-GitHubZen
85+
LogGroup 'Get-GitHubContext' {
86+
Get-GitHubContext
8387
}
8488
85-
- name: Action-Test 2
86-
uses: ./
87-
with:
88-
Script: |
89-
LogGroup "Get-GitHubOctocat" {
90-
Get-GitHubOctocat
89+
LogGroup 'Get-GitHubUser' {
90+
Get-GitHubUser
9191
}
9292
93-
- name: Action-Test 3
93+
ActionTestWithGitHubApp:
94+
name: Action-Test - [GitHubApp]
95+
runs-on: ubuntu-latest
96+
steps:
97+
# Need to check out as part of the test, as its a local action
98+
- name: Checkout repo
99+
uses: actions/checkout@v4
100+
101+
- name: Action-Test
94102
uses: ./
95103
with:
104+
ClientID: ${{ secrets.TEST_APP_CLIENT_ID }}
105+
PrivateKey: ${{ secrets.TEST_APP_PRIVATE_KEY }}
96106
Script: |
97-
LogGroup "Get-GitHubRateLimit" {
98-
Get-GitHubRateLimit
107+
LogGroup 'Get-GitHubContext' {
108+
Get-GitHubContext
109+
}
110+
111+
LogGroup 'Get-GitHubApp' {
112+
Get-GitHubApp
113+
}
114+
115+
LogGroup 'Get-GitHubAppInstallation' {
116+
Get-GitHubAppInstallation
99117
}

README.md

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ 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. This will override the default behavior of using the `GITHUB_TOKEN` environment variable. | false | `${{ github.token }}` |
14+
| `Token` | Log in using an Installation Access Token (IAT) | false | `${{ github.token }}` |
15+
| `ClientID` | Log in using a GitHub App, using the App's Client ID and Private Key | false | |
16+
| `PrivateKey` | Log in using a GitHub App, using the App's Client ID and Private Key | false | |
1517
| `Debug` | Enable debug output | false | `'false'` |
1618
| `Verbose` | Enable verbose output | false | `'false'` |
1719
| `Version` | Specifies the version of the GitHub module to be installed. The value must be an exact version. | false | |
@@ -20,7 +22,26 @@ For more information on the available functions and automatic loaded variables,
2022

2123
### Examples
2224

23-
#### Example 1: Run a script that uses the GitHub PowerShell module
25+
#### Example 1: Run a GitHub PowerShell script
26+
27+
Run a script that uses the GitHub PowerShell module.
28+
This example runs an authenticated script using the `GITHUB_TOKEN` and gets the GitHub Zen message.
29+
30+
```yaml
31+
jobs:
32+
Run-Script:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Run script
36+
uses: PSModule/GitHub-Script@v1
37+
with:
38+
Script: |
39+
LogGroup "Get-GitHubZen" {
40+
Get-GitHubZen
41+
}
42+
```
43+
44+
#### Example 2: Run a GitHub PowerShell script without a token
2445
2546
Run a script that uses the GitHub PowerShell module.
2647
This example runs a non-authenticated script that gets the GitHub Zen message.
@@ -33,16 +54,17 @@ jobs:
3354
- name: Run script
3455
uses: PSModule/GitHub-Script@v1
3556
with:
57+
Token: ''
3658
Script: |
3759
LogGroup "Get-GitHubZen" {
3860
Get-GitHubZen
3961
}
4062
```
4163
42-
#### Example 2: Run a script that uses the GitHub PowerShell module with a token
64+
#### Example 3: Run a GitHub PowerShell script with a custom token
4365
44-
Run a script that uses the GitHub PowerShell module with a token.
45-
This example runs an authenticated script that gets the GitHub Zen message.
66+
Run a script that uses the GitHub PowerShell module with a token. The token can be both a personal access token (PAT) or
67+
an installation access token (IAT). This example runs an authenticated script that gets the GitHub Zen message.
4668
4769
```yaml
4870
jobs:
@@ -52,13 +74,34 @@ jobs:
5274
- name: Run script
5375
uses: PSModule/GitHub-Script@v1
5476
with:
55-
Token: ${{ github.token }}
77+
Token: ${{ secrets.Token }}
5678
Script: |
5779
LogGroup "Get-GitHubZen" {
5880
Get-GitHubZen
5981
}
6082
```
6183
84+
#### Example 4: Run a GitHub PowerShell script with a GitHub App using a Client ID and Private Key
85+
86+
Run a script that uses the GitHub PowerShell module with a GitHub App.
87+
This example runs an authenticated script that gets the GitHub App.
88+
89+
```yaml
90+
jobs:
91+
Run-Script:
92+
runs-on: ubuntu-latest
93+
steps:
94+
- name: Run script
95+
uses: PSModule/GitHub-Script@v1
96+
with:
97+
ClientID: ${{ secrets.CLIENT_ID }}
98+
PrivateKey: ${{ secrets.PRIVATE_KEY }}
99+
Script: |
100+
LogGroup "Get-GitHubApp" {
101+
Get-GitHubApp
102+
}
103+
```
104+
62105
## Related projects
63106
64107
- [actions/create-github-app-token](https://github.com/actions/create-github-app-token) -> Functionality will be brought into GitHub PowerShell module.

action.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@ inputs:
1010
description: The script to run.
1111
required: false
1212
Token:
13-
description: The access token to use.
13+
description: Log in using an Installation Access Token (IAT).
1414
required: false
1515
default: ${{ github.token }}
16+
ClientID:
17+
description: Log in using a GitHub App, using the App's Client ID and Private Key.
18+
required: false
19+
PrivateKey:
20+
description: Log in using a GitHub App, using the App's Client ID and Private Key.
21+
required: false
1622
Debug:
1723
description: Enable debug output.
1824
required: false
@@ -41,6 +47,8 @@ runs:
4147
working-directory: ${{ inputs.WorkingDirectory }}
4248
env:
4349
GITHUB_ACTION_INPUT_Token: ${{ inputs.Token }}
50+
GITHUB_ACTION_INPUT_ClientID: ${{ inputs.ClientID }}
51+
GITHUB_ACTION_INPUT_PrivateKey: ${{ inputs.PrivateKey }}
4452
GITHUB_ACTION_INPUT_Debug: ${{ inputs.Debug }}
4553
GITHUB_ACTION_INPUT_Verbose: ${{ inputs.Verbose }}
4654
GITHUB_ACTION_INPUT_Version: ${{ inputs.Version }}

scripts/main.ps1

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,20 @@ if (-not $alreadyImported) {
4848
}
4949
'::endgroup::'
5050

51-
LogGroup 'Connect-Github' {
52-
if (-not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token)) {
53-
Write-Verbose "Setting GITHUB_TOKEN to provided input 'Token'"
54-
Connect-Github -Token $env:GITHUB_ACTION_INPUT_Token
55-
} elseif (-not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_ClientID) -and -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_PrivateKey)) {
56-
Write-Verbose "Setting ClientID and PEM to provided inputs 'ClientID' and 'PEM'"
51+
$providedToken = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token)
52+
$providedClientID = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_ClientID)
53+
$providedPrivateKey = -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_PrivateKey)
54+
Write-Verbose "Provided authentication info:"
55+
Write-Verbose "Token: [$providedToken]"
56+
Write-Verbose "ClientID: [$providedClientID]"
57+
Write-Verbose "PrivateKey: [$providedPrivateKey]"
58+
59+
if ($providedClientID -and $providedPrivateKey) {
60+
LogGroup 'Connect-Github - GitHub App' {
5761
Connect-Github -ClientID $env:GITHUB_ACTION_INPUT_ClientID -PrivateKey $env:GITHUB_ACTION_INPUT_PrivateKey
58-
} elseif (-not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_JWT)) {
59-
Write-Verbose "Setting JWT to provided input 'JWT'"
60-
Connect-Github -JWT $env:GITHUB_ACTION_INPUT_JWT
62+
}
63+
} elseif ($providedToken) {
64+
LogGroup 'Connect-Github - Token' {
65+
Connect-Github -Token $env:GITHUB_ACTION_INPUT_Token
6166
}
6267
}

0 commit comments

Comments
 (0)