-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpsakeFile.ps1
More file actions
61 lines (55 loc) · 2.74 KB
/
Copy pathpsakeFile.ps1
File metadata and controls
61 lines (55 loc) · 2.74 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
properties {
# Set this to $true to create a module with a monolithic PSM1
$PSBPreference.Build.CompileModule = $false
$PSBPreference.Help.DefaultLocale = 'en-US'
$PSBPreference.Test.OutputFile = 'out/testResults.xml'
$PSBPreference.General.ModuleVersion = dotnet-gitversion /showvariable MajorMinorPatch
$PSBPreference.Test.ScriptAnalysis.FailBuildOnSeverityLevel = 'Error'
$PSBPreference.Test.ImportModule = $true
}
task Default -depends buildmodule
# task Test -FromModule PowerShellBuild -minimumVersion '0.6.1' -depends UpdateVersion, build, pester
# task build -FromModule PowerShellBuild -minimumVersion '0.6.1' #-depends UpdateVersion
task init -FromModule PowerShellBuild -minimumVersion '0.6.1'
task buildmodule -depends init, clean, stagefiles, UpdateVersion, GENERATEMARKDOWN, GENERATEMAML, BUILDHELP, Test
task release -depends init, clean, stagefiles, UpdateVersion, GENERATEMARKDOWN, GENERATEMAML, BUILDHELP, publish
Task UpdateVersion {
$file = "$env:BHBuildOutput\$env:BHProjectName.psd1"
Write-Host ("Updating version in {0}" -f $file)
$newVersion = dotnet-gitversion /showvariable MajorMinorPatch
$prereleaseVersion = (dotnet-gitversion /showvariable NuGetPreReleaseTag) -replace "-",""
if (! $prereleaseVersion) {
$prereleaseVersion = ' '
}
#update version in psd1
# Read all lines from the file
$content = Get-Content -Path $file
# Find and replace the ModuleVersion line
$versionPattern = '^\s*ModuleVersion\s*=\s*[''"]([0-9]+\.?)+[''"]'
$newVersionLine = "ModuleVersion = '$NewVersion'"
$updated = $false
for ($i = 0; $i -lt $content.Count; $i++) {
if ($content[$i] -match $versionPattern) {
$content[$i] = $content[$i] -replace $versionPattern, $newVersionLine
$updated = $true
break
}
}
if (-not $updated) {
throw "ModuleVersion line not found in the PSD1 file"
}
# Save the updated content
$content | Set-Content -Path $file -Encoding UTF8
Write-Host "Successfully updated ModuleVersion to $NewVersion in $Path"
if ($prereleaseVersion -and $prereleaseVersion -notlike "*tag*") {
$moduleversion = ("{0}-{1}" -f $moduleversion, $prereleaseVersion)
update-ModuleManifest -Path $file -ModuleVersion $newVersion -Prerelease $prereleaseVersion
}
$moduledata = Import-PowerShellDataFile -Path $file
$moduleversion = $moduledata.ModuleVersion
$prereleaseVersion = $moduledata.PrivateData.psdata.prerelease
if ($prereleaseVersion -and $prereleaseVersion -notlike "*tag*") {
$moduleversion = ("{0}-{1}" -f $moduleversion, $prereleaseVersion)
}
Write-Host ("Version is: {0}" -f $moduleversion)
} -description 'updates the psd1 version in releases'