Skip to content

Instantly share code, notes, and snippets.

@ykurniawan
Created October 2, 2018 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ykurniawan/d32a89fb1d38eb28c714aafe12b8612e to your computer and use it in GitHub Desktop.
Save ykurniawan/d32a89fb1d38eb28c714aafe12b8612e to your computer and use it in GitHub Desktop.
Powershell script to Update Build & Version numbers for iOS & Android (Info.plist and AndroidManifest.xml )
$majorMinorVersion = ""
$commitCount = & git rev-list --count HEAD
Write-Output "git rev-list --count HEAD = $commitCount"
$params = @{
FilePath = ""
OS = ""
ToolsDir = ""
SolutionFolder = ""
VersionSpecFilePath = ""
BuildCounter = $commitCount
SetBuildNumber = "%mr.Build.Version.SetTCBuildNumber%"
}
if(![System.IO.File]::Exists($params.FilePath)){
Write-Error "$params.FilePath does not exist"
exit
}
$version = Retrieve-Version-From-Spec-File
-Path $params.VersionSpecFilePath `
-BuildCount $params.BuildCounter `
Write-Host "##teamcity[buildNumber '$($version.PackageVersion)']"
$fileXml = [xml] (Get-Content $params.FilePath )
$versionNumber = $version.PackageVersion
$buildCounter = $params.BuildCounter
if($params.OS -eq "iOS"){
Write-Output "Writing to $filePath - setting CFBundleVersion to $versionNumber"
Select-Xml -xml $fileXml -XPath "//dict/key[. = 'CFBundleShortVersionString']/following-sibling::string[1]" |
%{
$_.Node.InnerXml = $versionNumber
}
Select-Xml -xml $fileXml -XPath "//dict/key[. = 'CFBundleVersion']/following-sibling::string[1]" |
%{
$_.Node.InnerXml = $buildCounter
}
}
elseif($params.OS -eq "Android"){
$xpath = "//manifest"
Write-Output "Writing to $filePath - setting manifest.android:versionCode to $versionNumber"
Select-Xml -xml $fileXml -XPath $xpath |
%{
$_.Node.SetAttribute("android:versionName", $versionNumber)
$_.Node.SetAttribute("android:versionCode", $buildCounter)
}
}
else{
Write-Error "Unrecognised OS argument: $params.OS"
exit
}
$fileXml.Save($params.FilePath)
Write-Output "Writing Version ($version.PackageVersion) to BuildVersion.txt"
$version.PackageVersion | Out-File BuildVersion.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment