forked from adbertram/PSPostMan
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvoke-PSDeploy.ps1
More file actions
77 lines (71 loc) · 2.98 KB
/
Invoke-PSDeploy.ps1
File metadata and controls
77 lines (71 loc) · 2.98 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
Function Invoke-PSDeploy {
[CmdletBinding()]
PARAM(
[Parameter(Mandatory=$true)]
[string]
$Path
,
[Parameter(Mandatory=$true)]
[string]
$FeedUrl
,
[Parameter(Mandatory=$true)]
[securestring]
$ApiKey
,
[switch]
$Beta
)
Write-Verbose "-------------Start $($myInvocation.InvocationName) -----------------"
Write-Verbose " From Script:'$($myInvocation.ScriptName)' - At Line:$($myInvocation.ScriptLineNumber) char:$($myInvocation.OffsetInLine)"
Write-Verbose " Line '$($myInvocation.Line.Trim())'"
$myInvocation.BoundParameters.GetEnumerator() | ForEach-Object { Write-Verbose " BoundParameter : '$($_.key)' = '$($_.Value)'"}
$myInvocation.UnboundArguments | ForEach-Object { Write-Verbose " UnboundArguments : '$_'"}
Write-Host "Creating Nuget package" -ForegroundColor Cyan
Try {
$ModulePackage = New-PMModulePackage -PassThru -Path "$Path\$(split-path $Path -Leaf)" -Beta:$Beta
} Catch {
Write-Warning "New-PMModulePackage : $($_.exception.message)"
$_
}
Try {
# $Version = Get-NextPSGalleryVersion -Name $env:BHProjectName -ErrorAction Stop
Update-Metadata -Path $env:BHPSModuleManifest -PropertyName FunctionsToExport -Value '*' -ErrorAction stop
} Catch {
"Failed to set FunctionsToExport for '$env:BHProjectName': $_.`nContinuing with existing version"
}
if ($ModulePackage) {
# $ModulePackage = Move-Item -path $ModulePackage -Destination "$Path\Builds" -PassThru
Write-Host "Signing Nuget package" -ForegroundColor Cyan
$Certificate = Get-ChildItem -Path Cert:\CurrentUser\My -CodeSigningCert | Where-Object {$_.NotAfter -gt (Get-date)}| Sort-Object NotAfter -Descending | Select-Object -First 1
$Params = @{
path = $ModulePackage.fullname
CertificateFingerprint = $Certificate.Thumbprint
Timestamper = 'http://timestamp.digicert.com'
Verbose =$VerbosePreference
}
Try {
Set-PMPackageCert @Params
$PackageSigned = $True
} Catch {
Write-Warning "Set-PMPackageCert : $($_.exception.message)"
$PackageSigned = $false
}
if ($PackageSigned) {
Write-Host "Publishing Nuget package" -ForegroundColor Cyan
$Params = @{
Path = $ModulePackage.fullname
FeedUrl = $FeedUrl
ApiKey = $([Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($ApiKey)))
Verbose = $VerbosePreference
}
Write-Verbose "Publish-PMPackage`n$($Params | Format-Table | Out-String)"
Try {
Publish-PMPackage @Params
} Catch {
Write-Warning "Publish-PMPackage : $($_.exception.message)"
}
}
Remove-Item -Path $ModulePackage -Force
}
}