-
Notifications
You must be signed in to change notification settings - Fork 0
/
PSModulePush.Task.ps1
43 lines (40 loc) · 1.76 KB
/
PSModulePush.Task.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
Add-BuildTask PSModulePush {
if ($BuildSystem -ne 'None' -and
$BranchName -in "master","main" -and
-not [string]::IsNullOrWhiteSpace($PSGalleryKey)) {
# If the $PSGalleryUri is set, make sure that's where we publish....
if ($PSGalleryUri -and $Script:PSRepository) {
$PackageSource = Get-PSRepository -Name $Script:PSRepository -ErrorAction Ignore
If (-Not $PackageSource -or $PackageSource.PublishLocation -ne $PSGalleryUri) {
$source = @{
Name = $Script:PSRepository
Location = $PSGalleryUri
Force = $true
Trusted = $True
ForceBootstrap = $True
ProviderName = $PowerShellGet
}
Register-PackageSource @source
}
}
$publishModuleSplat = @{
Path = $PSModuleOutputPath
NuGetApiKey = $PSGalleryKey
Verbose = $true
Force = $true
Repository = $Script:PSRepository
ErrorAction = 'Stop'
}
"Files in module output:"
Get-ChildItem $PSModuleOutputPath -Recurse -File |
Select-Object -Expand FullName
"Publishing [$PSModuleOutputPath] to [$Script:PSRepository]"
Publish-Module @publishModuleSplat
} else {
Write-Warning ("Skipping publish: To publish, ensure that...`n" +
"`t* You are in a known build system (Current: $BuildSystem)`n" +
"`t* You are committing to the main branch (Current: $BranchName) `n" +
"`t* The repository APIKey is defined in `$PSGalleryKey (Current: $(![string]::IsNullOrWhiteSpace($PSGalleryKey)))")
}
}
Add-BuildTask PSGallery PSModulePush