-
Notifications
You must be signed in to change notification settings - Fork 7
/
publish.ps1
47 lines (36 loc) · 1.67 KB
/
publish.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
# **************************************************************************
# Copyright (c) Cloud Native Foundation.
# SPDX-License-Identifier: Apache-2.0
# **************************************************************************
<#
.SYNOPSIS
Publish the CloudEvents.Sdk module to PSGallery
.PARAMETER NuGetApiKey
PowerShell Gallery API Key to be used to publish the module
.PARAMETER ModuleReleaseDir
Parent directory of the 'CloudEvents.Sdk' module that will be published
#>
param(
[Parameter(Mandatory = $true)]
[string]
$NuGetApiKey,
[Parameter(Mandatory = $true)]
[ValidateScript({ Test-Path $_ })]
[string]
$ModuleReleaseDir
)
# Work with full path in case relative path is provided
$ModuleReleaseDir = (Resolve-Path $ModuleReleaseDir).Path
$moduleName = 'CloudEvents.Sdk'
# Build is successful and all tests pass
$env:PSModulePath += [IO.Path]::PathSeparator + $ModuleReleaseDir
$localModule = Get-Module $moduleName -ListAvailable
$psGalleryModule = Find-Module -Name $moduleName -Repository PSGallery
# Throw an exception if module with the same version is availble on PSGallery
if ( $null -ne $psGalleryModule -and `
$null -ne $localModule -and `
$psGalleryModule.Version -eq $localModule.Version ) {
throw "'$moduleName' module with version '$($localModule.Version)' is already available on PSGallery"
}
Write-Host "Performing operation: Publish-Module -Name $moduleName -RequiredVersion $($localModule.Version) -NuGetApiKey *** -Repository PSGallery -Confirm:`$false"
Publish-Module -Name $moduleName -RequiredVersion $localModule.Version -NuGetApiKey $NuGetApiKey -Repository PSGallery -Confirm:$false -ErrorAction Stop