Skip to content

Commit 7b5bfd2

Browse files
Merge pull request #128 from WarehouseFinds/feat/nuget_package
Create a NuGet package for the module
2 parents 6e20fd1 + 61afc15 commit 7b5bfd2

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

.github/actions/ps-release/action.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,18 @@ runs:
6666
Set-StrictMode -Version Latest
6767
[void] (Import-Module InvokeBuild)
6868
Invoke-Build -NugetApiKey ${{ env.PSGALLERY_API_KEY }} -Task Publish
69+
70+
- name: Publish build package to Github Release
71+
shell: pwsh
72+
run: |
73+
Set-StrictMode -Version Latest
74+
[void] (Import-Module InvokeBuild)
75+
Invoke-Build -Task Package
76+
77+
- name: Upload build package to Github Release
78+
uses: actions/upload-release-asset@v1
79+
with:
80+
upload_url: ${{ steps.create_release.outputs.upload_url }}
81+
asset_path: ./build/package/*.nupkg
82+
asset_name: ${{ github.event.repository.name }}-v${{ inputs.release-version }}.nupkg
83+
asset_content_type: application/octet-stream

PSScriptModule.build.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,34 @@ task Build Clean, {
215215
Build-Module @requestParam
216216
}
217217

218+
# Synopsis: Create a NuGet package for the module
219+
task Package {
220+
$packageOutputPath = Join-Path -Path $buildPath -ChildPath 'package'
221+
if (!(Test-Path $packageOutputPath)) {
222+
[void] (New-Item -Path $packageOutputPath -ItemType Directory -Force)
223+
}
224+
225+
$requestParam = @{
226+
Name = "$($moduleName)_local_feed"
227+
SourceLocation = $packageOutputPath
228+
PublishLocation = $packageOutputPath
229+
InstallationPolicy = 'Trusted'
230+
ErrorAction = 'Stop'
231+
}
232+
[void] (Register-PSRepository @requestParam)
233+
234+
$requestParam = @{
235+
Path = (Join-Path -Path $buildPath -ChildPath "out/$moduleName")
236+
Repository = "$($moduleName)_local_feed"
237+
NuGetApiKey = 'ABC123'
238+
ErrorAction = 'Stop'
239+
}
240+
[void] (Publish-Module @requestParam)
241+
242+
[void] (Unregister-PSRepository -Name "$($moduleName)_local_feed")
243+
244+
}
245+
218246
# Synopsis: Publish the module to PSGallery
219247
task Publish -If ($NugetApiKey) {
220248
$requestParam = @{

0 commit comments

Comments
 (0)