diff --git a/.github/actions/Cleanup-PSModulePrereleases/action.yml b/.github/actions/Cleanup-PSModulePrereleases/action.yml new file mode 100644 index 00000000..af728ffd --- /dev/null +++ b/.github/actions/Cleanup-PSModulePrereleases/action.yml @@ -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 diff --git a/.github/actions/Publish-PSModule/src/cleanup.ps1 b/.github/actions/Cleanup-PSModulePrereleases/src/cleanup.ps1 similarity index 94% rename from .github/actions/Publish-PSModule/src/cleanup.ps1 rename to .github/actions/Cleanup-PSModulePrereleases/src/cleanup.ps1 index b7e64ce7..546593a8 100644 --- a/.github/actions/Publish-PSModule/src/cleanup.ps1 +++ b/.github/actions/Cleanup-PSModulePrereleases/src/cleanup.ps1 @@ -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 @@ -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)" } diff --git a/.github/actions/Publish-PSModule/action.yml b/.github/actions/Publish-PSModule/action.yml index c17c16e2..c855fe20 100644 --- a/.github/actions/Publish-PSModule/action.yml +++ b/.github/actions/Publish-PSModule/action.yml @@ -7,16 +7,12 @@ inputs: description: Name of the module to publish. required: false ModulePath: - description: Path to the folder containing the / module subdirectory from Build-PSModule. A module artifact must exist before invoking this action. + description: Path to the folder containing the / 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 @@ -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 diff --git a/.github/actions/Publish-PSModule/src/publish.ps1 b/.github/actions/Publish-PSModule/src/publish.ps1 index 6b08e27f..d99b31be 100644 --- a/.github/actions/Publish-PSModule/src/publish.ps1 +++ b/.github/actions/Publish-PSModule/src/publish.ps1 @@ -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 diff --git a/.github/workflows/Publish-Module.yml b/.github/workflows/Publish-Module.yml index e46b3b1c..ee1bbcb6 100644 --- a/.github/workflows/Publish-Module.yml +++ b/.github/workflows/Publish-Module.yml @@ -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 }} @@ -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 }}