Create VersionApplicator

This commit is contained in:
Webber 2020-04-22 00:05:46 +02:00 committed by Webber Takken
parent 03510d4a55
commit 5ee9c59113
3 changed files with 83 additions and 0 deletions

View File

@ -30,6 +30,22 @@ namespace UnityBuilderAction.Versioning
return version; return version;
} }
/// <summary>
/// Get the version of the current tag.
///
/// Output Format:
/// #.* (where # is the major version and * can be any number of any type of character)
/// </summary>
/// <returns></returns>
public static string GenerateSemanticClassicVersion()
{
string version = Run(@"tag --points-at HEAD | grep v[0-9]*");
version = version.Substring(1);
return version;
}
/// <summary> /// <summary>
/// Get the total number of commits. /// Get the total number of commits.
/// </summary> /// </summary>

View File

@ -0,0 +1,64 @@
using System;
using JetBrains.Annotations;
using UnityEditor;
namespace UnityBuilderAction.Versioning
{
public class VersionApplicator
{
enum Strategy
{
None,
Custom,
SemanticCommit,
SemanticClassic,
}
public static void SetVersionForBuild(string strategy, [CanBeNull] string version)
{
if (!Enum.TryParse<Strategy>(strategy, out Strategy validatedStrategy)) {
throw new Exception($"Invalid versioning argument provided. {strategy} is not a valid strategy.");
}
switch (validatedStrategy) {
case Strategy.None:
return;
case Strategy.Custom:
ApplyCustomVersion(version);
return;
case Strategy.SemanticCommit:
ApplySemanticCommitVersion();
return;
case Strategy.SemanticClassic:
ApplySemanticClassicVersion();
return;
default:
throw new NotImplementedException("Version strategy has not been implemented.");
}
}
static void ApplyCustomVersion(string version)
{
Apply(version);
}
static void ApplySemanticCommitVersion()
{
string version = Git.GenerateSemanticCommitVersion();
Apply(version);
}
static void ApplySemanticClassicVersion()
{
string version = Git.GenerateSemanticClassicVersion();
Apply(version);
}
static void Apply(string version)
{
PlayerSettings.bundleVersion = version;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 30483367ddc84699a0da377ccb93769a
timeCreated: 1587504315