Skip to content

Commit

Permalink
Put task 'Set_Module_Version' before 'Push_Build_Changes_To_Repo' to …
Browse files Browse the repository at this point in the history
…persist the version in the manifest
  • Loading branch information
MathieuBuisson committed May 2, 2017
1 parent c327125 commit bda6793
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
3 changes: 1 addition & 2 deletions PSCodeHealth.BuildSettings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ $Settings = @{

IsPullRequest = ($env:APPVEYOR_PULL_REQUEST_NUMBER -gt 0)
Version = $env:APPVEYOR_BUILD_VERSION
NewManifestPath = '{0}\BuildOutput\{1}\{1}.psd1' -f $PSScriptRoot, $env:APPVEYOR_PROJECT_NAME
ManifestPath = '{0}\{1}\{1}.psd1' -f $PSScriptRoot, $env:APPVEYOR_PROJECT_NAME
VersionRegex = "ModuleVersion\s=\s'(?<ModuleVersion>\S+)'" -as [regex]

ModuleName = $env:APPVEYOR_PROJECT_NAME
ManifestPath = '{0}\{1}\{1}.psd1' -f $PSScriptRoot, $env:APPVEYOR_PROJECT_NAME
HeaderPath = "$PSScriptRoot\header-mkdocs.yml"
MkdocsPath = "$PSScriptRoot\mkdocs.yml"
FunctionDocsPath = "$PSScriptRoot\docs\Functions"
Expand Down
38 changes: 19 additions & 19 deletions PSCodeHealth.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,23 @@ Task Build_Documentation {
$HeaderContent | Set-Content -Path $Settings.MkdocsPath -Force
}

task Set_Module_Version {
Write-TaskBanner -TaskName $Task.Name

$ManifestContent = Get-Content -Path $Settings.ManifestPath
$CurrentVersion = $Settings.VersionRegex.Match($ManifestContent).Groups['ModuleVersion'].Value
"Current module version in the manifest : $CurrentVersion"

$ManifestContent -replace $CurrentVersion,$Settings.Version | Set-Content -Path $Settings.ManifestPath -Force
$NewManifestContent = Get-Content -Path $Settings.ManifestPath
$NewVersion = $Settings.VersionRegex.Match($NewManifestContent).Groups['ModuleVersion'].Value
"Updated module version in the manifest : $NewVersion"

If ( $NewVersion -ne $Settings.Version ) {
Throw "Module version was not updated correctly to $($Settings.Version) in the manifest."
}
}

task Push_Build_Changes_To_Repo {
Write-TaskBanner -TaskName $Task.Name

Expand All @@ -155,30 +172,13 @@ task Copy_Source_To_Build_Output {
Copy-Item -Path $Settings.SourceFolder -Destination $Settings.BuildOutput -Recurse
}

task Set_Module_Version {
Write-TaskBanner -TaskName $Task.Name

$ManifestContent = Get-Content -Path $Settings.NewManifestPath
$CurrentVersion = $Settings.VersionRegex.Match($ManifestContent).Groups['ModuleVersion'].Value
"Current module version in the manifest : $CurrentVersion"

$ManifestContent -replace $CurrentVersion,$Settings.Version | Set-Content -Path $Settings.NewManifestPath -Force
$NewManifestContent = Get-Content -Path $Settings.NewManifestPath
$NewVersion = $Settings.VersionRegex.Match($NewManifestContent).Groups['ModuleVersion'].Value
"Updated module version in the manifest : $NewVersion"

If ( $NewVersion -ne $Settings.Version ) {
Throw "Module version was not updated correctly to $($Settings.Version) in the manifest."
}
}

# Default task :
task . Clean,
Install_Dependencies,
Test,
Analyze,
Fail_If_Analyze_Findings,
Build_Documentation,
Set_Module_Version,
Push_Build_Changes_To_Repo,
Copy_Source_To_Build_Output,
Set_Module_Version
Copy_Source_To_Build_Output

0 comments on commit bda6793

Please sign in to comment.