Skip to content

🩹 [Patch]: Remove reliance on GitHub #51

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 4 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 0 additions & 2 deletions .github/workflows/Action-Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ jobs:
env:
GITHUB_TOKEN: ${{ github.token }}
with:
Verbose: true
Debug: true
Name: PSModuleTest
WorkingDirectory: tests
APIKey: ${{ secrets.APIKEY }}
Expand Down
28 changes: 3 additions & 25 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,6 @@ inputs:
description: If specified, the action will only log the changes it would make, but will not actually create or delete any releases or tags.
required: false
default: 'false'
Debug:
description: Enable debug output.
required: false
default: 'false'
Verbose:
description: Enable verbose output.
required: false
default: 'false'
Version:
description: Specifies the version of the GitHub module to be installed. The value must be an exact version.
required: false
Prerelease:
description: Allow prerelease versions if available.
required: false
default: 'false'
WorkingDirectory:
description: The working directory where the script will run from.
required: false
Expand All @@ -83,7 +68,8 @@ runs:
uses: PSModule/Install-PSModuleHelpers@v1

- name: Run Publish-PSModule
uses: PSModule/GitHub-Script@v1
shell: pwsh
working-directory: ${{ inputs.WorkingDirectory }}
env:
PSMODULE_PUBLISH_PSMODULE_INPUT_Name: ${{ inputs.Name }}
PSMODULE_PUBLISH_PSMODULE_INPUT_ModulePath: ${{ inputs.ModulePath }}
Expand All @@ -98,12 +84,4 @@ runs:
PSMODULE_PUBLISH_PSMODULE_INPUT_PatchLabels: ${{ inputs.PatchLabels }}
PSMODULE_PUBLISH_PSMODULE_INPUT_VersionPrefix: ${{ inputs.VersionPrefix }}
PSMODULE_PUBLISH_PSMODULE_INPUT_WhatIf: ${{ inputs.WhatIf }}
PSMODULE_PUBLISH_PSMODULE_INPUT_WorkingDirectory: ${{ inputs.WorkingDirectory }}
with:
Name: Publish-PSModule
Debug: ${{ inputs.Debug }}
Prerelease: ${{ inputs.Prerelease }}
Verbose: ${{ inputs.Verbose }}
Version: ${{ inputs.Version }}
WorkingDirectory: ${{ inputs.WorkingDirectory }}
Script: ${{ github.action_path }}/scripts/main.ps1
run: ${{ github.action_path }}/scripts/main.ps1
56 changes: 30 additions & 26 deletions scripts/helpers/Publish-PSModule.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
function Publish-PSModule {
<#
.SYNOPSIS
Publishes a module to the PowerShell Gallery and GitHub Pages.
.SYNOPSIS
Publishes a module to the PowerShell Gallery and creates a GitHub Release.

.DESCRIPTION
Publishes a module to the PowerShell Gallery and GitHub Pages.
.DESCRIPTION
Publishes a module to the PowerShell Gallery and creates a GitHub Release.

.EXAMPLE
Publish-PSModule -Name 'PSModule.FX' -APIKey $env:PSGALLERY_API_KEY
.EXAMPLE
Publish-PSModule -Name 'PSModule.FX' -APIKey $env:PSGALLERY_API_KEY
#>
[OutputType([void])]
[CmdletBinding()]
Expand All @@ -19,6 +19,10 @@
'PSUseDeclaredVarsMoreThanAssignments', '',
Justification = 'LogGroup - Scoping affects the variables line of sight.'
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidUsingWriteHost', '',
Justification = 'Log outputs to GitHub Actions logs.'
)]
param(
# Name of the module to process.
[Parameter()]
Expand All @@ -33,7 +37,7 @@
[string] $APIKey
)

