mirror of
https://github.com/game-ci/unity-builder.git
synced 2025-07-04 12:25:19 -04:00
Create VersionApplicator
This commit is contained in:
parent
03510d4a55
commit
5ee9c59113
@ -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>
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 30483367ddc84699a0da377ccb93769a
|
||||||
|
timeCreated: 1587504315
|
Loading…
Reference in New Issue
Block a user