Skip to content

Commit

Permalink
[google][firebase] Moved logic to methods in update.cake
Browse files Browse the repository at this point in the history
- Added logic to update XBD version in packages.config files
- Added Bumped property to know when the files have been touched
  • Loading branch information
SotoiGhost committed Jun 12, 2017
1 parent c73afc3 commit 45e3cb9
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 65 deletions.
39 changes: 23 additions & 16 deletions poco.cake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public abstract class GoogleBase
public virtual string NuGetId { get; }
public string CurrentVersion { get; set; }
public string NewVersion { get; set; }
public bool Bumped { get; set; }
public virtual string [] BaseOf {
get { return new string[] { }; }
}
Expand Down Expand Up @@ -278,23 +279,29 @@ public abstract class Google
}
}

public class XamarinBuildDownload : GoogleBase
public abstract class Xamarin
{
public override string Name {
get { return "Xamarin.Build.Download"; }
}
public override string NuGetId {
get { return "Xamarin.Build.Download"; }
}
public override string [] BaseOf {
get { return new [] { new Firebase.AdMob ().Name, new Firebase.Analytics ().Name, new Firebase.Auth ().Name,
new Firebase.CloudMessaging ().Name, new Firebase.Core ().Name, new Firebase.CrashReporting ().Name,
new Firebase.Database ().Name, new Firebase.DynamicLinks ().Name, new Firebase.InstanceID ().Name,
new Firebase.Invites ().Name, new Firebase.RemoteConfig ().Name, new Firebase.Storage ().Name,
new Google.Analytics ().Name, new Google.AppIndexing ().Name, new Google.Cast ().Name,
new Google.Core ().Name, new Google.InstanceID ().Name, new Google.Maps ().Name,
new Google.MobileAds ().Name, new Google.PlayGames ().Name, new Google.SignIn ().Name,
new Google.TagManager ().Name };
public abstract class Build
{
public class Download : GoogleBase
{
public override string Name {
get { return "Xamarin.Build.Download"; }
}
public override string NuGetId {
get { return "Xamarin.Build.Download"; }
}
public override string [] BaseOf {
get { return new [] { new Firebase.AdMob ().Name, new Firebase.Analytics ().Name, new Firebase.Auth ().Name,
new Firebase.CloudMessaging ().Name, new Firebase.Core ().Name, new Firebase.CrashReporting ().Name,
new Firebase.Database ().Name, new Firebase.DynamicLinks ().Name, new Firebase.InstanceID ().Name,
new Firebase.Invites ().Name, new Firebase.RemoteConfig ().Name, new Firebase.Storage ().Name,
new Google.Analytics ().Name, new Google.AppIndexing ().Name, new Google.Cast ().Name,
new Google.Core ().Name, new Google.InstanceID ().Name, new Google.Maps ().Name,
new Google.MobileAds ().Name, new Google.PlayGames ().Name, new Google.SignIn ().Name,
new Google.TagManager ().Name };
}
}
}
}
}
127 changes: 78 additions & 49 deletions update.cake
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using Newtonsoft.Json;
var TARGET = Argument ("target", Argument ("t", Argument ("Target", "build")));
var COMPONENT_NAME = Argument ("component-name", Argument ("cn", Argument ("Component-name", "")));
var COMPONENT_VERSION = Argument ("component-version", Argument ("cv", Argument ("Component-version", "")));
var BUMP_DEPENDENCIES = Argument ("bump-dependencies", Argument ("bd", true));
var BUMP_DEPENDENTS = Argument ("bump-dependents", Argument ("bd", true));

public Dictionary<string, GoogleBase> CreateComponents ()
{
Expand Down Expand Up @@ -45,7 +45,7 @@ public Dictionary<string, GoogleBase> CreateComponents ()
googleComponents ["Google.SignIn"] = GetComponent<Google.SignIn> ();
googleComponents ["Google.TagManager"] = GetComponent<Google.TagManager> ();

googleComponents ["Xamarin.Build.Download"] = GetComponent<XamarinBuildDownload> ();
googleComponents ["Xamarin.Build.Download"] = GetComponent<Xamarin.Build.Download> ();

return googleComponents;
}
Expand All @@ -56,86 +56,113 @@ public T GetComponent<T> () where T : GoogleBase, new ()

FilePath nuspecPath = null;

if (component is XamarinBuildDownload) {
if (component is Xamarin.Build.Download) {
nuspecPath = GetFiles ($"./Firebase.Core/nuget/*.nuspec").ToList () [0];
component.CurrentVersion = XmlPeek (nuspecPath, "/package/metadata/dependencies/group[@targetFramework='Xamarin.iOS10']/dependency[@id='Xamarin.Build.Download']/@version");
} else {
nuspecPath = GetFiles ($"./{component.Name}/nuget/*.nuspec").ToList () [0];
component.CurrentVersion = XmlPeek (nuspecPath, "/package/metadata/version/text()");
}

component.NewVersion = component.CurrentVersion;

var versionParts = component.CurrentVersion.Split ('.');
var lastIndex = versionParts.Length - 1;
versionParts [lastIndex] = (int.Parse (versionParts [lastIndex]) + 1).ToString ();
component.NewVersion = string.Join (".", versionParts);

return component;
}

public void UpdateComponentVersion (Dictionary<string, GoogleBase> components, string componentName, bool bumpDependencies)
public void UpdateYamlVersion (GoogleBase component)
{
var message = $"Working on {componentName} component";
Information ($"{new string ('/', message.Length + 6)}");
Information ($"// {message} //");
Information ($"{new string ('/', message.Length + 6)}\n");

var component = components [componentName];

var yamlPath = new FilePath ($"./{component.Name}/component/component.yaml");
var nuspecPaths = GetFiles ($"./{component.Name}/nuget/*.nuspec");
FilePath nuspecPath = new FilePath ($"./{component.Name}/nuget/NotFound.nuspec");;

foreach (var path in nuspecPaths)
nuspecPath = path;
if (!FileExists (yamlPath))
return;

Information ($"Updating version in component.yaml file of {component.Name} component.");

if (FileExists (yamlPath)) {
Information ($"Updating version in component.yaml file of {component.Name} component");
// var componentData = DeserializeYamlFromFile<Component> (yamlPath);

// var componentData = DeserializeYamlFromFile<Component> (yamlPath);
// Temporary Workaround. Seems that YamlDotNet cannot deserialize an object within an object in version 3.8.0
// This doesn't happen in version 4.x
var jsonString = ConvertYamlToJsonFromFile (yamlPath);
var componentData = DeserializeJson<Component> (jsonString);

// Temporary Workaround. Seems that YamlDotNet cannot deserialize an object within an object in version 3.8.0
// This doesn't happen in version 4.x
var jsonString = ConvertYamlToJsonFromFile (yamlPath);
var componentData = DeserializeJson<Component> (jsonString);
componentData.Version = component.NewVersion;

var parts = componentData.Packages.iOSUnifiedPaths [0].Split ('=');
parts [1] = component.NewVersion;
componentData.Packages.iOSUnifiedPaths [0] = string.Join ("=", parts);

componentData.Version = component.NewVersion;

var parts = componentData.Packages.iOSUnifiedPaths [0].Split ('=');
parts [1] = component.NewVersion;
componentData.Packages.iOSUnifiedPaths [0] = string.Join ("=", parts);
SerializeYamlToFile (yamlPath, componentData);
}

SerializeYamlToFile (yamlPath, componentData);
}
public void UpdateNuspecMainVersion (GoogleBase component)
{
var nuspecPaths = GetFiles ($"./{component.Name}/nuget/*.nuspec");
var nuspecPath = new FilePath ($"./{component.Name}/nuget/NotFound.nuspec");

if (FileExists (nuspecPath)) {
Information ($"Updating version in .nuspec file of {component.Name} component\n");
XmlPoke (nuspecPath, "/package/metadata/version", component.NewVersion);
}
foreach (var path in nuspecPaths)
nuspecPath = path;

if (!FileExists (nuspecPath))
return;

Information ($"Updating version in .nuspec file of {component.Name} component.\n");
XmlPoke (nuspecPath, "/package/metadata/version", component.NewVersion);
}

public void UpdateNuspecDependencyVersion (GoogleBase component)
{
foreach (var name in component.BaseOf) {
nuspecPath = GetFiles ($"./{name}/nuget/*.nuspec").ToList () [0];
var nuspecPath = GetFiles ($"./{name}/nuget/*.nuspec").ToList () [0];

Information ($"Updating {component.Name} dependency version in .nuspec file of {name} component");
Information ($"Updating {component.Name} dependency version in .nuspec file of {name} component.");

if (FileExists (nuspecPath)) {
var result = XmlPeek (nuspecPath, $"/package/metadata/dependencies/group[@targetFramework='Xamarin.iOS10']/dependency[@id='{component.NuGetId}']/@version");
if (!string.IsNullOrWhiteSpace (result))
XmlPoke (nuspecPath, $"/package/metadata/dependencies/group[@targetFramework='Xamarin.iOS10']/dependency[@id='{component.NuGetId}']/@version", component.NewVersion);
}
}
}

public void UpdateSamplesPackagesConfigVersion (GoogleBase component)
{
foreach (var name in component.BaseOf) {
var packagesPaths = GetFiles ($"./{name}/samples/**/packages.config");

if (!bumpDependencies)
foreach (var packagePath in packagesPaths) {
Information ($"Updating {component.Name} version in packages.config file of {name} sample component.");
XmlPoke (packagePath, $"/packages/package[@id='{component.Name}']/@version", component.NewVersion);
}
}
}

public void UpdateComponentVersion (Dictionary<string, GoogleBase> components, string componentName, bool bumpDependents)
{
var message = $"Working on {componentName} component";
Information ($"{new string ('/', message.Length + 6)}");
Information ($"// {message} //");
Information ($"{new string ('/', message.Length + 6)}\n");

var component = components [componentName];

UpdateYamlVersion (component);
UpdateNuspecMainVersion (component);
UpdateNuspecDependencyVersion (component);

if (component is Xamarin.Build.Download)
UpdateSamplesPackagesConfigVersion (component);

if (!bumpDependents)
return;

Information ($"\nBUMP_DEPENDENCIES was set to true! Starting bumping {component.Name} dependent components due {component.Name} version update...");
Information ($"\nBUMP_DEPENDENTS was set to true! Starting bumping {component.Name} dependent components due {component.Name} version update...");

foreach (var name in component.BaseOf) {
var dependentComponent = components [name];

var versionParts = dependentComponent.CurrentVersion.Split ('.');
var lastIndex = versionParts.Length - 1;
versionParts [lastIndex] = (int.Parse (versionParts [lastIndex]) + 1).ToString ();

dependentComponent.NewVersion = string.Join (".", versionParts);
components [name] = dependentComponent;

dependentComponent.Bumped = true;
Information ($"\nBumping {dependentComponent.Name} component from version {dependentComponent.CurrentVersion} to {dependentComponent.NewVersion}...\n");
UpdateComponentVersion (components, name, false);
}
Expand Down Expand Up @@ -217,16 +244,18 @@ Task ("build").Does (() =>

Information ($"Component to updated: {updatedComponent.Name} {updatedComponent.CurrentVersion} => {updatedComponent.NewVersion}\n");

UpdateComponentVersion (components, COMPONENT_NAME, BUMP_DEPENDENCIES);
UpdateComponentVersion (components, COMPONENT_NAME, BUMP_DEPENDENTS);

components.Remove (updatedComponent.Name);

Information ($"Component updated: {updatedComponent.Name} {updatedComponent.CurrentVersion} => {updatedComponent.NewVersion}\n");

Information ("List of bumped components due update:");
foreach (var pair in components)
if (pair.Value.CurrentVersion != pair.Value.NewVersion)
if (pair.Value.Bumped)
Information ($"{pair.Key,-26}{pair.Value.CurrentVersion,-11}=>{"",-3}{pair.Value.NewVersion}");
});

Task ("Default").IsDependentOn ("build");

RunTarget (TARGET);

0 comments on commit 45e3cb9

Please sign in to comment.