From 01a087b81c05087243188ea04415ca4c943cc429 Mon Sep 17 00:00:00 2001 From: Seamas McGettrick Date: Fri, 15 Sep 2023 00:51:34 -0500 Subject: [PATCH 1/2] SL-6372 Update for NET6/NET7 Maui support --- .github/workflows/deploy.yml | 26 ++++++++-- .github/workflows/test.yml | 34 ++++++++----- .../Float.TinCan.ActivityLibrary.Tests.csproj | 14 ++--- .../ActivityDownloader.cs | 17 +++++-- .../ActivityLaunchCoordinator.cs | 51 +++++++++++++++---- .../Definition/IActivityViewer.cs | 7 ++- .../Float.TinCan.ActivityLibrary.csproj | 19 ++++--- 7 files changed, 124 insertions(+), 44 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7542347..ecc691b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,22 +1,38 @@ name: Deploy on: - workflow_dispatch: + release: + types: [published] jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 - name: Setup .NET - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v3 with: - dotnet-version: 6.0.x + dotnet-version: | + 3.1.x + 6.0.x + 7.0.x + - name: Retore Workload + run: dotnet workload restore + - name: Restore dependencies + run: dotnet restore + - name: Set Assembly Version + run: ./build.sh --task=GitVersion --configuration=Release + - name: Build Library + run: dotnet build ./Float.TinCan.ActivityLibrary/Float.TinCan.ActivityLibrary.csproj --configuration Release --no-restore + - name: Update Version + run: sed -i "s/<\/Version>/${{ github.event.release.name }}<\/Version>/" ./Float.TinCan.ActivityLibrary/Float.TinCan.ActivityLibrary.csproj + - name: Pack and Upload + run: dotnet pack --configuration Release --no-restore - name: Deploy to NuGet env: FLOAT_NUGET_TOKEN: ${{ secrets.FLOAT_NUGET_TOKEN }} - run: ./build.sh --task=Deploy --configuration=Release --nugetUrl="https://api.nuget.org/v3/index.json" --nugetToken="${FLOAT_NUGET_TOKEN}" + run: dotnet nuget push ./Float.TinCan.ActivityLibrary/bin/Release/Float.TinCan.ActivityLibrary.${{ github.event.release.name }}.nupkg --api-key "${FLOAT_NUGET_TOKEN}" --source https://api.nuget.org/v3/index.json diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 77b732e..c04327d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,18 +6,28 @@ on: jobs: build: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Setup .NET - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 6.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --no-restore - - name: Test - run: dotnet test --no-build --verbosity normal + - uses: actions/checkout@v3 + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: | + 3.1.x + 6.0.x + 7.0.x + - name: Retore Workload + run: dotnet workload restore + - name: Restore dependencies + run: dotnet restore + - name: Build + run: dotnet build --configuration Release --no-restore + - name: Test + run: dotnet test --configuration Release --no-build --verbosity normal --logger:"trx;" + - name: Publish Test Results + uses: EnricoMi/publish-unit-test-result-action@v2 + if: always() + with: + files: | + **/TestResults/*.trx diff --git a/Float.TinCan.ActivityLibrary.Tests/Float.TinCan.ActivityLibrary.Tests.csproj b/Float.TinCan.ActivityLibrary.Tests/Float.TinCan.ActivityLibrary.Tests.csproj index 89be904..2d2fc7e 100644 --- a/Float.TinCan.ActivityLibrary.Tests/Float.TinCan.ActivityLibrary.Tests.csproj +++ b/Float.TinCan.ActivityLibrary.Tests/Float.TinCan.ActivityLibrary.Tests.csproj @@ -1,18 +1,20 @@ - net6.0 + netcoreapp3.1;net6.0;net7.0 false + 9.0 + true - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/Float.TinCan.ActivityLibrary/ActivityDownloader.cs b/Float.TinCan.ActivityLibrary/ActivityDownloader.cs index 773f5c2..6ae3a02 100644 --- a/Float.TinCan.ActivityLibrary/ActivityDownloader.cs +++ b/Float.TinCan.ActivityLibrary/ActivityDownloader.cs @@ -1,10 +1,16 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Linq; using System.Threading.Tasks; using Float.FileDownloader; using Float.TinCan.ActivityLibrary.Definition; +#if NETSTANDARD using Xamarin.Forms; +#else +using Microsoft.Maui; +using Microsoft.Maui.ApplicationModel; +#endif namespace Float.TinCan.ActivityLibrary { @@ -60,11 +66,16 @@ public static DownloadStatus Download(IActivity activity, IRemoteFileProvider fi { tasks?.Exception?.Handle(exc => { - Device.BeginInvokeOnMainThread(() => + Action mainThreadCode = () => { DeleteDownloadsForActivity(activity, metaDataProvider); ActiveDownloads.Remove(activity); - }); + }; +#if NETSTANDARD + Device.BeginInvokeOnMainThread(mainThreadCode); +#else + MainThread.BeginInvokeOnMainThread(mainThreadCode); +#endif return true; }); diff --git a/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs b/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs index 77cfb7b..b6c3d3a 100644 --- a/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs +++ b/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs @@ -11,7 +11,13 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using TinCan; +#if NETSTANDARD using Xamarin.Forms; +#else +using Microsoft.Maui; +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.Controls; +#endif namespace Float.TinCan.ActivityLibrary { @@ -111,7 +117,7 @@ public override void Start() } else { - Device.BeginInvokeOnMainThread(async () => + Action mainThreadCode = async () => { try { @@ -129,7 +135,12 @@ public override void Start() downloadStatus.DownloadsCompleted += HandleDownloadCompleted; downloadStatus.DownloadsCancelled += HandleDownloadCancelled; await ShowDownloadStatus(CreateDownloadStatusPage(downloadStatus)); - }); + }; +#if NETSTANDARD + Device.BeginInvokeOnMainThread(mainThreadCode); +#else + MainThread.BeginInvokeOnMainThread(mainThreadCode); +#endif } } @@ -243,11 +254,16 @@ protected virtual void OnActivityFinished(object sender, EventArgs args) /// protected void ShowCompletionScreen() { - Device.BeginInvokeOnMainThread(async () => + Action mainThreadCode = async () => { var completionPage = CreateActivityCompletePage(AvailablePostAssessments != null && AvailablePostAssessments.Any()); await NavigationContext.PresentPageAsync(completionPage); - }); + }; +#if NETSTANDARD + Device.BeginInvokeOnMainThread(mainThreadCode); +#else + MainThread.BeginInvokeOnMainThread(mainThreadCode); +#endif } /// @@ -273,10 +289,15 @@ protected virtual void HandleCancelDownloadRequested(object sender, EventArgs ar /// Arguments related to the event. protected virtual void HandleActivityFinished(object sender, EventArgs args) { - Device.BeginInvokeOnMainThread(() => + Action mainThreadCode = () => { this.Activity.CompletionDate = DateTimeOffset.Now; - }); + }; +#if NETSTANDARD + Device.BeginInvokeOnMainThread(mainThreadCode); +#else + MainThread.BeginInvokeOnMainThread(mainThreadCode); +#endif if (args is not StatementEventArgs statementArgs) { @@ -319,10 +340,15 @@ protected virtual void HandleActivityProgressed(object sender, EventArgs args) return; } - Device.BeginInvokeOnMainThread(() => + Action mainThreadCode = () => { this.Activity.PercentComplete = (double)percentComplete / 100; - }); + }; +#if NETSTANDARD + Device.BeginInvokeOnMainThread(mainThreadCode); +#else + MainThread.BeginInvokeOnMainThread(mainThreadCode); +#endif } /// @@ -414,7 +440,7 @@ protected virtual void HandleDownloadError(object sender, EventArgs args) void CreateRunnerAndHandleErrors() { - Device.BeginInvokeOnMainThread(async () => + Action mainThreadCode = async () => { try { @@ -427,7 +453,12 @@ void CreateRunnerAndHandleErrors() OnActivityLaunchException(e); Finish(EventArgs.Empty); } - }); + }; +#if NETSTANDARD + Device.BeginInvokeOnMainThread(mainThreadCode); +#else + MainThread.BeginInvokeOnMainThread(mainThreadCode); +#endif } /// diff --git a/Float.TinCan.ActivityLibrary/Definition/IActivityViewer.cs b/Float.TinCan.ActivityLibrary/Definition/IActivityViewer.cs index aec4358..05c6e1c 100644 --- a/Float.TinCan.ActivityLibrary/Definition/IActivityViewer.cs +++ b/Float.TinCan.ActivityLibrary/Definition/IActivityViewer.cs @@ -1,4 +1,9 @@ -using Xamarin.Forms; +#if NETSTANDARD +using Xamarin.Forms; +#else +using Microsoft.Maui; +using Microsoft.Maui.Controls; +#endif namespace Float.TinCan.ActivityLibrary.Definition { diff --git a/Float.TinCan.ActivityLibrary/Float.TinCan.ActivityLibrary.csproj b/Float.TinCan.ActivityLibrary/Float.TinCan.ActivityLibrary.csproj index 8e3766d..c190a0b 100644 --- a/Float.TinCan.ActivityLibrary/Float.TinCan.ActivityLibrary.csproj +++ b/Float.TinCan.ActivityLibrary/Float.TinCan.ActivityLibrary.csproj @@ -1,6 +1,6 @@ - netstandard2.0 + netstandard2;net6.0;net7.0 Float.TinCan.ActivityLibrary Float A library for starting xAPI activities. @@ -11,6 +11,9 @@ $(AssemblyName) false 9.0 + 1.0.0 + + true @@ -29,17 +32,19 @@ readme.md - - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all + + + - + From 9da6aa69f683b583cb0fe2945bb53db305fa9ce4 Mon Sep 17 00:00:00 2001 From: Seamas McGettrick Date: Fri, 15 Sep 2023 00:52:10 -0500 Subject: [PATCH 2/2] Remove restore packages from build script --- build.cake | 1 - 1 file changed, 1 deletion(-) diff --git a/build.cake b/build.cake index 2a32252..4bc99aa 100644 --- a/build.cake +++ b/build.cake @@ -92,7 +92,6 @@ Task("GitVersion") }); Task("Build") - .IsDependentOn("RestorePackages") .IsDependentOn("GitVersion") .Does(() => {