Skip to content

Commit

Permalink
add version utils to get the version text or anything related to vers…
Browse files Browse the repository at this point in the history
…ion.
  • Loading branch information
andy840119 committed Feb 10, 2022
1 parent 323183f commit d6f006f
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
49 changes: 49 additions & 0 deletions osu.Game.Rulesets.Karaoke.Tests/Utils/VersionUtilsTest.cs
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);
}
}
}
36 changes: 36 additions & 0 deletions osu.Game.Rulesets.Karaoke/Utils/VersionUtils.cs
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}";
}
}
}
}

0 comments on commit d6f006f

Please sign in to comment.