Skip to content

Commit

Permalink
Merge pull request #1 from AlamoEngine-Tools/develop
Browse files Browse the repository at this point in the history
New Releases
  • Loading branch information
AnakinRaW authored May 31, 2024
2 parents d434ab6 + 09afc2a commit 38c6035
Show file tree
Hide file tree
Showing 22 changed files with 209 additions and 29 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Releasing ModVerify

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:

# Builds and tests the solution.
test:
uses: ./.github/workflows/test.yml

pack:
name: Pack
needs: [test]
runs-on: windows-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
- name: Setup .NET
uses: actions/setup-dotnet@v4
- name: Create NetFramework Release
run: dotnet publish .\src\ModVerify.CliApp\ModVerify.CliApp.csproj --configuration Release -f net48 --output ./releases/net48
- name: Create Net Core Release
run: dotnet publish .\src\ModVerify.CliApp\ModVerify.CliApp.csproj --configuration Release -f net8.0 --output ./releases/net8.0
- name: Upload a Build Artifact
uses: actions/upload-artifact@v4
with:
name: Binary Releases
path: ./releases
if-no-files-found: error
retention-days: 1

deploy:
name: Deploy
if: |
github.ref == 'refs/heads/main' && github.event_name == 'push'
needs: [pack]
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/download-artifact@v4
with:
name: Binary Releases
path: ./releases
- name: Create NET Core zip
# Change into the artifacts directory to avoid including the directory itself in the zip archive
working-directory: ./releases/net8.0
run: zip -r ./releases/ModVerify-Net8.zip .
- uses: dotnet/[email protected]
id: nbgv
- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
name: v${{ steps.nbgv.outputs.SemVer2 }}
tag_name: v${{ steps.nbgv.outputs.SemVer2 }}
token: ${{ secrets.GITHUB_TOKEN }}
generate_release_notes: true
files: |
./releases/net48/ModVerify.CliApp.exe
./releases/ModVerify-Net8.zip
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: Petroglyph Tools .NET Build & Test
name: ModVerify Build & Test

on:
workflow_call:
workflow_dispatch:
push:
branches: [ main ]
branches: [ develop ]
pull_request:
branches: [ main ]
branches: [ develop ]

jobs:
build-test:
Expand Down
9 changes: 9 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Condition="!Exists('packages.config')">
<PrivateAssets>all</PrivateAssets>
<Version>3.6.133</Version>
</PackageReference>
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions src/ModVerify.CliApp/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<Costura />
</Weavers>
4 changes: 4 additions & 0 deletions src/ModVerify.CliApp/ModVerify.CliApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<ItemGroup>
<PackageReference Include="AlamoEngineTools.PG.StarWarsGame.Infrastructure.Clients" Version="3.1.5" />
<PackageReference Include="AlamoEngineTools.SteamAbstraction" Version="3.1.5" />
<PackageReference Include="Costura.Fody" Version="5.7.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
Expand Down
6 changes: 4 additions & 2 deletions src/ModVerify.CliApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static async Task Main(string[] args)
}
}

private static VerifyFocPipeline BuildPipeline(IPlayableObject playableObject, IGame fallbackGame)
private static VerifyGamePipeline BuildPipeline(IPlayableObject playableObject, IGame fallbackGame)
{
IList<string> mods = Array.Empty<string>();
if (playableObject is IMod mod)
Expand All @@ -97,7 +97,9 @@ private static VerifyFocPipeline BuildPipeline(IPlayableObject playableObject, I
playableObject.Game.Directory.FullName,
fallbackGame.Directory.FullName);

return new VerifyFocPipeline(gameLocations, VerificationSettings.Default, _services);
var repo = _services.GetRequiredService<IGameRepositoryFactory>().Create(GameEngineType.Foc, gameLocations);

return new VerifyGamePipeline(repo, VerificationSettings.Default, _services);
}

private static IServiceProvider CreateAppServices()
Expand Down
4 changes: 4 additions & 0 deletions src/ModVerify/GameVerificationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public sealed class GameVerificationException(IEnumerable<GameVerificationStep>
private readonly string? _error = null;
private readonly IEnumerable<IStep> _failedSteps = failedSteps ?? throw new ArgumentNullException(nameof(failedSteps));

public GameVerificationException(GameVerificationStep step) : this([step])

Check warning on line 14 in src/ModVerify/GameVerificationException.cs

View workflow job for this annotation

GitHub Actions / test / Build & Test (windows-latest)

Missing XML comment for publicly visible type or member 'GameVerificationException.GameVerificationException(GameVerificationStep)'

Check warning on line 14 in src/ModVerify/GameVerificationException.cs

View workflow job for this annotation

GitHub Actions / Pack

Missing XML comment for publicly visible type or member 'GameVerificationException.GameVerificationException(GameVerificationStep)'

Check warning on line 14 in src/ModVerify/GameVerificationException.cs

View workflow job for this annotation

GitHub Actions / Pack

Missing XML comment for publicly visible type or member 'GameVerificationException.GameVerificationException(GameVerificationStep)'
{
}

/// <inheritdoc/>
public override string Message => Error;

Expand Down
4 changes: 4 additions & 0 deletions src/ModVerify/ModVerify.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Required" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 13 additions & 3 deletions src/ModVerify/Steps/GameVerificationStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

namespace AET.ModVerify.Steps;

public abstract class GameVerificationStep(CreateGameDatabaseStep createDatabaseStep, IGameRepository repository, IServiceProvider serviceProvider)
public abstract class GameVerificationStep(
CreateGameDatabaseStep createDatabaseStep,
IGameRepository repository,
VerificationSettings settings,
IServiceProvider serviceProvider)
: PipelineStep(serviceProvider)
{
protected readonly IFileSystem FileSystem = serviceProvider.GetRequiredService<IFileSystem>();
Expand All @@ -22,6 +26,8 @@ public abstract class GameVerificationStep(CreateGameDatabaseStep createDatabase

public IReadOnlyCollection<VerificationError> VerifyErrors => _verifyErrors;

protected VerificationSettings Settings { get; } = settings;

protected GameDatabase Database { get; private set; } = null!;

protected IGameRepository Repository => repository;
Expand All @@ -34,14 +40,16 @@ protected sealed override void RunCore(CancellationToken token)
{
createDatabaseStep.Wait();
Database = createDatabaseStep.GameDatabase;


Logger?.LogInformation($"Running verifier '{Name}'...");
try
{
_errorLog = CreateVerificationLogFile();
RunVerification(token);
}
finally
{
Logger?.LogInformation($"Finished verifier '{Name}'");
_errorLog.Dispose();
_errorLog = null!;
}
Expand All @@ -57,9 +65,11 @@ protected void AddError(VerificationError error)
Logger?.LogTrace($"Error suppressed: '{error}'");
return;
}

_verifyErrors.Add(error);
_errorLog.WriteLine(error.Message);

if (Settings.ThrowBehavior == VerifyThrowBehavior.FailFast)
throw new GameVerificationException(this);
}

protected virtual bool OnError(VerificationError error)
Expand Down
8 changes: 6 additions & 2 deletions src/ModVerify/Steps/VerifyReferencedModelsStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@

namespace AET.ModVerify.Steps;

internal sealed class VerifyReferencedModelsStep(CreateGameDatabaseStep createDatabaseStep, IGameRepository repository, IServiceProvider serviceProvider)
: GameVerificationStep(createDatabaseStep, repository, serviceProvider)
internal sealed class VerifyReferencedModelsStep(
CreateGameDatabaseStep createDatabaseStep,
IGameRepository repository,
VerificationSettings settings,
IServiceProvider serviceProvider)
: GameVerificationStep(createDatabaseStep, repository, settings, serviceProvider)
{
public const string ModelNotFound = "ALO00";
public const string ModelBroken = "ALO01";
Expand Down
11 changes: 11 additions & 0 deletions src/ModVerify/VerificationSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace AET.ModVerify;

public record VerificationSettings
{
public static readonly VerificationSettings Default = new()
{
ThrowBehavior = VerifyThrowBehavior.None
};

public VerifyThrowBehavior ThrowBehavior { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,26 @@

namespace AET.ModVerify;


public record VerificationSettings
{
public static readonly VerificationSettings Default = new();

public bool ThrowOnError { get; init; }
}


public class VerifyFocPipeline : ParallelPipeline
public class VerifyGamePipeline : ParallelPipeline
{
private IList<GameVerificationStep> _verificationSteps = null!;
private readonly GameLocations _gameLocations;
private readonly IGameRepository _repository;
private readonly VerificationSettings _settings;

public VerifyFocPipeline(GameLocations gameLocations, VerificationSettings settings, IServiceProvider serviceProvider)
public VerifyGamePipeline(IGameRepository gameRepository, VerificationSettings settings, IServiceProvider serviceProvider)
: base(serviceProvider, 4, false)
{
_gameLocations = gameLocations;
_repository = gameRepository;
_settings = settings;
}

protected override Task<IList<IStep>> BuildSteps()
{
var repository = new FocGameRepository(_gameLocations, ServiceProvider);
var buildIndexStep = new CreateGameDatabaseStep(_repository, ServiceProvider);

var buildIndexStep = new CreateGameDatabaseStep(repository, ServiceProvider);
_verificationSteps = new List<GameVerificationStep>
{
new VerifyReferencedModelsStep(buildIndexStep, repository, ServiceProvider),
new VerifyReferencedModelsStep(buildIndexStep, _repository, _settings, ServiceProvider),
};

var allSteps = new List<IStep>
Expand Down Expand Up @@ -71,7 +61,7 @@ public override async Task RunAsync(CancellationToken token = default)
}
}

if (_settings.ThrowOnError && failedSteps.Count > 0)
if (_settings.ThrowBehavior == VerifyThrowBehavior.FinalThrow && failedSteps.Count > 0)
throw new GameVerificationException(stepsWithVerificationErrors);
}
finally
Expand Down
8 changes: 8 additions & 0 deletions src/ModVerify/VerifyThrowBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace AET.ModVerify;

public enum VerifyThrowBehavior
{
None,
FinalThrow,
FailFast
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class FocGameRepository : IGameRepository

private readonly IVirtualMegArchive? _masterMegArchive;

public GameEngineType EngineType => GameEngineType.Foc;

public IRepository EffectsRepository { get; }

public FocGameRepository(GameLocations gameLocations, IServiceProvider serviceProvider)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace PG.StarWarsGame.Engine.FileSystem;

internal sealed class GameRepositoryFactory(IServiceProvider serviceProvider) : IGameRepositoryFactory
{
public IGameRepository Create(GameEngineType engineType, GameLocations gameLocations)
{
if (engineType == GameEngineType.Eaw)
throw new NotImplementedException("Empire at War is currently not supported.");
return new FocGameRepository(gameLocations, serviceProvider);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

public interface IGameRepository : IRepository
{
IRepository EffectsRepository { get; }
public GameEngineType EngineType { get; }

bool FileExists(string filePath, string[] extensions, bool megFileOnly = false);
IRepository EffectsRepository { get; }

bool FileExists(string filePath, string[] extensions, bool megFileOnly = false);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace PG.StarWarsGame.Engine.FileSystem;

public interface IGameRepositoryFactory
{
IGameRepository Create(GameEngineType engineType, GameLocations gameLocations);
}
2 changes: 2 additions & 0 deletions src/PetroglyphTools/PG.StarWarsGame.Engine/GameDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace PG.StarWarsGame.Engine;

public class GameDatabase
{
public required GameEngineType EngineType { get; init; }

public required GameConstants GameConstants { get; init; }

public required IList<GameObject> GameObjects { get; init; }
Expand Down
16 changes: 16 additions & 0 deletions src/PetroglyphTools/PG.StarWarsGame.Engine/GameEngineType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace PG.StarWarsGame.Engine;

/// <summary>
/// The type of engine can be either "Empire at War" of "Forces of Corruption"
/// </summary>
public enum GameEngineType
{
/// <summary>
/// Empire at War
/// </summary>
Eaw = 0,
/// <summary>
/// Forces of Corruption
/// </summary>
Foc = 1
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using PG.StarWarsGame.Engine.FileSystem;
using PG.StarWarsGame.Engine.Language;
using PG.StarWarsGame.Engine.Xml;

Expand All @@ -8,6 +9,7 @@ public static class PetroglyphEngineServiceContribution
{
public static void ContributeServices(IServiceCollection serviceCollection)
{
serviceCollection.AddSingleton<IGameRepositoryFactory>(sp => new GameRepositoryFactory(sp));
serviceCollection.AddSingleton<IGameLanguageManager>(sp => new GameLanguageManager(sp));
serviceCollection.AddSingleton<IPetroglyphXmlFileParserFactory>(sp => new PetroglyphXmlFileParserFactory(sp));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ protected override async Task RunCoreAsync(CancellationToken token)

GameDatabase = new GameDatabase
{
EngineType = repository.EngineType,
GameConstants = _parseGameConstants.Database,
GameObjects = _parseGameObjects.Database
};
Expand Down
Loading

0 comments on commit 38c6035

Please sign in to comment.