set-version-metadata.ps1 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Script for reading generated version values and updating metadata properties
  2. #read major / minor version values from version.h (generated by cmake via version.h.in)
  3. $majorVer=99
  4. $minorVer=99
  5. $patchVer=0
  6. $buildNum=0
  7. #define regular expressions to be used when checking for #define statements
  8. $versionSniffingRegex = "(\s*#define\s+(\S+)\s+)(\d+)"
  9. #read generated file, load values from this with regular expression
  10. Get-Content ".\version.h" | Where-Object { $_ -match $versionSniffingRegex } | ForEach-Object {
  11. switch ($Matches[2])
  12. {
  13. "SRT_VERSION_MAJOR" { $majorVer = $Matches[3] }
  14. "SRT_VERSION_MINOR" { $minorVer = $Matches[3] }
  15. "SRT_VERSION_PATCH" { $patchVer = $Matches[3] }
  16. "SRT_VERSION_BUILD" { $buildNum = $Matches[3] }
  17. }
  18. }
  19. $FileDescriptionBranchCommitValue = "SRT Local Build"
  20. if($Env:APPVEYOR){
  21. #make AppVeyor update with this new version number
  22. Update-AppveyorBuild -Version "$majorVer.$minorVer.$patchVer.$buildNum"
  23. $FileDescriptionBranchCommitValue = "$Env:APPVEYOR_REPO_NAME - $($Env:APPVEYOR_REPO_BRANCH) ($($Env:APPVEYOR_REPO_COMMIT.substring(0,8)))"
  24. }
  25. if($Env:TEAMCITY_VERSION){
  26. #make TeamCity update with this new version number
  27. Write-Output "##teamcity[buildNumber '$majorVer.$minorVer.$patchVer.$buildNum']"
  28. Write-Output "##teamcity[setParameter name='MajorVersion' value='$majorVer']"
  29. Write-Output "##teamcity[setParameter name='MinorVersion' value='$minorVer']"
  30. Write-Output "##teamcity[setParameter name='PatchVersion' value='$patchVer']"
  31. Write-Output "##teamcity[setParameter name='BuildVersion' value='$buildNum']"
  32. $FileDescriptionBranchCommitValue = "$majorVer.$minorVer.$patchVer.$buildNum - ($($Env:BUILD_VCS_NUMBER.substring(0,8)))"
  33. }
  34. #find C++ resource files and update file description with branch / commit details
  35. $FileDescriptionStringRegex = '(\bVALUE\s+\"FileDescription\"\s*\,\s*\")([^\"]*\\\")*[^\"]*(\")'
  36. Get-ChildItem -Path "../srtcore/srt_shared.rc" | ForEach-Object {
  37. $fileName = $_
  38. Write-Output "Processing metadata changes for file: $fileName"
  39. $FileLines = Get-Content -path $fileName
  40. for($i=0;$i -lt $FileLines.Count;$i++)
  41. {
  42. $FileLines[$i] = $FileLines[$i] -Replace $FileDescriptionStringRegex, "`${1}$FileDescriptionBranchCommitValue`${3}"
  43. }
  44. [System.IO.File]::WriteAllLines($fileName.FullName, $FileLines)
  45. }