Add migration test from velo 0.0.84

This commit is contained in:
Caelan Sayler
2024-01-15 21:53:47 +00:00
parent 329742ad1e
commit 1cae116d78
7 changed files with 92 additions and 6 deletions

View File

@@ -0,0 +1,7 @@
dotnet build -c Release -p:UseVelopack=0.0.84
dotnet tool install vpk --version 0.0.84 --tool-path bin/vpk
./bin/vpk/vpk.exe pack -u LegacyTestApp -v 1.0.0 -p bin/Release/net48

View File

@@ -6,18 +6,23 @@
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<!--<UseClowd>2.11.1</UseClowd>--> <!--<UseClowd>2.11.1</UseClowd>-->
<!--<UseClowd>3.0.210-*</UseClowd>--> <!--<UseClowd>3.0.210-*</UseClowd>-->
<!--<UseVelopack>0.0.84</UseVelopack>-->
</PropertyGroup> </PropertyGroup>
<Choose> <Choose>
<When Condition=" $(UseClowd) != '' "> <When Condition=" $(UseClowd) != '' or $(UseVelopack) != '' ">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<DefineConstants>CLOWD</DefineConstants> <DefineConstants Condition="$(UseClowd) != ''">CLOWD</DefineConstants>
<DefineConstants Condition="$(UseVelopack) != ''">VELOPACK</DefineConstants>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup Condition=" $(UseClowd) != '' ">
<PackageReference Include="Clowd.Squirrel" Version="$(UseClowd)" /> <PackageReference Include="Clowd.Squirrel" Version="$(UseClowd)" />
<None Update="LegacyTestApp.exe.squirrel" CopyToOutputDirectory="Always" /> <None Update="LegacyTestApp.exe.squirrel" CopyToOutputDirectory="Always" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition=" $(UseVelopack) != '' ">
<PackageReference Include="Velopack" Version="$(UseVelopack)" />
</ItemGroup>
</When> </When>
<Otherwise> <Otherwise>
<ItemGroup> <ItemGroup>

View File

@@ -2,7 +2,11 @@
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
#if VELOPACK
using Velopack;
#else
using Squirrel; using Squirrel;
#endif
[assembly: AssemblyMetadata("SquirrelAwareVersion", "1")] [assembly: AssemblyMetadata("SquirrelAwareVersion", "1")]
@@ -19,6 +23,13 @@ namespace LegacyTestApp
onAppUninstall: (v, t) => debugFile("args.txt", String.Join(" ", args)), onAppUninstall: (v, t) => debugFile("args.txt", String.Join(" ", args)),
onEveryRun: (v, t, f) => debugFile("args.txt", String.Join(" ", args)) onEveryRun: (v, t, f) => debugFile("args.txt", String.Join(" ", args))
); );
#elif VELOPACK
VelopackApp.Build()
.WithAfterInstallFastCallback(v => debugFile("args.txt", String.Join(" ", args)))
.WithBeforeUpdateFastCallback(v => debugFile("args.txt", String.Join(" ", args)))
.WithBeforeUninstallFastCallback(v => debugFile("args.txt", String.Join(" ", args)))
.WithAfterUpdateFastCallback(v => debugFile("args.txt", String.Join(" ", args)))
.Run();
#else #else
SquirrelAwareApp.HandleEvents( SquirrelAwareApp.HandleEvents(
onInitialInstall: v => debugFile("args.txt", String.Join(" ", args)), onInitialInstall: v => debugFile("args.txt", String.Join(" ", args)),
@@ -29,17 +40,34 @@ namespace LegacyTestApp
#endif #endif
try { try {
#if !VELOPACK
SquirrelLogger.Register(); SquirrelLogger.Register();
#endif
if (args.Length == 1 && args[0] == "version") { if (args.Length == 1 && args[0] == "version") {
#if VELOPACK
var um = new UpdateManager("n/a", logger: new SquirrelLogger());
Console.WriteLine(um.CurrentVersion?.ToString() ?? "unknown_version");
#else
using var um = new UpdateManager(""); using var um = new UpdateManager("");
Console.WriteLine(um.CurrentlyInstalledVersion()?.ToString() ?? "unknown_version"); Console.WriteLine(um.CurrentlyInstalledVersion()?.ToString() ?? "unknown_version");
#endif
return 0; return 0;
} }
if (args.Length == 2) { if (args.Length == 2) {
if (args[0] == "check") { if (args[0] == "check") {
#if VELOPACK
var um = new UpdateManager(args[1]);
var info = um.CheckForUpdates();
if (info == null || info.TargetFullRelease == null) {
Console.WriteLine("no updates");
return 0;
} else {
Console.WriteLine("update: " + info.TargetFullRelease.Version);
return 0;
}
#else
using var um = new UpdateManager(args[1]); using var um = new UpdateManager(args[1]);
var info = um.CheckForUpdate().GetAwaiter().GetResult(); var info = um.CheckForUpdate().GetAwaiter().GetResult();
if (info == null || info.ReleasesToApply == null || info.FutureReleaseEntry == null || info.ReleasesToApply.Count == 0) { if (info == null || info.ReleasesToApply == null || info.FutureReleaseEntry == null || info.ReleasesToApply.Count == 0) {
@@ -49,16 +77,30 @@ namespace LegacyTestApp
Console.WriteLine("update: " + info.FutureReleaseEntry.Version); Console.WriteLine("update: " + info.FutureReleaseEntry.Version);
return 0; return 0;
} }
#endif
} }
if (args[0] == "download") { if (args[0] == "download") {
#if VELOPACK
var um = new UpdateManager(args[1]);
var info = um.CheckForUpdates();
if (info == null) return -1;
um.DownloadUpdates(info);
return 0;
#else
using var um = new UpdateManager(args[1]); using var um = new UpdateManager(args[1]);
var entry = um.UpdateApp().GetAwaiter().GetResult(); var entry = um.UpdateApp().GetAwaiter().GetResult();
return entry == null ? -1 : 0; return entry == null ? -1 : 0;
#endif
} }
if (args[0] == "apply") { if (args[0] == "apply") {
#if VELOPACK
var um = new UpdateManager(args[1]);
um.ApplyUpdatesAndRestart();
#else
UpdateManager.RestartApp(); UpdateManager.RestartApp();
#endif
return 0; return 0;
} }
} }

View File

@@ -2,7 +2,27 @@
namespace LegacyTestApp namespace LegacyTestApp
{ {
internal class SquirrelLogger : Squirrel.SimpleSplat.ILogger #if VELOPACK
using Microsoft.Extensions.Logging;
class SquirrelLogger : ILogger
{
public IDisposable BeginScope<TState>(TState state) where TState : notnull
{
return null;
}
public bool IsEnabled(LogLevel logLevel)
{
return true;
}
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
Console.WriteLine(formatter(state, exception));
}
}
#else
class SquirrelLogger : Squirrel.SimpleSplat.ILogger
{ {
protected SquirrelLogger() protected SquirrelLogger()
{ {
@@ -20,4 +40,5 @@ namespace LegacyTestApp
Console.WriteLine(message); Console.WriteLine(message);
} }
} }
#endif
} }

View File

@@ -18,3 +18,10 @@ rmdir /s /q releases
powershell -executionpolicy bypass ./BuildClowdV3.ps1 powershell -executionpolicy bypass ./BuildClowdV3.ps1
copy /Y releases\LegacyTestAppSetup.exe ..\fixtures\LegacyTestApp-ClowdV3-Setup.exe copy /Y releases\LegacyTestAppSetup.exe ..\fixtures\LegacyTestApp-ClowdV3-Setup.exe
rmdir /s /q bin
rmdir /s /q obj
rmdir /s /q releases
powershell -executionpolicy bypass ./BuildVelopack0084.ps1
copy /Y releases\LegacyTestApp-win-Setup.exe ..\fixtures\LegacyTestApp-Velopack0084-Setup.exe

View File

@@ -487,6 +487,7 @@ public class WindowsPackTests
[InlineData("LegacyTestApp-ClowdV2-Setup.exe", "app-1.0.0")] [InlineData("LegacyTestApp-ClowdV2-Setup.exe", "app-1.0.0")]
[InlineData("LegacyTestApp-ClowdV3-Setup.exe", "current")] [InlineData("LegacyTestApp-ClowdV3-Setup.exe", "current")]
[InlineData("LegacyTestApp-SquirrelWinV2-Setup.exe", "app-1.0.0")] [InlineData("LegacyTestApp-SquirrelWinV2-Setup.exe", "app-1.0.0")]
[InlineData("LegacyTestApp-Velopack0084-Setup.exe", "current")]
public void LegacyAppCanSuccessfullyMigrate(string fixture, string origDirName) public void LegacyAppCanSuccessfullyMigrate(string fixture, string origDirName)
{ {
Skip.IfNot(VelopackRuntimeInfo.IsWindows); Skip.IfNot(VelopackRuntimeInfo.IsWindows);
@@ -528,6 +529,9 @@ public class WindowsPackTests
// this is the file written by TestApp when it's detected the squirrel restart. if this is here, everything went smoothly. // this is the file written by TestApp when it's detected the squirrel restart. if this is here, everything went smoothly.
Assert.True(File.Exists(Path.Combine(rootDir, "restarted"))); Assert.True(File.Exists(Path.Combine(rootDir, "restarted")));
var chk3version = RunNoCoverage(appExe, new string[] { "version" }, currentDir, logger);
Assert.EndsWith(Environment.NewLine + "2.0.0", chk3version);
} }
//private string RunCoveredRust(string binName, string[] args, string workingDir, ILogger logger, int? exitCode = 0) //private string RunCoveredRust(string binName, string[] args, string workingDir, ILogger logger, int? exitCode = 0)

Binary file not shown.