Skip to content

Commit

Permalink
Merge branch 'main' into refactor-scubadiver
Browse files Browse the repository at this point in the history
  • Loading branch information
Qonfused authored Oct 28, 2024
2 parents 58923ac + 9ff6606 commit b4f030b
Show file tree
Hide file tree
Showing 27 changed files with 625 additions and 297 deletions.
113 changes: 0 additions & 113 deletions .github/workflows/build.yml

This file was deleted.

100 changes: 100 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Test
on:
push:
branches: [main]
pull_request:
types: [opened, synchronize]
paths:
- '.github/workflows/test.yml'
- '**/*.cs'
- '**/*.sln'
- '**/*.csproj'
- '**/*.props'
- '**/*.targets'
- '**/packages.lock.json'
workflow_dispatch:
concurrency:
group: ci-${{ github.workflow }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
test:
runs-on: windows-latest
name: "Run SDK Tests"
timeout-minutes: 15
steps:
# Creates a dev drive using ReFS.
#
# This step creates a 10GB VHDX file, mounts it, initializes the disk,
# creates a partition, and formats the volume using ReFS. The drive letter
# is stored in the DEV_DRIVE environment variable for later use.
- name: Create dev drive using ReFS
run: |
$VHD_PATH = "${{ github.workspace }}/dev.vhdx"
$Volume = New-VHD -Path $VHD_PATH -SizeBytes 10GB -Fixed |
Mount-VHD -Passthru |
Initialize-Disk -Passthru |
New-Partition -AssignDriveLetter -UseMaximumSize |
Format-Volume -FileSystem ReFS -Confirm:$false -Force
Write-Output "WORKSPACE=$($Volume.DriveLetter):/workspace" >> $env:GITHUB_ENV
# Checks out the repository to the dev drive.
#
# This is a patch of the actions/checkout action to allow for `path` to
# point to another drive. By default, this is restricted to paths relative
# to the $GITHUB_WORKSPACE directory, which is slower than a ReFS VHDX.
- name: Checkout latest repository commit
uses: Qonfused/checkout@4.2.2
with:
path: ${{ env.WORKSPACE }}
show-progress: false
fetch-depth: 0 # Disable shallow clone for Nerdbank.GitVersioning

# Setup the .NET environment
- name: Install .NET Core
uses: actions/setup-dotnet@v4

# Setup NuGet environment
- name: Setup NuGet
uses: NuGet/setup-nuget@v2

- name: Restore NuGet Cache
id: nuget-cache
uses: actions/cache@v4
with:
path: ${{ env.WORKSPACE }}/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Restore NuGet packages
if: steps.nuget-cache.outputs.cache-hit != 'true'
run: |
nuget restore `
-Verbosity quiet `
-NonInteractive -UseLockFile `
-OutputDirectory "${{ env.WORKSPACE }}/packages"
working-directory: ${{ env.WORKSPACE }}

# Build the SDK
- name: Build SDK Solution
run: dotnet build
working-directory: ${{ env.WORKSPACE }}

# Create .env file for integration tests
- name: Create .env file
run: |
echo "USERNAME=${{ secrets.USERNAME }}" > .env
echo "PASSWORD=${{ secrets.PASSWORD }}" >> .env
working-directory: ${{ env.WORKSPACE }}

# Run the test suite
#
# Run tests with a retry mechanism to handle transient test failures from
# slow Windows runners. This is a workaround for intermittent crashes
# caused by small Windows Server 2022 runners' service instability.
- name: Run tests
uses: nick-fields/retry@v3
with:
timeout_minutes: 10
max_attempts: 3
command: dotnet test "${{ env.WORKSPACE }}" --no-build -clp:NoSummary
3 changes: 3 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<!-- MTGOSDK/lib/ILRepack -->
<PackageVersion Include="ILRepack.Lib.MSBuild.Task"
Version="2.0.34.1" />
<!-- MTGOSDK/lib/Launcher -->
<PackageVersion Include="FrameworkExtract.System.Deployment"
Version="4.0.30319" />
<!-- MTGOSDK.MSBuild -->
<PackageVersion Include="Microsoft.Build.Utilities.Core"
Version="17.10.4" />
Expand Down
4 changes: 2 additions & 2 deletions MTGOSDK.Tests/src/Tests/MTGOSDK.API/History.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace MTGOSDK.Tests.MTGOSDK_API;

public class History : HistoryValidationFixture
{
[Test]
// [Test]
public void Test_HistoryManager()
{
Assert.That(HistoryManager.HistoryLoaded, Is.True);
Expand Down Expand Up @@ -47,7 +47,7 @@ public void Test_HistoryManager()

// [RateLimit(ms: 300)]
// [TestCase<HistoricalItem>()]
[TestCase<HistoricalMatch>()]
// [TestCase<HistoricalMatch>()]
// [TestCase<HistoricalTournament>()]
public void Test_HistoricalItems<T>()
where T : class
Expand Down
7 changes: 5 additions & 2 deletions MTGOSDK.Tests/src/Tests/SetupFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ public virtual async Task RunAfterAnyTests()
if (!RemoteClient.IsInitialized && client == null) return;

// Log off the client to ensure that the user session terminates.
await client.LogOff();
Assert.That(Client.IsLoggedIn, Is.False);
if (!Client.IsInteractive)
{
await client.LogOff();
Assert.That(Client.IsLoggedIn, Is.False);
}

// Set a callback to indicate when the client has been disposed.
bool isDisposed = false;
Expand Down
11 changes: 11 additions & 0 deletions MTGOSDK.Win32/src/Deployment/ClickOncePaths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ public static class ClickOncePaths
private const string SIDEBYSIDE_STATE_MANAGER_REGISTRY_KEY_PATH =
@"SOFTWARE\Classes\Software\Microsoft\Windows\CurrentVersion\Deployment\SideBySide\2.0\StateManager";

/// <summary>
/// The path to the ClickOnce service executable.
/// </summary>
/// <remarks>
/// This is the executable that is used to launch and install ClickOnce
/// applications. It handles redirects from .application and .appref-ms files.
/// </remarks>
public static string ClickOnceServiceExecutable =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows),
@"Microsoft.NET\Framework\v4.0.30319\dfsvc.exe");

/// <summary>
/// The application directory for ClickOnce deployments.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions MTGOSDK/lib/Launcher/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!dist/
40 changes: 40 additions & 0 deletions MTGOSDK/lib/Launcher/Launcher.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<LangVersion>Latest</LangVersion>
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FrameworkExtract.System.Deployment" />
</ItemGroup>

<!-- Merge the Launcher executable with System.Deployment.dll -->
<PropertyGroup>
<ILRepackTargetsFile>
$(MSBuildThisFileDirectory)..\ILRepack\ILRepack.targets
</ILRepackTargetsFile>
<ILRepackTarget>Launcher</ILRepackTarget>
<ILRepackOutput>$(SolutionDir)dist\$(Configuration)\$(ILRepackTarget).exe</ILRepackOutput>
</PropertyGroup>

<Target Name="BuildArtifactDirectory"
AfterTargets="AfterBuild;MergeReferenceAssemblies">
<Copy SourceFiles="$(OutputPath)Launcher.exe"
DestinationFolder="$(MSBuildThisFileDirectory)\dist" />
<!-- Write a build timestamp to the dist/ directory -->
<PropertyGroup>
<BuildTimestamp>$([System.DateTime]::UtcNow.ToString("o"))</BuildTimestamp>
</PropertyGroup>
<WriteLinesToFile File="$(MSBuildThisFileDirectory)\dist\build.timestamp"
Lines="$(BuildTimestamp)"
Overwrite="true" />
</Target>

</Project>
59 changes: 59 additions & 0 deletions MTGOSDK/lib/Launcher/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/** @file
Copyright (c) 2024, Cory Bennett. All rights reserved.
SPDX-License-Identifier: Apache-2.0
**/

using System;
using System.Threading;
using System.Deployment.Application;


namespace Launcher;

public class Program
{
public static void Main(string[] args)
{
try
{
string manifestUri = args[0];
InPlaceHostingManager iphm = new(new Uri(manifestUri), false);
AutoResetEvent waitHandle = new(false);

// Download the deployment manifest.
iphm.GetManifestCompleted += (sender, e) =>
{
if (e.Error != null)
throw new Exception(
"Could not download manifest. Error: " + e.Error.Message);

waitHandle.Set();
};
iphm.GetManifestAsync();
waitHandle.WaitOne();

// Verify and grant permissions specified in the application manifest.
iphm.AssertApplicationRequirements(true);

// Download the deployment manifest.
iphm.DownloadApplicationCompleted += (sender, e) =>
{
if (e.Error != null)
throw new Exception(
"Could not download application. Error: " + e.Error.Message);

waitHandle.Set();
};
iphm.DownloadApplicationAsync();
waitHandle.WaitOne();

Environment.Exit(0);
}
catch (Exception ex)
{
// Send the exception message to STDERR
Console.Error.WriteLine(ex.Message);
Environment.Exit(1);
}
}
}
Binary file added MTGOSDK/lib/Launcher/dist/Launcher.exe
Binary file not shown.
1 change: 1 addition & 0 deletions MTGOSDK/lib/Launcher/dist/build.timestamp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-10-22T09:01:36.1196273Z
Loading

0 comments on commit b4f030b

Please sign in to comment.