Created
June 24, 2020 09:54
-
-
Save BurgerZ/05a1d648aa7851aeb72646fe4d145e31 to your computer and use it in GitHub Desktop.
Powershell script to Update Build & Version numbers for iOS & Android (Info.plist and AndroidManifest.xml )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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