Skip to content

Commit

Permalink
Merge branch 'dev' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed Sep 27, 2020
2 parents 09d39f5 + 08a49e3 commit 39ef7d1
Show file tree
Hide file tree
Showing 60 changed files with 1,855 additions and 527 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/ci-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Dev Build

on:
push:
branches: [ dev ]
pull_request:
branches: [ dev ]

jobs:
build:

runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build -c Release --no-restore
- name: Test
run: dotnet test -c Release --no-build
23 changes: 23 additions & 0 deletions .github/workflows/ci-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Release Build

on:
push:
branches: [ release ]
pull_request:
branches: [ release ]

jobs:
build:

runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build -c Release --no-restore
- name: Test
run: dotnet test -c Release --no-build
45 changes: 45 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Release

on:
release:
types: [published]

jobs:
release:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build -c Release --no-restore /p:Version=${{ github.event.release.tag_name }} -p:PackageReleaseNotes="See https://github.com/Noggog/Synthesis/releases/tag/${{ github.event.release.tag_name }}"
- name: Test
run: dotnet test --no-build -c Release
- name: Publish Synthesis GUI to Github
uses: svenstaro/upload-release-action@v2
with:
file: Synthesis.Bethesda.GUI/bin/Release/Synthesis.exe
repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.event.release.tag_name }}
- name: Publish Mutagen Synthesis to Github
uses: svenstaro/upload-release-action@v2
with:
file: Mutagen.Bethesda.Synthesis/bin/Release/Mutagen.Bethesda.Synthesis.${{ github.event.release.tag_name }}.nupkg
repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.event.release.tag_name }}
- name: Publish Synthesis Bethesda to Github
uses: svenstaro/upload-release-action@v2
with:
file: Synthesis.Bethesda/bin/Release/Synthesis.Bethesda.${{ github.event.release.tag_name }}.nupkg
repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.event.release.tag_name }}
- name: Publish Synthesis Execution to Github
uses: svenstaro/upload-release-action@v2
with:
file: Synthesis.Bethesda.Execution/bin/Release/Synthesis.Bethesda.Execution.${{ github.event.release.tag_name }}.nupkg
repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.event.release.tag_name }}
- name: Publish to Nuget.org
run: dotnet nuget push **/*${{ github.event.release.tag_name }}.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --no-symbols true
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<PropertyGroup>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
<Version>0.7.1.0-dev</Version>
</PropertyGroup>
</Project>
7 changes: 3 additions & 4 deletions Mutagen.Bethesda.Synthesis/Mutagen.Bethesda.Synthesis.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
Expand All @@ -12,7 +12,6 @@
<RepositoryUrl>https://github.com/Noggog/Synthesis</RepositoryUrl>
<PackageLicenseExpression>GPL-3.0-only</PackageLicenseExpression>
<AssemblyName>Mutagen.Bethesda.Synthesis</AssemblyName>
<Version>0.7.0.0</Version>
<Platforms>x64</Platforms>
</PropertyGroup>

Expand All @@ -23,8 +22,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Mutagen.Bethesda" Version="0.16.0" />
<PackageReference Include="Mutagen.Bethesda.Kernel" Version="0.16.0" />
<PackageReference Include="Mutagen.Bethesda" Version="[0.17,0.18)" />
<PackageReference Include="Mutagen.Bethesda.Kernel" Version="[0.17,0.18)" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 4 additions & 2 deletions Mutagen.Bethesda.Synthesis/SynthesisPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ public async Task Patch<TMod, TModGetter>(
state.PatchMod.WriteToBinaryParallel(path: settings.OutputPath, param: GetWriteParams(state.LoadOrder.Select(i => i.Key)));
}
catch (Exception ex)
when (userPreferences?.ActionsForEmptyArgs?.BlockAutomaticExit ?? false)
when (Environment.GetCommandLineArgs().Length == 0
&& (userPreferences?.ActionsForEmptyArgs?.BlockAutomaticExit ?? false))
{
System.Console.Error.WriteLine(ex);
System.Console.Error.WriteLine("Error occurred. Press enter to exit");
Expand Down Expand Up @@ -237,7 +238,8 @@ public void Patch<TMod, TModGetter>(
state.PatchMod.WriteToBinaryParallel(path: settings.OutputPath, param: GetWriteParams(state.LoadOrder.Select(i => i.Key)));
}
catch (Exception ex)
when (userPreferences?.ActionsForEmptyArgs?.BlockAutomaticExit ?? false)
when (Environment.GetCommandLineArgs().Length == 0
&& (userPreferences?.ActionsForEmptyArgs?.BlockAutomaticExit ?? false))
{
System.Console.Error.WriteLine(ex);
System.Console.Error.WriteLine("Error occurred. Press enter to exit");
Expand Down
1 change: 0 additions & 1 deletion Synthesis.Bethesda.CLI/Synthesis.Bethesda.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<Product>Synthesis</Product>
<Description>A lightweight wrapper CLI to run Synthesis pipelines without a GUI</Description>
<Platforms>x64</Platforms>
<Version>0.7.0.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
105 changes: 105 additions & 0 deletions Synthesis.Bethesda.Execution/Patcher Runs/GithubPatcherRun.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using LibGit2Sharp;
using Mutagen.Bethesda;
using Noggog;
using Synthesis.Bethesda.Execution.Patchers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reactive.Subjects;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Synthesis.Bethesda.Execution
{
public class GithubPatcherRun : IPatcherRun
{
public string Name { get; }
private readonly string _nickname;
private readonly string _remote;
private readonly string _localDir;
private readonly string _pathToSln;
private readonly string _pathToProj;
private readonly string _pathToExe;
public SolutionPatcherRun? SolutionRun { get; private set; }

private Subject<string> _output = new Subject<string>();
public IObservable<string> Output => _output;

private Subject<string> _error = new Subject<string>();
public IObservable<string> Error => _error;

public GithubPatcherRun(string nickname, string remote, string localDir, string pathToSln, string pathToProj, string pathToExe)
{
_nickname = nickname;
_remote = remote;
_localDir = localDir;
_pathToProj = pathToProj;
_pathToSln = pathToSln;
_pathToExe = pathToExe;
Name = $"{nickname} => {remote} => {Path.GetFileNameWithoutExtension(pathToProj)}";
}

public void Dispose()
{
}

public async Task Prep(GameRelease release, CancellationToken? cancel = null)
{
var prepResult = await PrepRepo(GetResponse<string>.Succeed(_remote), _localDir, cancel ?? CancellationToken.None);
if (prepResult.Failed)
{
throw new SynthesisBuildFailure(prepResult.Reason);
}
SolutionRun = new SolutionPatcherRun(_nickname, Path.Combine(_localDir, _pathToSln), Path.Combine(_localDir, _pathToProj), Path.Combine(_localDir, _pathToExe));
await SolutionRun.Prep(release, cancel).ConfigureAwait(false);
}

public async Task Run(RunSynthesisPatcher settings, CancellationToken? cancel = null)
{
if (SolutionRun == null)
{
throw new SynthesisBuildFailure("Expected Solution Run object did not exist.");
}
await SolutionRun.Run(settings, cancel).ConfigureAwait(false);
}

private static bool DeleteOldRepo(string localDir, GetResponse<string> remoteUrl)
{
if (!Directory.Exists(localDir)) return false;
var dirInfo = new DirectoryPath(localDir);
if (remoteUrl.Failed)
{
dirInfo.DeleteEntireFolder();
return false;
}
using var repo = new Repository(localDir);
// If it's the same remote repo, don't delete
if (repo.Network.Remotes.FirstOrDefault()?.Url.Equals(remoteUrl.Value) ?? false) return true;
dirInfo.DeleteEntireFolder();
return false;
}

public static async Task<GetResponse<(string Remote, string Local)>> PrepRepo(GetResponse<string> remote, string localDir, CancellationToken cancel)
{
try
{
cancel.ThrowIfCancellationRequested();
if (DeleteOldRepo(localDir: localDir, remoteUrl: remote))
{
// Short circuiting deletion
return GetResponse<(string Remote, string Local)>.Succeed((remote.Value, localDir), remote.Reason);
}
cancel.ThrowIfCancellationRequested();
if (remote.Failed) return GetResponse<(string Remote, string Local)>.Fail((remote.Value, string.Empty), remote.Reason);
var clonePath = Repository.Clone(remote.Value, localDir);
return GetResponse<(string Remote, string Local)>.Succeed((remote.Value, clonePath), remote.Reason);
}
catch (Exception ex)
{
return GetResponse<(string Remote, string Local)>.Fail((remote.Value, string.Empty), ex);
}
}
}
}
2 changes: 1 addition & 1 deletion Synthesis.Bethesda.Execution/Patcher Runs/IPatcherRun.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Mutagen.Bethesda;
using Mutagen.Bethesda;
using System;
using System.Collections.Generic;
using System.Text;
Expand Down
32 changes: 8 additions & 24 deletions Synthesis.Bethesda.Execution/Patcher Runs/SolutionPatcherRun.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Buildalyzer;
using Buildalyzer.Environment;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Emit;
Expand All @@ -26,6 +24,7 @@ public class SolutionPatcherRun : IPatcherRun
public string Name { get; }
public string PathToSolution { get; }
public string PathToProject { get; }
public string PathToExe { get; }
public CliPatcherRun? CliRun { get; private set; }

private Subject<string> _output = new Subject<string>();
Expand All @@ -34,34 +33,19 @@ public class SolutionPatcherRun : IPatcherRun
private Subject<string> _error = new Subject<string>();
public IObservable<string> Error => _error;

public SolutionPatcherRun(string nickname, string pathToSln, string pathToProj)
public SolutionPatcherRun(string nickname, string pathToSln, string pathToProj, string pathToExe)
{
PathToSolution = pathToSln;
PathToProject = pathToProj;
Name = $"{Path.GetFileNameWithoutExtension(pathToSln)} => {Path.GetFileNameWithoutExtension(pathToProj)}";
PathToExe = pathToExe;
Name = $"{nickname} => {Path.GetFileNameWithoutExtension(pathToSln)} => {Path.GetFileNameWithoutExtension(pathToProj)}";
}

public async Task Prep(GameRelease release, CancellationToken? cancel = null)
{
// Right now this is slow as it cleans the build results unnecessarily. Need to look into that
var manager = new AnalyzerManager();
var proj = manager.GetProject(PathToProject);
var opt = new EnvironmentOptions();
opt.TargetsToBuild.SetTo("Build");
var build = proj.Build();
var results = build.Results.ToArray();
if (results.Length != 1)
{
throw new SynthesisBuildFailure("Unsupported number of build results.");
}
var result = results[0];
if (!result.Properties.TryGetValue("RunCommand", out var cmd))
{
throw new SynthesisBuildFailure("Could not find executable to be run");
}
CliRun = new CliPatcherRun(nickname: Name, pathToExecutable: cmd);
CliRun = new CliPatcherRun(nickname: Name, pathToExecutable: PathToExe);

var resp = await CompileWithDotnet(PathToSolution, cancel ?? CancellationToken.None).ConfigureAwait(false);
var resp = await CompileWithDotnet(PathToProject, cancel ?? CancellationToken.None).ConfigureAwait(false);
if (!resp.Succeeded)
{
throw new SynthesisBuildFailure(resp.Reason);
Expand Down Expand Up @@ -121,10 +105,10 @@ public void Dispose()
return (true, default);
}

public static async Task<ErrorResponse> CompileWithDotnet(string solutionUrl, CancellationToken cancel)
public static async Task<ErrorResponse> CompileWithDotnet(string url, CancellationToken cancel)
{
using var process = ProcessWrapper.Start(
new ProcessStartInfo("dotnet", $"build \"{solutionUrl}\""),
new ProcessStartInfo("dotnet", $"build \"{url}\""),
cancel: cancel);
string? firstError = null;
bool buildFailed = false;
Expand Down
6 changes: 5 additions & 1 deletion Synthesis.Bethesda.Execution/Runner/IRunReporter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Synthesis.Bethesda.Execution.Patchers;
using Synthesis.Bethesda.Execution.Patchers;
using System;
using System.Collections.Generic;
using System.Text;
Expand All @@ -12,6 +12,8 @@ public interface IRunReporter<TKey>
void ReportRunProblem(TKey key, IPatcherRun patcher, Exception ex);
void ReportStartingRun(TKey key, IPatcherRun patcher);
void ReportRunSuccessful(TKey key, IPatcherRun patcher, string outputPath);
void ReportOutput(string str);
void ReportError(string str);
}

public interface IRunReporter
Expand All @@ -21,5 +23,7 @@ public interface IRunReporter
void ReportRunProblem(IPatcherRun patcher, Exception ex);
void ReportStartingRun(IPatcherRun patcher);
void ReportRunSuccessful(IPatcherRun patcher, string outputPath);
void ReportOutput(string str);
void ReportError(string str);
}
}
Loading

0 comments on commit 39ef7d1

Please sign in to comment.