Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dev builds for auto updater #3997

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ jobs:
image: mono:${{ matrix.mono }}

steps:
- uses: actions/checkout@v3

- name: Adding HTTPS support to APT for old Mono images
run: |
apt-get update || true
apt-get install -y apt-transport-https
- name: Installing checkout/build dependencies
run: apt-get update && apt-get install -y git
- uses: actions/checkout@v3

- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7'
- name: Installing build dependencies
run: apt-get update && apt-get install -y git
- name: Install runtime dependencies
run: apt-get install -y xvfb
- name: Restore cache for _build/tools
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
image: mono:latest

steps:
- name: Installing checkout/build dependencies
run: apt-get update && apt-get install -y git make sed gzip fakeroot lintian dpkg-dev gpg createrepo
- uses: actions/checkout@v3

- name: Check version
Expand All @@ -35,8 +37,6 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7'
- name: Installing build dependencies
run: apt-get update && apt-get install -y git make sed gzip fakeroot lintian dpkg-dev gpg createrepo
- name: Installing runtime dependencies
run: apt-get install -y xvfb
- name: Install Docker
Expand Down Expand Up @@ -119,6 +119,9 @@ jobs:
echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
./build docker-metadata --exclusive

- name: Create a version.json file for S3
shell: bash
run: python bin/version_info.py > _build/repack/Release/version.json
- name: Push ckan.exe and netkan.exe to S3
# Send ckan.exe and netkan.exe to https://ksp-ckan.s3-us-west-2.amazonaws.com/
uses: jakejarvis/s3-sync-action@master
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ jobs:
image: mono:latest

steps:
- name: Installing checkout/build dependencies
run: apt-get update && apt-get install -y git make sed libplist-utils xorriso gzip fakeroot lintian rpm wget jq dpkg-dev gpg createrepo
- uses: actions/checkout@v3

- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7'
- name: Installing build dependencies
run: apt-get update && apt-get install -y git make sed libplist-utils xorriso gzip fakeroot lintian rpm wget jq dpkg-dev gpg createrepo
- name: Installing runtime dependencies
run: apt-get install -y xvfb

Expand Down
23 changes: 9 additions & 14 deletions AutoUpdate/Main.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;

