This repository has been archived by the owner on Apr 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuild.ps1
78 lines (69 loc) · 2.42 KB
/
Build.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
Param(
# Name of Module
[Parameter(Mandatory=$true)]
[string]$ModuleName,
# By default Update-Manifest increments ModuleVersion; this controls which part of the version number is incremented
[Parameter(ParameterSetName="Increment")]
[ValidateSet("Major","Minor","Build")]
[string]$Increment = "Build",
# When set, and incrementing the ModuleVersion, output the new version number.
[Parameter(ParameterSetName="Increment")]
[switch]$Passthru,
[Parameter(Mandatory=$true)]
[string]$PSGalleryApiKey
)
# ++++++++++++++++++++++++
# Install Powershell Gallery Module
Write-Output "- Install Powershell Gallery"
Try {
if ((Get-Module -ListAvailable -Name 'PowerShellGet') -eq $null) {
Install-Module -Name PowerShellGet -Force
}
} Catch {
Throw [System.NotImplementedException]::New("Unable to install Powershell Gallery Module : $_")
}
# ++++++++++++++++++++++++
# Get Current Version
Write-Output "- Get Current Version"
Try {
[Version]$Version = (Find-Module -Name 'Garbage-Collector' -ErrorAction SilentlyContinue).Version
if($Version -ne $null) {
$Version = switch($Increment) {
"Major" {
[Version]::new($Version.Major + 1, 0)
}
"Minor" {
$Minor = if($Version.Minor -le 0) { 1 } else { $Version.Minor + 1 }
[Version]::new($Version.Major, $Minor)
}
"Build" {
$Build = if($Version.Build -le 0) { 1 } else { $Version.Build + 1 }
[Version]::new($Version.Major, $Version.Minor, $Build)
}
}
} else {
$Version = [version]'0.0.1'
}
} Catch {
Throw [System.NotImplementedException]::New("Unable to get version : $_")
}
# ++++++++++++++++++++++++
# Create Definision File
Write-Output "- Create Definision File"
Try {
$Params = @{
Path = (Join-Path -Path $PSScriptRoot -ChildPath "$ModuleName/$ModuleName.psd1")
ModuleVersion = $Version
}
Update-ModuleManifest @Params
} Catch {
Throw [System.NotImplementedException]::New("Unable to Create Definision File : $_")
}
# ++++++++++++++++++++++++
# Publish Module
Write-Output "- Publish Module"
Try {
publish-module -path (Join-Path -Path $PSScriptRoot -ChildPath $ModuleName) -NuGetApiKey $PSGalleryApiKey
} Catch {
Throw [System.NotImplementedException]::New("Unable to upload on Powershell Gallery : $_")
}