-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPSModulePush.Task.ps1
56 lines (51 loc) · 2.16 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
44
45
46
47
48
49
50
51
52
53
54
55
56
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) {
$PackageSources = Get-PackageSource
foreach($source in $PackageSources) {
if ($source.Name -eq $Script:PSRepository -or $source.Location -eq $PSGalleryUri -or $source.PublishLocation -eq $PSGalleryPublishUri) {
Unregister-PackageSource -Name $source.Name
}
}
$source = @{
Name = $Script:PSRepository
Force = $true
Trusted = $True
ForceBootstrap = $True
}
if (($PSRepository -eq "PSGallery")) {
$source["ProviderName"] = "PowerShellGet"
} else {
if ($PSGalleryUri) {
$source["Location"] = $PSGalleryUri
}
if ($PSGalleryPublishUri) {
$source["PublishLocation"] = $PSGalleryPublishUri
}
}
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