diff --git a/.github/actions/ps-release/action.yml b/.github/actions/ps-release/action.yml index 2c9d3b0..ba498d8 100644 --- a/.github/actions/ps-release/action.yml +++ b/.github/actions/ps-release/action.yml @@ -66,3 +66,18 @@ runs: Set-StrictMode -Version Latest [void] (Import-Module InvokeBuild) Invoke-Build -NugetApiKey ${{ env.PSGALLERY_API_KEY }} -Task Publish + + - name: Publish build package to Github Release + shell: pwsh + run: | + Set-StrictMode -Version Latest + [void] (Import-Module InvokeBuild) + Invoke-Build -Task Package + + - name: Upload build package to Github Release + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./build/package/*.nupkg + asset_name: ${{ github.event.repository.name }}-v${{ inputs.release-version }}.nupkg + asset_content_type: application/octet-stream diff --git a/PSScriptModule.build.ps1 b/PSScriptModule.build.ps1 index 002438d..d89aaa3 100644 --- a/PSScriptModule.build.ps1 +++ b/PSScriptModule.build.ps1 @@ -215,6 +215,34 @@ task Build Clean, { Build-Module @requestParam } +# Synopsis: Create a NuGet package for the module +task Package { + $packageOutputPath = Join-Path -Path $buildPath -ChildPath 'package' + if (!(Test-Path $packageOutputPath)) { + [void] (New-Item -Path $packageOutputPath -ItemType Directory -Force) + } + + $requestParam = @{ + Name = "$($moduleName)_local_feed" + SourceLocation = $packageOutputPath + PublishLocation = $packageOutputPath + InstallationPolicy = 'Trusted' + ErrorAction = 'Stop' + } + [void] (Register-PSRepository @requestParam) + + $requestParam = @{ + Path = (Join-Path -Path $buildPath -ChildPath "out/$moduleName") + Repository = "$($moduleName)_local_feed" + NuGetApiKey = 'ABC123' + ErrorAction = 'Stop' + } + [void] (Publish-Module @requestParam) + + [void] (Unregister-PSRepository -Name "$($moduleName)_local_feed") + +} + # Synopsis: Publish the module to PSGallery task Publish -If ($NugetApiKey) { $requestParam = @{