Skip to content
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
34 changes: 34 additions & 0 deletions .github/actions/Cleanup-PSModulePrereleases/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Cleanup-PSModulePrereleases
description: Cleanup prerelease GitHub releases associated with the current pull request branch.
author: PSModule

inputs:
AutoCleanup:
description: Control whether to automatically delete prerelease tags.
required: false
default: 'true'
WhatIf:
description: If specified, the action will only log the changes it would make.
required: false
default: 'false'
WorkingDirectory:
description: The working directory where the script will run from.
required: false
default: '.'

runs:
using: composite
steps:
- name: Install-PSModule
uses: ./_wf/.github/actions/Install-PSModule

- name: Cleanup Prereleases
if: inputs.AutoCleanup == 'true' || inputs.WhatIf == 'true'
shell: pwsh
working-directory: ${{ inputs.WorkingDirectory }}
env:
PSMODULE_CLEANUP_PSMODULEPRERELEASES_INPUT_WhatIf: ${{ inputs.WhatIf }}
PSMODULE_CLEANUP_PSMODULEPRERELEASES_CONTEXT_ReleaseTag: ${{ env.PSMODULE_PUBLISH_PSMODULE_CONTEXT_ReleaseTag }}
run: |
# Cleanup prerelease tags
${{ github.action_path }}/src/cleanup.ps1

Check warning

Code scanning / CodeQL

Code injection Medium

Potential code injection in
${ github.action_path }
, which may be controlled by an external user.
Comment thread
MariusStorhaug marked this conversation as resolved.
Dismissed
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Import-Module -Name 'Helpers' -Force

#region Load inputs
LogGroup 'Load inputs' {
$whatIf = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_WhatIf -eq 'true'
$whatIf = $env:PSMODULE_CLEANUP_PSMODULEPRERELEASES_INPUT_WhatIf -eq 'true'

$githubEventJson = Get-Content -Raw $env:GITHUB_EVENT_PATH
$githubEvent = $githubEventJson | ConvertFrom-Json
Expand All @@ -27,7 +27,7 @@ LogGroup 'Load inputs' {
Write-Host "Prerelease name: [$prereleaseName]"
Write-Host "WhatIf: [$whatIf]"

$publishedReleaseTag = $env:PSMODULE_PUBLISH_PSMODULE_CONTEXT_ReleaseTag
$publishedReleaseTag = $env:PSMODULE_CLEANUP_PSMODULEPRERELEASES_CONTEXT_ReleaseTag
if (-not [string]::IsNullOrWhiteSpace($publishedReleaseTag)) {
Write-Host "Published tag: [$publishedReleaseTag] (excluded from cleanup)"
}
Expand Down
17 changes: 1 addition & 16 deletions .github/actions/Publish-PSModule/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ inputs:
description: Name of the module to publish.
required: false
ModulePath:
description: Path to the folder containing the <Name>/ module subdirectory from Build-PSModule. A module artifact must exist before invoking this action.
description: Path to the folder containing the <Name>/ module subdirectory from Build-PSModule.
required: false
default: outputs/module
APIKey:
description: PowerShell Gallery API Key.
required: true
AutoCleanup:
description: Control whether to automatically delete the prerelease tags after the stable release is created.
required: false
default: 'true'
WhatIf:
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
Expand Down Expand Up @@ -71,14 +67,3 @@ runs:
PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsReleaseName: ${{ inputs.UsePRTitleAsReleaseName }}
PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsNotesHeading: ${{ inputs.UsePRTitleAsNotesHeading }}
run: ${{ github.action_path }}/src/publish.ps1

- name: Cleanup Prereleases
if: env.PSMODULE_PUBLISH_PSMODULE_CONTEXT_IsPrerelease != 'true' && (inputs.AutoCleanup == 'true' || inputs.WhatIf == 'true')
shell: pwsh
working-directory: ${{ inputs.WorkingDirectory }}
env:
PSMODULE_PUBLISH_PSMODULE_INPUT_WhatIf: ${{ inputs.WhatIf }}
PSMODULE_PUBLISH_PSMODULE_CONTEXT_ReleaseTag: ${{ env.PSMODULE_PUBLISH_PSMODULE_CONTEXT_ReleaseTag }}
run: |
# Cleanup prerelease tags
${{ github.action_path }}/src/cleanup.ps1
4 changes: 1 addition & 3 deletions .github/actions/Publish-PSModule/src/publish.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ LogGroup 'Resolve version from manifest' {
PRHeadRef = $prHeadRef
} | Format-List | Out-String

# Expose publish context to subsequent steps so the cleanup step can gate on release type.
$envLine = "PSMODULE_PUBLISH_PSMODULE_CONTEXT_IsPrerelease=$($createPrerelease.ToString().ToLower())"
$envLine | Out-File -Path $env:GITHUB_ENV -Append -Encoding utf8NoBOM
# Expose release tag to subsequent steps so cleanup can exclude the just-published tag.
"PSMODULE_PUBLISH_PSMODULE_CONTEXT_ReleaseTag=$releaseTag" | Out-File -Path $env:GITHUB_ENV -Append -Encoding utf8NoBOM
}
#endregion Resolve version from manifest
Expand Down
12 changes: 11 additions & 1 deletion .github/workflows/Publish-Module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
persist-credentials: false

- name: Publish module
if: fromJson(inputs.Settings).Publish.Module.Resolution.ReleaseType != 'None'
uses: ./_wf/.github/actions/Publish-PSModule
env:
GH_TOKEN: ${{ github.token }}
Expand All @@ -46,8 +47,17 @@ jobs:
ModulePath: outputs/module
APIKey: ${{ secrets.APIKey }}
WhatIf: ${{ github.repository == 'PSModule/Process-PSModule' }}
AutoCleanup: ${{ fromJson(inputs.Settings).Publish.Module.AutoCleanup }}
UsePRTitleAsReleaseName: ${{ fromJson(inputs.Settings).Publish.Module.UsePRTitleAsReleaseName }}
UsePRBodyAsReleaseNotes: ${{ fromJson(inputs.Settings).Publish.Module.UsePRBodyAsReleaseNotes }}
UsePRTitleAsNotesHeading: ${{ fromJson(inputs.Settings).Publish.Module.UsePRTitleAsNotesHeading }}
WorkingDirectory: ${{ fromJson(inputs.Settings).WorkingDirectory }}

- name: Cleanup prereleases
if: fromJson(inputs.Settings).Publish.Module.Resolution.ReleaseType != 'Prerelease'
uses: ./_wf/.github/actions/Cleanup-PSModulePrereleases
env:
GH_TOKEN: ${{ github.token }}
with:
WhatIf: ${{ github.repository == 'PSModule/Process-PSModule' }}
AutoCleanup: ${{ fromJson(inputs.Settings).Publish.Module.AutoCleanup }}
WorkingDirectory: ${{ fromJson(inputs.Settings).WorkingDirectory }}
Loading