-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset-version.ps1
71 lines (50 loc) · 2 KB
/
set-version.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
using namespace System
param([switch]$VerboseSwitch = $false)
# $Verbose=$true -or $VerboseSwitch
$Verbose=$VerboseSwitch
# Write-Verbose "[$script] [$env:SnippetsInitialized] -not `$env:SnippetsInitialized: $(-not $env:SnippetsInitialized)" -Verbose:$Verbose
$script = $MyInvocation.MyCommand
Push-Location
try {
if ((Get-Location).Path.EndsWith('PowerShell')) {
Set-Location Snippets
}
$gitversion = Get-Command dotnet-gitversion -Verbose:$Verbose -ErrorAction SilentlyContinue
if (-not $gitversion) {
& dotnet tool install gitversion.tool -g
}
$gitversion = Get-Command dotnet-gitversion -Verbose:$Verbose -ErrorAction SilentlyContinue
if (-not $gitversion) {
throw 'Cannot find or install dotnet-gitversion.'
}
$version = & $gitversion /showvariable FullSemVer
$path = Get-Location
$versionFilePath = Join-Path (Get-Location) -Child ".version"
if(-not (Test-Path $versionFilePath)) {
Write-Verbose "[$script] Writing $version to $versionFilePath" -Verbose:$Verbose
Write-Output $version > $versionFilePath
git add $versionFilePath
if ($LASTEXITCODE -ne 0) {
throw "git add $versionFilePath failed with: $LASTEXITCODE"
}
git commit -m "Added version"
if ($LASTEXITCODE -ne 0) {
throw "git commit -m `"Added version`" failed with: $LASTEXITCODE"
}
}
if(Test-Path $versionFilePath) {
Write-Verbose "[$script] `$versionFilePath ($versionFilePath) exists: $(Test-Path $versionFilePath)" -Verbose:$Verbose
$verifiedVersion = Get-Content -Path $versionFilePath -Verbose:$Verbose
Write-Verbose "[$script] `$verifiedVersion: $verifiedVersion" -Verbose:$Verbose
Write-Verbose "[$script] Current Semver is $verifiedVersion" -Verbose:$Verbose
}
$env:SnippetsVersion=$verifiedVersion
return "Current Semver is ${env:SnippetsVersion}"
}
catch {
"Handled: $_"
}
finally {
Pop-Location
$Verbose = $VerboseSwitch
}