Skip to content

Commit

Permalink
Merge #233
Browse files Browse the repository at this point in the history
233: Feature/Analytics r=brunoocasali a=brunoocasali

- Create the `Version` class
- Load the current version from the csproj data through the `GetType>Assembly>GetName>Version` (I don’t really know if this could have some potential of not working in some cases, let me know that).


> The Github Action for some reason stopped working, I fixed the version of the .net in order to fix the problem.

Related to meilisearch/integration-guides#150

Co-authored-by: Bruno Casali <brunoocasali@gmail.com>
  • Loading branch information
bors[bot] and brunoocasali authored Feb 8, 2022
2 parents 16b97de + c1bdea0 commit b06bf3d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.101
dotnet-version: "3.1.x"
- name: Meilisearch (latest version) setup with Docker
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --no-analytics=true --master-key=masterKey
- name: Install dependencies
Expand All @@ -38,6 +38,8 @@ jobs:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: "3.1.x"
- name: Install dotnet-format
run: dotnet tool install -g dotnet-format
- name: Check with dotnet-format
Expand Down
26 changes: 26 additions & 0 deletions src/Meilisearch/Version.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace Meilisearch
{
/// <summary>
/// Information regarding an API key for the Meilisearch server.
/// </summary>
public class Version
{
/// <summary>
/// Extracts version from Meilisearch.csproj.
/// </summary>
/// <returns>Returns a formatted version.</returns>
public string GetQualifiedVersion()
{
return $"Meilisearch .NET (v{this.GetVersion()})";
}

/// <summary>
/// Extracts the "major.minor.build" version from Meilisearch.csproj.
/// </summary>
/// <returns>Returns a version from the GetType as String.</returns>
public string GetVersion()
{
return this.GetType().Assembly.GetName().Version.ToString(3);
}
}
}
43 changes: 43 additions & 0 deletions tests/Meilisearch.Tests/VersionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace Meilisearch.Tests
{
using System.IO;
using System.Xml;
using Xunit;

public class VersionTests
{
private Version version;

public VersionTests()
{
this.version = new Version();
}

[Fact]
public void GetQualifiedVersion()
{
var qualifiedVersion = this.version.GetQualifiedVersion();
var version = this.version.GetVersion();

Assert.Equal(qualifiedVersion, $"Meilisearch .NET (v{version})");
}

[Fact]
public void GetSimpleVersionFromCsprojFile()
{
// get the current version defined in the csproj file
var xmldoc = new XmlDocument();
var currentDir = Directory.GetParent(Directory.GetCurrentDirectory()).FullName;
var path = Path.Combine(currentDir, @"../../../../src/Meilisearch/Meilisearch.csproj");
xmldoc.Load(path);
var mgr = new XmlNamespaceManager(xmldoc.NameTable);
mgr.AddNamespace("x", "http://schemas.microsoft.com/developer/msbuild/2003");
var versionFromCsproj = xmldoc.FirstChild.FirstChild.SelectSingleNode("Version").InnerText;

var value = this.version.GetVersion();

Assert.NotNull(value);
Assert.Equal(versionFromCsproj, value);
}
}
}

0 comments on commit b06bf3d

Please sign in to comment.