Expand Down Expand Up @@ -46,7 +47,7 @@ public static int Main(string[] args)
// Wait for CKAN to close
try
{
if (IsOnWindows())
if (IsOnWindows)
{
// On Unix you can only wait for CHILD processes to exit
var process = Process.GetProcessById(Math.Abs(pid));
Expand Down Expand Up @@ -121,19 +122,19 @@ public static int Main(string[] args)
private static void StartCKAN(string path)
{
// Start CKAN
if (IsOnMono())
if (IsOnMono)
{
Process.Start("mono", string.Format("\"{0}\"", path));
}
else
{
Process.Start(path);
Process.Start(path, "--asroot");
}
}

private static void MakeExecutable(string path)
{
if (!IsOnWindows())
if (!IsOnWindows)
{
// TODO: It would be really lovely (and safer!) to use the native system
// call here: http://docs.go-mono.com/index.aspx?link=M:Mono.Unix.Native.Syscall.chmod
Expand All @@ -151,20 +152,14 @@ private static void MakeExecutable(string path)
/// <summary>
/// Are we on Mono?
/// </summary>
private static bool IsOnMono()
{
return Type.GetType("Mono.Runtime") != null;
}
private static bool IsOnMono
=> Type.GetType("Mono.Runtime") != null;

/// <summary>
/// Are we on Windows?
/// </summary>
private static bool IsOnWindows()
{
PlatformID platform = Environment.OSVersion.Platform;
return platform != PlatformID.MacOSX &&
platform != PlatformID.Unix && platform != PlatformID.Xbox;
}
private static bool IsOnWindows
=> RuntimeInformation.IsOSPlatform(OSPlatform.Windows);

/// <summary>
/// Display unexpected exceptions to user
Expand Down
8 changes: 5 additions & 3 deletions Cmdline/Action/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using CommandLine;
using CommandLine.Text;

using CKAN.Configuration;

namespace CKAN.CmdLine
{
/// <summary>
Expand Down Expand Up @@ -78,7 +80,7 @@ private int ListFilters(FilterListOptions opts)
return exitCode;
}

var cfg = ServiceLocator.Container.Resolve<Configuration.IConfiguration>();
var cfg = ServiceLocator.Container.Resolve<IConfiguration>();
user.RaiseMessage(Properties.Resources.FilterListGlobalHeader);
foreach (string filter in cfg.GlobalInstallFilters)
{
Expand Down Expand Up @@ -111,7 +113,7 @@ private int AddFilters(FilterAddOptions opts, string verb)

if (opts.global)
{
var cfg = ServiceLocator.Container.Resolve<Configuration.IConfiguration>();
var cfg = ServiceLocator.Container.Resolve<IConfiguration>();
var duplicates = cfg.GlobalInstallFilters
.Intersect(opts.filters)
.ToArray();
Expand Down Expand Up @@ -172,7 +174,7 @@ private int RemoveFilters(FilterRemoveOptions opts, string verb)

if (opts.global)
{
var cfg = ServiceLocator.Container.Resolve<Configuration.IConfiguration>();
var cfg = ServiceLocator.Container.Resolve<IConfiguration>();
var notFound = opts.filters
.Except(cfg.GlobalInstallFilters)
.ToArray();
Expand Down
63 changes: 45 additions & 18 deletions Cmdline/Action/Upgrade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
using System.Collections.Generic;
using System.Transactions;

using Autofac;
using log4net;

using CKAN.Versioning;
using CKAN.Configuration;

namespace CKAN.CmdLine
{
Expand Down Expand Up @@ -47,38 +49,63 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
user.RaiseMessage(" or ckan upgrade --all");
if (AutoUpdate.CanUpdate)
{
user.RaiseMessage(" or ckan upgrade ckan");
user.RaiseMessage(" or ckan upgrade ckan [--stable-release|--dev-build]");
}
return Exit.BADOPT;
}

if (!options.upgrade_all && options.modules[0] == "ckan" && AutoUpdate.CanUpdate)
{
user.RaiseMessage(Properties.Resources.UpgradeQueryingCKAN);
AutoUpdate.Instance.FetchLatestReleaseInfo();
var latestVersion = AutoUpdate.Instance.latestUpdate.Version;
var currentVersion = new ModuleVersion(Meta.GetVersion(VersionFormat.Short));
if (options.dev_build && options.stable_release)
{
user.RaiseMessage(Properties.Resources.UpgradeCannotCombineFlags);
return Exit.BADOPT;
}
var config = ServiceLocator.Container.Resolve<IConfiguration>();
var devBuild = options.dev_build
|| (!options.stable_release && config.DevBuilds);
if (devBuild != config.DevBuilds)
{
config.DevBuilds = devBuild;
user.RaiseMessage(
config.DevBuilds
? Properties.Resources.UpgradeSwitchingToDevBuilds
: Properties.Resources.UpgradeSwitchingToStableReleases);
}

if (latestVersion.IsGreaterThan(currentVersion))
user.RaiseMessage(Properties.Resources.UpgradeQueryingCKAN);
try
{
user.RaiseMessage(Properties.Resources.UpgradeNewCKANAvailable, latestVersion);
var releaseNotes = AutoUpdate.Instance.latestUpdate.ReleaseNotes;
user.RaiseMessage(releaseNotes);
user.RaiseMessage("");
user.RaiseMessage("");
var upd = new AutoUpdate();
var update = upd.GetUpdate(config.DevBuilds);
var latestVersion = update.Version;
var currentVersion = new ModuleVersion(Meta.GetVersion());

if (user.RaiseYesNoDialog(Properties.Resources.UpgradeProceed))
if (!latestVersion.Equals(currentVersion))
{
user.RaiseMessage(Properties.Resources.UpgradePleaseWait);
AutoUpdate.Instance.StartUpdateProcess(false);
user.RaiseMessage(Properties.Resources.UpgradeNewCKANAvailable, latestVersion);
var releaseNotes = update.ReleaseNotes;
user.RaiseMessage(releaseNotes);
user.RaiseMessage("");
user.RaiseMessage("");

if (user.RaiseYesNoDialog(Properties.Resources.UpgradeProceed))
{
user.RaiseMessage(Properties.Resources.UpgradePleaseWait);
upd.StartUpdateProcess(false, config.DevBuilds, user);
}
}
else
{
user.RaiseMessage(Properties.Resources.UpgradeAlreadyHaveLatest);
}
return Exit.OK;
}
else
catch (Exception exc)
{
user.RaiseMessage(Properties.Resources.UpgradeAlreadyHaveLatest);
user.RaiseError("Upgrade failed: {0}", exc.Message);
return Exit.ERROR;
}

return Exit.OK;
}

try
Expand Down
13 changes: 3 additions & 10 deletions Cmdline/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,20 @@ public static int Execute(GameInstanceManager manager, CommonOptions opts, strin
}
}
catch (NoGameInstanceKraken)
{
return printMissingInstanceError(new ConsoleUser(false));
}
finally
{
log.Info("CKAN exiting.");
return printMissingInstanceError(new ConsoleUser(false));
}

// Why do we print "CKAN exiting" twice???
Options cmdline;
try
{
cmdline = new Options(args);
}
catch (BadCommandKraken)
{
return AfterHelp();
}
finally
{
log.Info("CKAN exiting.");
return AfterHelp();
}

// Process commandline options.
Expand Down Expand Up @@ -301,7 +294,7 @@ private static int Gui(GameInstanceManager manager, GuiOptions options, string[]
// but trying to catch it here doesn't seem to help. Dunno why.

// GUI expects its first param to be an identifier, don't confuse it
GUI.GUI.Main_(args.Except(new string[] {"--verbose", "--debug", "--show-console"})
GUI.GUI.Main_(args.Except(new string[] {"--verbose", "--debug", "--show-console", "--asroot"})
.ToArray(),
manager, options.ShowConsole);

Expand Down
8 changes: 8 additions & 0 deletions Cmdline/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,14 @@ internal class UpgradeOptions : InstanceSpecificOptions
[Option("all", DefaultValue = false, HelpText = "Upgrade all available updated modules")]
public bool upgrade_all { get; set; }

[Option("dev-build", DefaultValue = false,
HelpText = "For `ckan` option only, use dev builds")]
public bool dev_build { get; set; }

[Option("stable-release", DefaultValue = false,
HelpText = "For `ckan` option only, use stable releases")]
public bool stable_release { get; set; }

[ValueList(typeof (List<string>))]
[InstalledIdentifiers]
public List<string> modules { get; set; }
Expand Down
3 changes: 3 additions & 0 deletions Cmdline/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ Try `ckan list` for a list of installed mods.</value></data>
<data name="UpdateRemovedHeader" xml:space="preserve"><value>Removed modules [Name (CKAN identifier)]:</value></data>
<data name="UpdateUpdatedHeader" xml:space="preserve"><value>Updated modules [Name (CKAN identifier)]:</value></data>
<data name="UpdateSummary" xml:space="preserve"><value>Updated information on {0} compatible modules</value></data>
<data name="UpgradeCannotCombineFlags" xml:space="preserve"><value>The `--dev-build` and `--stable-release` flags cannot be combined!</value></data>
<data name="UpgradeSwitchingToDevBuilds" xml:space="preserve"><value>Switching to dev builds</value></data>
<data name="UpgradeSwitchingToStableReleases" xml:space="preserve"><value>Switching to stable releases</value></data>
<data name="UpgradeQueryingCKAN" xml:space="preserve"><value>Querying the latest CKAN version</value></data>
<data name="UpgradeNewCKANAvailable" xml:space="preserve"><value>New CKAN version available - {0}</value></data>
<data name="UpgradeProceed" xml:space="preserve"><value>Proceed with install?</value></data>
Expand Down
3 changes: 2 additions & 1 deletion ConsoleUI/ModListScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using CKAN.ConsoleUI.Toolkit;
using CKAN.Extensions;
using CKAN.Games;
using CKAN.Configuration;

namespace CKAN.ConsoleUI {

Expand Down Expand Up @@ -540,7 +541,7 @@ private bool EditAuthTokens(ConsoleTheme theme)
private bool EditInstallFilters(ConsoleTheme theme)
{
LaunchSubScreen(theme, new InstallFiltersScreen(
ServiceLocator.Container.Resolve<Configuration.IConfiguration>(),
ServiceLocator.Container.Resolve<IConfiguration>(),
manager.CurrentInstance
));
return true;
Expand Down
Loading
Loading