Skip to content

🚀[Feature]: Control if GitHub credentials are persisted #50

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 6 commits into from
May 31, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ To get started with your own GitHub PowerShell based action, [create a new repos
| `ShowInit` | Show information about the initialization. | false | `'false'` |
| `ShowOutput` | Show the script's output. | false | `'false'` |
| `WorkingDirectory` | The working directory where the script runs. | false | `'.'` |
| `PreserveCredentials` | Preserve credentials after script execution. If false, disconnects GitHub contexts and CLI using Disconnect-GitHubAccount. | false | `'true'` |

### Outputs

Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ inputs:
description: The working directory where the script will run from.
required: false
default: '.'
PreserveCredentials:
description: Preserve credentials after script execution. If false, disconnects GitHub contexts and CLI using Disconnect-GitHubAccount.
required: false
default: 'true'

outputs:
result:
Expand All @@ -84,6 +88,7 @@ runs:
PSMODULE_GITHUB_SCRIPT_INPUT_ShowOutput: ${{ inputs.ShowOutput }}
PSMODULE_GITHUB_SCRIPT_INPUT_Prerelease: ${{ inputs.Prerelease }}
PSMODULE_GITHUB_SCRIPT_INPUT_ErrorView: ${{ inputs.ErrorView }}
PSMODULE_GITHUB_SCRIPT_INPUT_PreserveCredentials: ${{ inputs.PreserveCredentials }}
run: |
# ${{ inputs.Name }}
try {
Expand Down
25 changes: 25 additions & 0 deletions scripts/clean.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
Write-Debug "Cleaning up..."
Write-Debug "LASTEXITCODE: $LASTEXITCODE"
Write-Debug "PSMODULE_GITHUB_SCRIPT: $env:PSMODULE_GITHUB_SCRIPT"

# Check if credentials should be preserved
$preserveCredentials = $env:PSMODULE_GITHUB_SCRIPT_INPUT_PreserveCredentials -eq 'true'
Write-Debug "PreserveCredentials: $preserveCredentials"

if (-not $preserveCredentials) {
Write-Debug "Disconnecting GitHub contexts and CLI..."
try {
# Import GitHub module if not already imported
if (-not (Get-Module -Name GitHub -ErrorAction SilentlyContinue)) {
Import-Module -Name GitHub -ErrorAction SilentlyContinue
}

# Disconnect GitHub account if the module and function are available
if (Get-Command Disconnect-GitHubAccount -ErrorAction SilentlyContinue) {
Disconnect-GitHubAccount
Write-Debug "Successfully disconnected GitHub account"
} else {
Write-Debug "Disconnect-GitHubAccount command not available"
}
} catch {
Write-Warning "Failed to disconnect GitHub account: $($_.Exception.Message)"
}
}

$env:PSMODULE_GITHUB_SCRIPT = $false
Write-Debug "PSMODULE_GITHUB_SCRIPT: $env:PSMODULE_GITHUB_SCRIPT"
Loading