-
-
Save doggan/791119a38547b5977898 to your computer and use it in GitHub Desktop.
set iOS build version to CloudBuild version
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
CloudBuildManifest.cs and CloudBuildAPI.cs are upadated versions of the ones found here (namespace changed) | |
https://github.com/derkork/uTomate-UnityCloudBuildSample | |
Just put these files in an editor folder and you're good to go, your next cloudbuild iOS build will have an increased version number. | |
We're using Cloudbuild to generate builds which we can upload to testflight, and this makes that possible :) |
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
namespace UnityEngine.CloudBuild.API | |
{ | |
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
#if UNITY_CLOUD_BUILD | |
using UnityEditor; | |
using UnityEngine.CloudBuild; | |
using UnityEngine.CloudBuild.API; | |
#endif | |
public class CloudBuildAPI | |
{ | |
public static CloudBuildManifest GetBuildManifest() | |
{ | |
#if UNITY_CLOUD_BUILD | |
var manifest = (BuildManifestObject)AssetDatabase.LoadAssetAtPath("Assets/__UnityCloud__/Resources/UnityCloudBuildManifest.scriptable.asset", typeof(BuildManifestObject)); | |
return new CloudBuildManifest(manifest); | |
#else | |
var result = new CloudBuildManifest(); | |
// add a few dummy values | |
result.ProjectId = "com.yourproject.id[Local Dummy]"; | |
result.ScmBranch = "master[Local Dummy]"; | |
result.ScmCommitId = "da39a3ee5e6b4b0d3255bfef95601890afd80709[Local Dummy]"; | |
result.UnityVersion = Application.unityVersion; | |
result.XCodeVersion = "5.5 [Local Dummy]"; | |
result.BuildNumber = "182 [Local Dummy]"; | |
result.BuildStartTime = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds.ToString(); | |
result.BundleId = "com.yourbundle.id[Local Dummy]"; | |
return result; | |
#endif | |
} | |
} | |
} |
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
using UnityEngine; | |
using UnityEditor; | |
using UnityEditor.Callbacks; | |
using System.Collections; | |
using System.Collections.Generic; | |
using MiniJSON; | |
#if UNITY_IOS && UNITY_CLOUD_BUILD | |
using UnityEditor.iOS.Xcode; | |
using System.IO; | |
#endif | |
public class CloudBuildIncreaseVersionNum { | |
public class ChangeIOSBuildNumber { | |
#if UNITY_IOS && UNITY_CLOUD_BUILD | |
[PostProcessBuild] | |
public static void ChangeXcodePlist(BuildTarget buildTarget, string pathToBuiltProject) { | |
if (buildTarget == BuildTarget.iOS) { | |
// Get plist | |
string plistPath = pathToBuiltProject + "/Info.plist"; | |
PlistDocument plist = new PlistDocument(); | |
plist.ReadFromString(File.ReadAllText(plistPath)); | |
// Get root | |
PlistElementDict rootDict = plist.root; | |
// browse manifest | |
var cloudbuildVersionValue = UnityEngine.CloudBuild.API.CloudBuildAPI.GetBuildManifest().BuildNumber; | |
// Change value of CFBundleVersion in Xcode plist | |
var buildKey = "CFBundleVersion"; | |
rootDict.SetString(buildKey,cloudbuildVersionValue); | |
// Write to file | |
File.WriteAllText(plistPath, plist.WriteToString()); | |
} | |
} | |
#endif | |
} | |
} |
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
namespace UnityEngine.CloudBuild.API | |
{ | |
using System.Collections.Generic; | |
// usings go INSIDE the namespace so they don't conflict with the rest | |
using UnityEngine; | |
#if UNITY_CLOUD_BUILD | |
using UnityEngine.CloudBuild; | |
#endif | |
/// <summary> | |
/// API against Unity's build manifest object. Works locally (on a mock dictionary) and in the cloud. | |
/// </summary> | |
public class CloudBuildManifest | |
{ | |
#if UNITY_CLOUD_BUILD | |
private BuildManifestObject buildManifestObject; | |
#else | |
private Dictionary<string, string> contents; | |
#endif | |
#if UNITY_CLOUD_BUILD | |
internal CloudBuildManifest(BuildManifestObject buildManifestObject) | |
{ | |
this.buildManifestObject = buildManifestObject; | |
} | |
#else | |
internal CloudBuildManifest() | |
{ | |
this.contents = new Dictionary<string, string>(); | |
} | |
#endif | |
public string ScmCommitId | |
{ | |
get | |
{ | |
return Get("scmCommitId", null); | |
} | |
set | |
{ | |
Set("scmCommitId", value); | |
} | |
} | |
public string ScmBranch | |
{ | |
get | |
{ | |
return Get("scmBranch", null); | |
} | |
set | |
{ | |
Set("scmBranch", value); | |
} | |
} | |
public string BuildNumber | |
{ | |
get | |
{ | |
return Get("buildNumber", null); | |
} | |
set | |
{ | |
Set("buildNumber", value); | |
} | |
} | |
public string BuildStartTime | |
{ | |
get | |
{ | |
return Get("buildStartTime", null); | |
} | |
set | |
{ | |
Set("buildStartTime", value); | |
} | |
} | |
public string ProjectId | |
{ | |
get | |
{ | |
return Get("projectId", null); | |
} | |
set | |
{ | |
Set("projectId", value); | |
} | |
} | |
public string BundleId | |
{ | |
get | |
{ | |
return Get("bundleId", null); | |
} | |
set | |
{ | |
Set("bundleId", value); | |
} | |
} | |
public string UnityVersion | |
{ | |
get | |
{ | |
return Get("unityVersion", null); | |
} | |
set | |
{ | |
Set("unityVersion", value); | |
} | |
} | |
public string XCodeVersion | |
{ | |
get | |
{ | |
return Get("xCodeVersion", null); | |
} | |
set | |
{ | |
Set("xCodeVersion", value); | |
} | |
} | |
public string CloudBuildTargetName | |
{ | |
get | |
{ | |
return Get("cloudBuildTargetName", null); | |
} | |
set | |
{ | |
Set("cloudBuildTargetName", value); | |
} | |
} | |
public string Get(string key, string defaultValue) | |
{ | |
#if UNITY_CLOUD_BUILD | |
return buildManifestObject.GetValue(key, defaultValue); | |
#else | |
string result; | |
if (!contents.TryGetValue(key, out result)) | |
{ | |
return defaultValue; | |
} | |
return result; | |
#endif | |
} | |
public void Set(string key, string value) | |
{ | |
#if UNITY_CLOUD_BUILD | |
buildManifestObject.SetValue(key, value); | |
#else | |
contents[key] = value; | |
#endif | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment