Skip to content

Commit 86197ff

Browse files
committed
Simplify version bump script with stash push/pop
1 parent e6697be commit 86197ff

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

Build/set-version-UnitsNet.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,13 @@ $numberExtensionsProjFile = "$root\UnitsNet.NumberExtensions\UnitsNet.NumberExte
5656
$nanoFrameworkNuspecGeneratorFile = "$root\CodeGen\Generators\NanoFrameworkGen\NuspecGenerator.cs"
5757
$winrtAssemblyInfoFile = "$root\UnitsNet.WindowsRuntimeComponent\Properties\AssemblyInfo.cs"
5858
$winrtNuspecFile = "$root\UnitsNet.WindowsRuntimeComponent\UnitsNet.WindowsRuntimeComponent.nuspec"
59-
$versionFiles = @($projFile, $numberExtensionsProjFile, $winrtAssemblyInfoFile, $winrtNuspecFile)
6059

6160
# Use UnitsNet.Common.props version as base if bumping major/minor/patch
6261
$newVersion = Get-NewProjectVersion $projFile $paramSet $setVersion $bumpVersion
6362

63+
# Reset and stash any other local changes.
64+
Invoke-StashPush
65+
6466
# Update project files
6567
Set-ProjectVersion $projFile $newVersion
6668
Set-ProjectVersion $numberExtensionsProjFile $newVersion
@@ -73,6 +75,9 @@ Set-NuspecVersion $winrtNuspecFile $newVersion
7375
Set-NuspecVersion $nanoFrameworkNuspecGeneratorFile $newVersion
7476

7577
# Git commit and tag
76-
Invoke-CommitVersionBump @("UnitsNet") $versionFiles $newVersion
78+
Invoke-CommitVersionBump @("UnitsNet") $newVersion
7779
Invoke-TagVersionBump "UnitsNet" $newVersion
7880
Invoke-TagVersionBump "UnitsNet.NumberExtensions" $newVersion
81+
82+
# Restore any local changes.
83+
Invoke-StashPop

Build/set-version.psm1

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,22 @@ function Get-NewProjectVersion(
1616
}
1717
}
1818

19+
function Invoke-StashPush() {
20+
git reset --quiet
21+
git stash --include-untracked --message "Before version bump" --quiet
22+
}
23+
24+
function Invoke-StashPop() {
25+
git stash pop --quiet
26+
}
27+
1928
function Invoke-CommitVersionBump(
2029
[string[]]$projectNames,
21-
[string[]]$projectPaths,
2230
[string] $newSemVer) {
2331
try {
24-
Write-Host -Foreground Green Resetting git index.
25-
git reset
26-
27-
ForEach ($path in $projectPaths) {
28-
$path = Resolve-Path $path
29-
Write-Host -Foreground Green "Staging file: $path"
30-
git add $path
31-
}
32-
3332
$projectNamesConcat = [string]::Join(", ", $projectNames)
3433
Write-Host -Foreground Green "Committing new version: $newSemVer"
35-
git commit -m "${projectNamesConcat}: $newSemVer"
34+
git commit -a -m "${projectNamesConcat}: $newSemVer"
3635
}
3736
catch {
3837
$err = $PSItem.Exception
@@ -159,4 +158,11 @@ function Resolve-Error ($ErrorRecord=$Error[0])
159158
}
160159
}
161160

162-
export-modulemember -function Get-NewProjectVersion, Invoke-CommitVersionBump, Invoke-TagVersionBump, Set-ProjectVersion, Set-AssemblyInfoVersion, Set-NuspecVersion
161+
export-modulemember -function Get-NewProjectVersion,
162+
Invoke-CommitVersionBump,
163+
Invoke-TagVersionBump,
164+
Set-ProjectVersion,
165+
Set-AssemblyInfoVersion,
166+
Set-NuspecVersion,
167+
Invoke-StashPush,
168+
Invoke-StashPop

0 commit comments

Comments
 (0)