Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feat/1246-allow-re…
Browse files Browse the repository at this point in the history
…ordering-senses-example-sentences-complex-forms-and-components
  • Loading branch information
myieye committed Dec 13, 2024
2 parents ea86354 + f2101d5 commit 72d170a
Show file tree
Hide file tree
Showing 18 changed files with 138 additions and 31 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/fw-lite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,14 @@ jobs:
- name: Publish Windows MAUI portable app
working-directory: backend/FwLite/FwLiteDesktop
run: |
dotnet publish -r win-x64 --artifacts-path ../artifacts -p:WindowsPackageType=None -p:ApplicationDisplayVersion=${{ needs.build-and-test.outputs.semver-version }}
dotnet publish -r win-arm64 --artifacts-path ../artifacts -p:WindowsPackageType=None -p:ApplicationDisplayVersion=${{ needs.build-and-test.outputs.semver-version }}
dotnet publish -r win-x64 --artifacts-path ../artifacts -p:WindowsPackageType=None -p:ApplicationDisplayVersion=${{ needs.build-and-test.outputs.semver-version }} -p:InformationalVersion=${{ needs.build-and-test.outputs.version }}
mkdir -p ../artifacts/sign/portable
cp -r ../artifacts/publish/FwLiteDesktop/* ../artifacts/sign/portable/
- name: Publish Windows MAUI msix app
working-directory: backend/FwLite/FwLiteDesktop
run: |
dotnet publish -r win-x64 --artifacts-path ../artifacts -p:ApplicationDisplayVersion=${{ needs.build-and-test.outputs.semver-version }}
dotnet publish -r win-arm64 --artifacts-path ../artifacts -p:ApplicationDisplayVersion=${{ needs.build-and-test.outputs.semver-version }}
dotnet publish -r win-x64 --artifacts-path ../artifacts -p:ApplicationDisplayVersion=${{ needs.build-and-test.outputs.semver-version }} -p:InformationalVersion=${{ needs.build-and-test.outputs.version }}
mkdir -p ../artifacts/msix
cp ../artifacts/bin/FwLiteDesktop/*/AppPackages/*/*.msix ../artifacts/msix/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<InformationalVersion>$(ApplicationDisplayVersion)</InformationalVersion>
<FileVersion>$(ApplicationDisplayVersion)</FileVersion>
<FileVersion>$(ApplicationDisplayVersion)</FileVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.0" />
Expand Down
15 changes: 13 additions & 2 deletions backend/FwLite/FwLiteDesktop/AppVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ namespace FwLiteDesktop;

public class AppVersion
{
public static readonly string Version = typeof(AppVersion).Assembly
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? "dev";
static AppVersion()
{
var infoVersion = typeof(AppVersion).Assembly
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
//info version may look like v2024-12-12-3073dd1c+3073dd1ce2ff5510f54a9411366f55c958b9ea45. We want to strip off everything after the +, so we can compare versions
if (infoVersion is not null && infoVersion.Contains('+'))
{
infoVersion = infoVersion[..infoVersion.IndexOf('+')];
}
Version = infoVersion ?? "dev";
}

public static readonly string Version;
}
6 changes: 2 additions & 4 deletions backend/FwLite/FwLiteDesktop/FwLiteDesktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@
<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>
<!-- version used in AppVersion.cs-->
<InformationalVersion>$(ApplicationDisplayVersion)</InformationalVersion>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.19041.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.19041.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug' ">
Expand Down
16 changes: 13 additions & 3 deletions backend/FwLite/FwLiteDesktop/Platforms/Windows/AppUpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,24 @@ private async Task TryUpdate()

private async Task ApplyUpdate(FwLiteRelease latestRelease)
{
logger.LogInformation("New version available: {Version}", latestRelease.Version);
logger.LogInformation("New version available: {Version}, Current version: {CurrentVersion}", latestRelease.Version, AppVersion.Version);
var packageManager = new PackageManager();
var asyncOperation = packageManager.AddPackageAsync(new Uri(latestRelease.Url), [], DeploymentOptions.None);
var asyncOperation = packageManager.AddPackageByUriAsync(new Uri(latestRelease.Url),
new AddPackageOptions()
{
DeferRegistrationWhenPackagesAreInUse = true,
ForceUpdateFromAnyVersion = true
});
asyncOperation.Progress = (info, progressInfo) =>
{
if (progressInfo.state == DeploymentProgressState.Queued)
{
logger.LogInformation("Queued update");
return;
}
logger.LogInformation("Downloading update: {ProgressPercentage}%", progressInfo.percentage);
};
var result = await asyncOperation.AsTask();
var result = await asyncOperation;
if (!string.IsNullOrEmpty(result.ErrorText))
{
logger.LogError(result.ExtendedErrorCode, "Failed to download update: {ErrorText}", result.ErrorText);
Expand Down
1 change: 0 additions & 1 deletion backend/FwLite/FwLiteProjectSync/FwLiteProjectSync.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<InformationalVersion>$(ApplicationDisplayVersion)</InformationalVersion>
<FileVersion>$(ApplicationDisplayVersion)</FileVersion>
</PropertyGroup>

Expand Down
82 changes: 82 additions & 0 deletions backend/FwLite/LcmCrdt.Tests/Changes/ChangeSerializationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System.Reflection;
using System.Text.Json;
using FluentAssertions.Execution;
using LcmCrdt.Changes;
using LcmCrdt.Changes.Entries;
using MiniLcm.Tests.AutoFakerHelpers;
using SIL.Harmony.Changes;
using Soenneker.Utils.AutoBogus;
using SystemTextJsonPatch;

namespace LcmCrdt.Tests.Changes;

public class ChangeSerializationTests
{
private static readonly AutoFaker Faker = new()
{
Config =
{
Overrides = [new WritingSystemIdOverride()]
}
};

public static IEnumerable<object[]> Changes()
{
foreach (var type in LcmCrdtKernel.AllChangeTypes())
{
//can't generate this type because there's no public constructor, so its specified below
if (type == typeof(SetComplexFormComponentChange)) continue;

object change;
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(JsonPatchChange<>))
{
change = PatchMethod.MakeGenericMethod(type.GenericTypeArguments[0]).Invoke(null, null)!;
}
else
{
change = Faker.Generate(type);
}
change.Should().NotBeNull($"change type {type.Name} should have been generated");
yield return [change];
}
yield return [SetComplexFormComponentChange.NewComplexForm(Guid.NewGuid(), Guid.NewGuid())];
yield return [SetComplexFormComponentChange.NewComponent(Guid.NewGuid(), Guid.NewGuid())];
yield return [SetComplexFormComponentChange.NewComponentSense(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid())];
}

private static readonly MethodInfo PatchMethod = new Func<IChange>(Patch<Entry>).Method.GetGenericMethodDefinition();

private static IChange Patch<T>() where T : class
{
return new JsonPatchChange<T>(Guid.NewGuid(), new JsonPatchDocument<T>());
}

[Theory]
[MemberData(nameof(Changes))]
public void CanRoundTripChanges(IChange change)
{
var config = new CrdtConfig();
LcmCrdtKernel.ConfigureCrdt(config);
//commit id is not serialized
change.CommitId = Guid.Empty;
var type = change.GetType();
var json = JsonSerializer.Serialize(change, config.JsonSerializerOptions);
var newChange = JsonSerializer.Deserialize(json, type, config.JsonSerializerOptions);
newChange.Should().BeEquivalentTo(change);
}

[Fact]
public void ChangesIncludesAllValidChangeTypes()
{
var allChangeTypes = LcmCrdtKernel.AllChangeTypes();
allChangeTypes.Should().NotBeEmpty();
var testedTypes = Changes().Select(c => c[0].GetType()).ToArray();
using (new AssertionScope())
{
foreach (var allChangeType in allChangeTypes)
{
testedTypes.Should().Contain(allChangeType);
}
}
}
}
2 changes: 2 additions & 0 deletions backend/FwLite/LcmCrdt.Tests/MiniLcmApiFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using MiniLcm;
using MiniLcm.Models;
using Xunit.Abstractions;
Expand All @@ -17,6 +18,7 @@ public class MiniLcmApiFixture : IAsyncLifetime
private LcmCrdtDbContext? _crdtDbContext;
public CrdtMiniLcmApi Api => (CrdtMiniLcmApi)_services.ServiceProvider.GetRequiredService<IMiniLcmApi>();
public DataModel DataModel => _services.ServiceProvider.GetRequiredService<DataModel>();
public CrdtConfig CrdtConfig => _services.ServiceProvider.GetRequiredService<IOptions<CrdtConfig>>().Value;

public MiniLcmApiFixture()
{
Expand Down
4 changes: 2 additions & 2 deletions backend/FwLite/LcmCrdt/Changes/AddSemanticDomainChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

namespace LcmCrdt.Changes;

public class AddSemanticDomainChange(SemanticDomain semanticDomain, Guid senseId)
: EditChange<Sense>(senseId), ISelfNamedType<AddSemanticDomainChange>
public class AddSemanticDomainChange(SemanticDomain semanticDomain, Guid entityId)
: EditChange<Sense>(entityId), ISelfNamedType<AddSemanticDomainChange>
{
public SemanticDomain SemanticDomain { get; } = semanticDomain;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ public class AddEntryComponentChange : CreateChange<ComplexFormComponent>, ISelf
[JsonConstructor]
public AddEntryComponentChange(Guid entityId,
Guid complexFormEntryId,
string? complexFormHeadword,
Guid componentEntryId,
string? componentHeadword,
Guid? componentSenseId = null) : base(entityId)
{
ComplexFormEntryId = complexFormEntryId;
Expand All @@ -28,9 +26,7 @@ public AddEntryComponentChange(Guid entityId,

public AddEntryComponentChange(ComplexFormComponent component) : this(component.Id == default ? Guid.NewGuid() : component.Id,
component.ComplexFormEntryId,
component.ComplexFormHeadword,
component.ComponentEntryId,
component.ComponentHeadword,
component.ComponentSenseId)
{
}
Expand Down
4 changes: 2 additions & 2 deletions backend/FwLite/LcmCrdt/Changes/RemoveSemanticDomainChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

namespace LcmCrdt.Changes;

public class RemoveSemanticDomainChange(Guid semanticDomainId, Guid senseId)
: EditChange<Sense>(senseId), ISelfNamedType<RemoveSemanticDomainChange>
public class RemoveSemanticDomainChange(Guid semanticDomainId, Guid entityId)
: EditChange<Sense>(entityId), ISelfNamedType<RemoveSemanticDomainChange>
{
public Guid SemanticDomainId { get; } = semanticDomainId;

Expand Down
4 changes: 2 additions & 2 deletions backend/FwLite/LcmCrdt/Changes/ReplaceSemanticDomainChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

namespace LcmCrdt.Changes;

public class ReplaceSemanticDomainChange(Guid oldSemanticDomainId, SemanticDomain semanticDomain, Guid senseId)
: EditChange<Sense>(senseId), ISelfNamedType<ReplaceSemanticDomainChange>
public class ReplaceSemanticDomainChange(Guid oldSemanticDomainId, SemanticDomain semanticDomain, Guid entityId)
: EditChange<Sense>(entityId), ISelfNamedType<ReplaceSemanticDomainChange>
{
public Guid OldSemanticDomainId { get; } = oldSemanticDomainId;
public SemanticDomain SemanticDomain { get; } = semanticDomain;
Expand Down
1 change: 0 additions & 1 deletion backend/FwLite/LcmCrdt/LcmCrdt.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<InformationalVersion>$(ApplicationDisplayVersion)</InformationalVersion>
<FileVersion>$(ApplicationDisplayVersion)</FileVersion>
</PropertyGroup>

Expand Down
16 changes: 15 additions & 1 deletion backend/FwLite/LcmCrdt/LcmCrdtKernel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Text.Json;
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization.Metadata;
using SIL.Harmony;
using SIL.Harmony.Core;
using SIL.Harmony.Changes;
Expand Down Expand Up @@ -190,6 +192,18 @@ public static void ConfigureCrdt(CrdtConfig config)
.Add<Changes.SetOrderChange<Sense>>();
}

public static Type[] AllChangeTypes()
{
var crdtConfig = new CrdtConfig();
ConfigureCrdt(crdtConfig);


var list = typeof(ChangeTypeListBuilder).GetProperty("Types", BindingFlags.Instance | BindingFlags.NonPublic)
?.GetValue(crdtConfig.ChangeTypeListBuilder) as List<JsonDerivedType>;
return list?.Select(t => t.DerivedType).ToArray() ?? [];
}


public static Task<IMiniLcmApi> OpenCrdtProject(this IServiceProvider services, CrdtProject project)
{
//this method must not be async, otherwise Setting the project scope will not work as expected.
Expand Down
1 change: 0 additions & 1 deletion backend/FwLite/LocalWebApp/LocalWebApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
<ServerGarbageCollection>false</ServerGarbageCollection>
<SelfContained>true</SelfContained>
<InformationalVersion>$(ApplicationDisplayVersion)</InformationalVersion>
<FileVersion>$(ApplicationDisplayVersion)</FileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release' ">
Expand Down
1 change: 0 additions & 1 deletion backend/FwLite/MiniLcm/MiniLcm.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<InformationalVersion>$(ApplicationDisplayVersion)</InformationalVersion>
<FileVersion>$(ApplicationDisplayVersion)</FileVersion>
</PropertyGroup>

Expand Down
1 change: 1 addition & 0 deletions backend/LexBoxApi/Controllers/FwLiteReleaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public async ValueTask<ActionResult<FwLiteRelease>> LatestRelease(string? appVer
}

[HttpGet("should-update")]
[AllowAnonymous]
public async Task<ActionResult<ShouldUpdateResponse>> ShouldUpdate([FromQuery] string appVersion)
{
using var activity = LexBoxActivitySource.Get().StartActivity();
Expand Down

0 comments on commit 72d170a

Please sign in to comment.