LogGroup 'Set configuration' {
Set-GitHubLogGroup 'Set configuration' {
$autoCleanup = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_AutoCleanup -eq 'true'
$autoPatching = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_AutoPatching -eq 'true'
$incrementalPrerelease = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_IncrementalPrerelease -eq 'true'
Expand All @@ -59,18 +63,18 @@
} | Format-List | Out-String
}

LogGroup 'Event information - JSON' {
Set-GitHubLogGroup 'Event information - JSON' {
$githubEventJson = Get-Content $env:GITHUB_EVENT_PATH
$githubEventJson | Format-List | Out-String
}

LogGroup 'Event information - Object' {
Set-GitHubLogGroup 'Event information - Object' {
$githubEvent = $githubEventJson | ConvertFrom-Json
$pull_request = $githubEvent.pull_request
$githubEvent | Format-List | Out-String
}

LogGroup 'Event information - Details' {
Set-GitHubLogGroup 'Event information - Details' {
$defaultBranchName = (gh repo view --json defaultBranchRef | ConvertFrom-Json | Select-Object -ExpandProperty defaultBranchRef).name
$isPullRequest = $githubEvent.PSObject.Properties.Name -Contains 'pull_request'
if (-not ($isPullRequest -or $whatIf)) {
Expand All @@ -96,17 +100,17 @@
Write-Output '-------------------------------------------------'
}

LogGroup 'Pull request - details' {
Set-GitHubLogGroup 'Pull request - details' {
$pull_request | Format-List | Out-String
}

LogGroup 'Pull request - Labels' {
Set-GitHubLogGroup 'Pull request - Labels' {
$labels = @()
$labels += $pull_request.labels.name
$labels | Format-List | Out-String
}

LogGroup 'Calculate release type' {
Set-GitHubLogGroup 'Calculate release type' {
$createRelease = $isMerged -and $targetIsDefaultBranch
$closedPullRequest = $prIsClosed -and -not $isMerged
$createPrerelease = $labels -Contains 'prerelease' -and -not $createRelease -and -not $closedPullRequest
Expand Down Expand Up @@ -134,7 +138,7 @@
Write-Output '-------------------------------------------------'
}

LogGroup 'Get latest version - GitHub' {
Set-GitHubLogGroup 'Get latest version - GitHub' {
$releases = gh release list --json 'createdAt,isDraft,isLatest,isPrerelease,name,publishedAt,tagName' | ConvertFrom-Json
if ($LASTEXITCODE -ne 0) {
Write-Error 'Failed to list all releases for the repo.'
Expand All @@ -157,7 +161,7 @@
Write-Output '-------------------------------------------------'
}

LogGroup 'Get latest version - PSGallery' {
Set-GitHubLogGroup 'Get latest version - PSGallery' {
$count = 5
$delay = 10
for ($i = 1; $i -le $count; $i++) {
Expand Down Expand Up @@ -186,7 +190,7 @@
Write-Output '-------------------------------------------------'
}

LogGroup 'Get latest version - Manifest' {
Set-GitHubLogGroup 'Get latest version - Manifest' {
Add-PSModulePath -Path (Split-Path -Path $ModulePath -Parent)
$manifestFilePath = Join-Path $ModulePath "$Name.psd1"
Write-Output "Module manifest file path: [$manifestFilePath]"
Expand All @@ -208,7 +212,7 @@
Write-Output '-------------------------------------------------'
}

LogGroup 'Get latest version' {
Set-GitHubLogGroup 'Get latest version' {
Write-Output "GitHub: [$($ghReleaseVersion.ToString())]"
Write-Output "PSGallery: [$($psGalleryVersion.ToString())]"
Write-Output "Manifest: [$($manifestVersion.ToString())] (ignored)"
Expand All @@ -220,7 +224,7 @@
Write-Output '-------------------------------------------------'
}

LogGroup 'Calculate new version' {
Set-GitHubLogGroup 'Calculate new version' {
# - Increment based on label on PR
$newVersion = New-PSSemVer -Version $latestVersion
$newVersion.Prefix = $versionPrefix
Expand Down Expand Up @@ -302,7 +306,7 @@
}
Write-Output "New version is [$($newVersion.ToString())]"

LogGroup 'Update module manifest' {
Set-GitHubLogGroup 'Update module manifest' {
Write-Output 'Bump module version -> module metadata: Update-ModuleMetadata'
$manifestNewVersion = "$($newVersion.Major).$($newVersion.Minor).$($newVersion.Patch)"
Set-ModuleManifest -Path $manifestFilePath -ModuleVersion $manifestNewVersion -Verbose:$false
Expand All @@ -314,12 +318,12 @@
Show-FileContent -Path $manifestFilePath
}

LogGroup 'Install module dependencies' {
Set-GitHubLogGroup 'Install module dependencies' {
Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath
}

if ($createPrerelease -or $createRelease -or $whatIf) {
LogGroup 'Publish-ToPSGallery' {
Set-GitHubLogGroup 'Publish-ToPSGallery' {
if ($createPrerelease) {
$publishPSVersion = "$($newVersion.Major).$($newVersion.Minor).$($newVersion.Patch)-$($newVersion.Prerelease)"
} else {
Expand All @@ -343,7 +347,7 @@
" PowerShell Gallery [$publishPSVersion]($psGalleryReleaseLink) has been created.'"
)
} else {
Write-GitHubNotice "Module [$Name - $publishPSVersion] published to the PowerShell Gallery."
Write-Host "::notice::Module [$Name - $publishPSVersion] published to the PowerShell Gallery."
gh pr comment $pull_request.number -b "Module [$Name - $publishPSVersion]($psGalleryReleaseLink) published to the PowerShell Gallery."
if ($LASTEXITCODE -ne 0) {
Write-Error 'Failed to comment on the pull request.'
Expand All @@ -352,7 +356,7 @@
}
}

LogGroup 'New-GitHubRelease' {
Set-GitHubLogGroup 'New-GitHubRelease' {
Write-Output 'Create new GitHub release'
if ($createPrerelease) {
if ($whatIf) {
Expand Down Expand Up @@ -384,17 +388,17 @@
exit $LASTEXITCODE
}
}
Write-GitHubNotice "Release created: [$newVersion]"
Write-Host "::notice::Release created: [$newVersion]"
}
}

LogGroup 'List prereleases using the same name' {
Set-GitHubLogGroup 'List prereleases using the same name' {
$prereleasesToCleanup = $releases | Where-Object { $_.tagName -like "*$prereleaseName*" }
$prereleasesToCleanup | Select-Object -Property name, publishedAt, isPrerelease, isLatest | Format-Table | Out-String
}

if ((($closedPullRequest -or $createRelease) -and $autoCleanup) -or $whatIf) {
LogGroup "Cleanup prereleases for [$prereleaseName]" {
Set-GitHubLogGroup "Cleanup prereleases for [$prereleaseName]" {
foreach ($rel in $prereleasesToCleanup) {
$relTagName = $rel.tagName
Write-Output "Deleting prerelease: [$relTagName]."
Expand Down
4 changes: 2 additions & 2 deletions scripts/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ for ($i = 0; $i -lt $retryCount; $i++) {
}

$path = (Join-Path -Path $PSScriptRoot -ChildPath 'helpers')
LogGroup "Loading helper scripts from [$path]" {
Set-GitHubLogGroup "Loading helper scripts from [$path]" {
Get-ChildItem -Path $path -Filter '*.ps1' -Recurse | ForEach-Object {
Write-Verbose "[$($_.FullName)]"
. $_.FullName
}
}

LogGroup 'Loading inputs' {
Set-GitHubLogGroup 'Loading inputs' {
$name = if ([string]::IsNullOrEmpty($env:PSMODULE_PUBLISH_PSMODULE_INPUT_Name)) {
$env:GITHUB_REPOSITORY_NAME
} else {
Expand Down
Loading