Skip to content

Commit

Permalink
Add task 'Set_Module_Version' for Invoke-Build
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuBuisson committed May 1, 2017
1 parent 9573bc0 commit 6ba8263
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
7 changes: 6 additions & 1 deletion PSCodeHealth.BuildSettings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Storing all values in a single $Settings variable to make it obvious that the values are coming from this BuildSettings file when accessing them.
$Settings = @{

BuildOutput = "$PSScriptRoot\BuildOutput"
Dependency = @('Coveralls','Pester','PsScriptAnalyzer')
SourceFolder = "$PSScriptRoot\$($env:APPVEYOR_PROJECT_NAME)"
Expand All @@ -28,4 +28,9 @@ $Settings = @{
Severity = 'Error'
Recurse = $True
}

IsPullRequest = ($env:APPVEYOR_PULL_REQUEST_NUMBER -gt 0)
Version = $env:APPVEYOR_BUILD_VERSION
ManifestPath = '{0}\BuildOutput\{1}\{1}.psd1' -f $PSScriptRoot, $env:APPVEYOR_PROJECT_NAME
VersionRegex = "ModuleVersion\s=\s'(?<ModuleVersion>\S+)'" -as [regex]
}
20 changes: 19 additions & 1 deletion PSCodeHealth.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,28 @@ 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.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."
}
}

# Default task :
task . Clean,
Install_Dependencies,
Test,
Analyze,
Fail_If_Analyze_Findings,
Copy_Source_To_Build_Output
Copy_Source_To_Build_Output,
Set_Module_Version
1 change: 1 addition & 0 deletions PSCodeHealth/PSCodeHealth.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
RootModule = '.\PSCodeHealth.psm1'

# Version number of this module.
# The real version number is set by the build process and is only visible in the build logs and the resulting package
ModuleVersion = '0.1.0'

# ID used to uniquely identify this module
Expand Down

0 comments on commit 6ba8263

Please sign in to comment.