-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBumpVersion.ps1
81 lines (65 loc) · 2.33 KB
/
BumpVersion.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
function Has-Version {
param ($version)
# Check if the version argument is provided
if ($version.Count -eq 0) {
Write-Host "Please provide the version number as an argument. Usage: .\bump-version.ps1 <new-version>"
exit
}
# Get the new version from the CLI argument
return $version[0]
}
$newVersion = Has-Version($args)
# Function to validate the version format (X.X.X where X is a number)
function Validate-VersionFormat {
param (
[string]$version
)
# Regex pattern for validating version format (X.X.X-beta)
$versionPattern = '^\d+\.\d+\.\d+$'
# Check if version matches the pattern
return $version -match $versionPattern
}
# Function to update version in a file
function Update-Version {
param (
[string]$filePath,
[string]$searchPattern,
[string]$newVersion,
[string]$replacementPattern
)
# Read the content of the file
$content = Get-Content $filePath
# Replace the version based on the provided pattern and replacement
$updatedContent = $content -replace $searchPattern, $replacementPattern
# Write the updated content back to the file
Set-Content $filePath -Value $updatedContent
Write-Host "Updated version in $filePath to $newVersion"
}
# Check if the version format is valid
if (-not (Validate-VersionFormat $newVersion)) {
Write-Host "Invalid version format. Please use the format: X.X.X where X is a number."
exit
}
# Define the paths and patterns for each file
$filesToUpdate = @(
@{
FilePath = ".\ComposGH\ComposGH.csproj"
SearchPattern = '<Version>(.*?)<\/Version>'
ReplacementPattern = "<Version>$newVersion-beta</Version>"
},
@{
FilePath = ".\Compos\ComposAPI.csproj"
SearchPattern = '<Version>(.*?)<\/Version>'
ReplacementPattern = "<Version>$newVersion-beta</Version>"
},
@{
FilePath = ".\ComposGH\ComposGHInfo.cs"
SearchPattern = 'string GrasshopperVersion = "(.*?)"'
ReplacementPattern = 'string GrasshopperVersion = "' + $newVersion + '-beta"'
}
)
# Loop through each file and update the version
foreach ($file in $filesToUpdate) {
Update-Version -filePath $file.FilePath -searchPattern $file.SearchPattern -newVersion $newVersion -replacementPattern $file.ReplacementPattern
}
Write-Host "Version update completed."