Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 3 additions & 9 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,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 @@ -99,11 +100,4 @@ runs:
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
40 changes: 20 additions & 20 deletions scripts/helpers/Publish-PSModule.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
function Publish-PSModule {
<#
.SYNOPSIS
Publishes a module to the PowerShell Gallery and GitHub Pages.
Publishes a module to the PowerShell Gallery.
Comment thread
MariusStorhaug marked this conversation as resolved.
Outdated

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

.EXAMPLE
Publish-PSModule -Name 'PSModule.FX' -APIKey $env:PSGALLERY_API_KEY
Expand Down Expand Up @@ -33,7 +33,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 +59,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 +96,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 +134,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 +157,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 +186,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 +208,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 +220,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 +302,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 +314,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 Down Expand Up @@ -352,7 +352,7 @@
}
}

LogGroup 'New-GitHubRelease' {
Set-GitHubLogGroup 'New-GitHubRelease' {
Write-Output 'Create new GitHub release'
if ($createPrerelease) {
if ($whatIf) {
Expand Down Expand Up @@ -388,13 +388,13 @@
}
}

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