-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add version utils to get the version text or anything related to vers…
…ion.
- Loading branch information
1 parent
323183f
commit d6f006f
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using NUnit.Framework; | ||
using osu.Game.Rulesets.Karaoke.Utils; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Tests.Utils | ||
{ | ||
public class VersionUtilsTest | ||
{ | ||
[Test] | ||
public void TestGetVersion() | ||
{ | ||
var expected = new Version(1, 0, 0, 0); | ||
var actual = VersionUtils.GetVersion(); | ||
Assert.NotNull(actual); | ||
Assert.AreEqual(expected.Major, actual.Major); | ||
Assert.AreEqual(expected.Minor, actual.Minor); | ||
Assert.AreEqual(expected.Build, actual.Build); | ||
Assert.AreEqual(expected.Revision, actual.Revision); | ||
} | ||
|
||
[Test] | ||
public void TestMajorVersionName() | ||
{ | ||
const string expected = "UwU"; | ||
string actual = VersionUtils.MajorVersionName; | ||
Assert.AreEqual(expected, actual); | ||
} | ||
|
||
[Test] | ||
public void IsDeployedBuild() | ||
{ | ||
// should not be deploy build if not build by github action. | ||
const bool expected = false; | ||
bool actual = VersionUtils.IsDeployedBuild; | ||
Assert.AreEqual(expected, actual); | ||
} | ||
|
||
[Test] | ||
public void TestGetDisplayVersion() | ||
{ | ||
const string expected = "1.0.0-UwU"; | ||
string actual = VersionUtils.DisplayVersion; | ||
Assert.AreEqual(expected, actual); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using osu.Framework.Development; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Utils | ||
{ | ||
public static class VersionUtils | ||
{ | ||
public static Version GetVersion() | ||
=> AssemblyUtils.GetAssemblyByName("osu.Game.Rulesets.Karaoke")?.GetName().Version ?? new Version(); | ||
|
||
/// <summary> | ||
/// Get the major version of this ruleset. | ||
/// Will be a noun or word. | ||
/// </summary> | ||
/// <returns>Major version name</returns> | ||
public static string MajorVersionName => "UwU"; | ||
|
||
public static bool IsDeployedBuild => GetVersion().Major > 1; | ||
|
||
public static string DisplayVersion | ||
{ | ||
get | ||
{ | ||
var assemblyVersion = GetVersion(); | ||
bool isDeployedBuild = assemblyVersion.Major > 0; | ||
if (!isDeployedBuild) | ||
return @"local " + (DebugUtils.IsDebugBuild ? @"debug" : @"release"); | ||
|
||
return $@"{assemblyVersion.Major}.{assemblyVersion.Minor}.{assemblyVersion.Build}-{MajorVersionName}"; | ||
} | ||
} | ||
} | ||
} |