-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.ps1
81 lines (64 loc) · 2.54 KB
/
deploy.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<#
.SYNOPSIS
Deploy module to PSGallery
.DESCRIPTION
Deploy module to PSGallery
.PARAMETER VersionTag
Update the module manifest with the version tag (Sample: v10.0.01-alpha)
.PARAMETER NuGetApiKey
PAT for the PSGallery
.PARAMETER DependencyInjection
DependencyInjection SCRIPTBLOCK to dot source mainly for testing
.EXAMPLE
.\deploy.ps1 -VersionTag v10.0.01-alpha -NuGetApiKey $NUGETAPIKEY
.EXAMPLE
$env:$NUGETAPIKEY = '****'
.\deploy.ps1 -VersionTag v10.0.01-alpha
.EXAMPLE
.\deploy.ps1 -VersionTag v10.0.01-alpha -NuGetApiKey $NUGETAPIKEY -DependencyInjection $SCRIPTBLOCK_FOR_TESTING
.LINK
https://raw.githubusercontent.com/rulasg/DemoPsModule/main/deploy.ps1
#>
[cmdletbinding(SupportsShouldProcess, ConfirmImpact='High')]
param(
# Update the module manifest with the version tag (Sample: v10.0.01-alpha)
[Parameter(Mandatory=$false)] [string]$VersionTag,
# PAT for the PSGallery
[Parameter(Mandatory=$false)] [string]$NuGetApiKey,
# DependencyInjection Ps1 file
[Parameter(Mandatory=$false)] [scriptblock]$DependencyInjection
)
$MODULE_PATH = $PSScriptRoot
$MODULE_NAME = $MODULE_PATH | Split-Path -LeafBase
$MODULE_PSD1 = Join-Path -Path $MODULE_PATH -ChildPath "$MODULE_NAME.psd1"
$MODULE_TOOLS = Join-Path -Path $MODULE_PATH -ChildPath "tools"
# Load helper
# We dot souce the ps1 to allow all code to be in the same scope as the script
# Easier to inject for testing with DependecyInjection parameter
. ($MODULE_TOOLS | Join-Path -ChildPath "deploy.Helper.ps1")
if ($DependencyInjection) {
. $DependencyInjection
}
# Process Tag
if($VersionTag){
try {
# Force manifest update even with -whatif
Update-DeployModuleManifest $VersionTag -whatif:$false
}
catch {
Write-Error -Message "Failed to update module manifest with version tag [$VersionTag]. Error: $_"
exit 1
}
}
# check that $NuggetApiKey is null or whitespace
# If it is use environment variable $env:NugetApiKey
if ( [string]::IsNullOrWhiteSpace($NuGetApiKey) ) {
if ( [string]::IsNullOrWhiteSpace($env:NUGETAPIKEY) ) {
# Write-Error -Message '$Env:NUGETAPIKEY is not set. Try running `$Env:NUGETAPIKEY = (Find-DocsFile nugetapikey | rsk | Get-SecretData).Get()`'
Write-Error -Message '$Env:NUGETAPIKEY is not set. Please set the variable with a PSGallery PAT or use -NuGetApiKey parameter.'
exit 1
}
$NuGetApiKey = $env:NUGETAPIKEY
}
# Deploy module to PSGallery
Invoke-DeployModuleToPSGallery -NuGetApiKey $NuGetApiKey -Force -ModuleManifestPath $MODULE_PSD1