This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathVersioning.ps1
More file actions
68 lines (54 loc) · 2.51 KB
/
Copy pathVersioning.ps1
File metadata and controls
68 lines (54 loc) · 2.51 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
Set-StrictMode -Version Latest
New-Module -ScriptBlock {
function Validate-Version([System.Version]$version) {
($version.Major -ge 0) -and ($version.Minor -ge 0) -and ($version.Build -ge 0)
}
function Generate-Version([System.Version]$currentVersion,
[bool]$BumpMajor, [bool] $BumpMinor,
[bool]$BumpPatch, [bool] $BumpBuild,
[int]$BuildNumber = -1) {
if (!(Validate-Version $currentVersion)) {
Die 1 "Invalid current version $currentVersion"
}
if ($BumpMajor) {
New-Object -TypeName System.Version -ArgumentList ($currentVersion.Major + 1), $currentVersion.Minor, $currentVersion.Build, 0
} elseif ($BumpMinor) {
New-Object -TypeName System.Version -ArgumentList $currentVersion.Major, ($currentVersion.Minor + 1), $currentVersion.Build, 0
} elseif ($BumpPatch) {
New-Object -TypeName System.Version -ArgumentList $currentVersion.Major, $currentVersion.Minor, ($currentVersion.Build + 1), 0
} elseif ($BumpBuild) {
if ($BuildNumber -ge 0) {
[System.Version] "$($currentVersion.Major).$($currentVersion.Minor).$($currentVersion.Build).$BuildNumber"
} else {
$timestamp = [System.DateTimeOffset]::UtcNow.ToUnixTimeSeconds()
[System.Version] "$($currentVersion.Major).$($currentVersion.Minor).$($currentVersion.Build).$timestamp"
}
}
else {
$currentVersion
}
}
function Read-Version {
Read-VersionAppVeyor
}
function Write-Version([System.Version]$version) {
Write-VersionVsixManifest $version
Write-VersionSolutionInfo $version
Write-VersionAppVeyor $version
Push-Location $rootDirectory
New-Item -Type Directory -ErrorAction SilentlyContinue build | out-null
Set-Content build\version $version
Pop-Location
}
function Commit-Version([System.Version]$version) {
Write-Host "Committing version bump..."
Push-Location $rootDirectory
Run-Command -Fatal { & $git commit --message "Bump version to $version" -- }
$output = Start-Process $git "commit --all --message ""Bump version to $version""" -wait -NoNewWindow -ErrorAction Continue -PassThru
if ($output.ExitCode -ne 0) {
Die 1 "Error committing version bump"
}
Pop-Location
}
Export-ModuleMember -Function Validate-Version,Write-Version,Commit-Version,Generate-Version,Read-Version
}