Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Use ubuntu 18 binary if default linux binary fails
Browse files Browse the repository at this point in the history
  • Loading branch information
refactorsaurusrex committed Dec 25, 2020
1 parent 9d1dbc5 commit 0cca0e3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
2 changes: 1 addition & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if ($LASTEXITCODE -ne 0) {
throw "Failed to publish application."
}

$targets = 'win-x64','linux-x64','osx-x64'
$targets = 'win-x64','linux-x64','osx-x64','ubuntu.18.04-x64'
foreach ($target in $targets) {
dotnet publish $proj -c Release --self-contained true -r $target --output "$publishOutputDir\$target"
if ($LASTEXITCODE -ne 0) {
Expand Down
5 changes: 4 additions & 1 deletion src/JournalCli/Cmdlets/CmdletBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public abstract class CmdletBase : PSCmdlet
protected CmdletBase()
{
// ReSharper disable AssignNullToNotNullAttribute
LogsDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "logs");
ModuleDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
LogsDirectory = Path.Combine(ModuleDirectory, "logs");
var path = Path.Combine(LogsDirectory, ".log");
// ReSharper restore AssignNullToNotNullAttribute
Log.Logger = new LoggerConfiguration()
Expand All @@ -28,6 +29,8 @@ protected CmdletBase()

protected string LogsDirectory { get; }

protected string ModuleDirectory { get; }

protected string ResolvePath(string path) => GetUnresolvedProviderPathFromPSPath(path);

protected void ThrowTerminatingError(string message, ErrorCategory category)
Expand Down
57 changes: 32 additions & 25 deletions src/JournalCli/Cmdlets/JournalCmdletBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.IO.Abstractions;
using System.Linq;
using System.Management.Automation;
Expand All @@ -17,6 +18,7 @@ public abstract class JournalCmdletBase : CmdletBase

#if !DEBUG
private static bool _beenWarned;
private static bool _binaryMoveAttempted;
private const string MissingGitBinaryWarning = "You're missing a native binary that's required to enable git integration. " +
"Click here for more information:\r\n\r\nhttps://journalcli.me/docs/faq#i-got-a-missing-git-binary-warning-whats-that-about\r\n";
#endif
Expand Down Expand Up @@ -87,40 +89,45 @@ private protected Journal OpenJournal()

protected void Commit(GitCommitType commitType)
{
#if !DEBUG
try
{
ValidateGitRepo();
var message = GitCommitMessage.Get(commitType);
CommitCore(message);
}
catch (TypeInitializationException e) when (e.InnerException is DllNotFoundException)
{
Log.Error(e, "Error encountered during Commit()");
if (!_beenWarned)
{
WriteWarning(MissingGitBinaryWarning);
_beenWarned = true;
}
}
#endif
var message = GitCommitMessage.Get(commitType);
Commit(message);
}

protected void Commit(string message)
{
#if !DEBUG
try
void TryMovingLinuxBinaries()
{
ValidateGitRepo();
CommitCore(message);
var binaries = Directory.GetFiles(Path.Combine(ModuleDirectory, "ubuntu.18.04-x64"));
foreach (var binary in binaries)
{
var destination = Path.Combine(ModuleDirectory, "linux-x64", Path.GetFileName(binary));
File.Copy(binary, destination, true);
}
}
catch (TypeInitializationException e) when (e.InnerException is DllNotFoundException)

while (!_beenWarned || !_binaryMoveAttempted)
{
Log.Error(e, "Error encountered during Commit()");
if (!_beenWarned)
try
{
ValidateGitRepo();
CommitCore(message);
}
catch (TypeInitializationException e) when (e.InnerException is DllNotFoundException)
{
WriteWarning(MissingGitBinaryWarning);
_beenWarned = true;
Log.Error(e, $"Error encountered while executing {nameof(Commit)} method");

if (_binaryMoveAttempted)
{
if (_beenWarned) continue;
WriteWarning(MissingGitBinaryWarning);
_beenWarned = true;
}
else
{
TryMovingLinuxBinaries();
_binaryMoveAttempted = true;
}
}
}
#endif
Expand Down

0 comments on commit 0cca0e3

Please sign in to comment.