Skip to content
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
17 changes: 15 additions & 2 deletions .github/workflows/build-2024.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,21 @@ on:

jobs:
build:

runs-on: ubuntu-latest
name: Build
strategy:
matrix:
kind: ['linux', 'windows', 'macOS']
include:
- kind: linux
os: ubuntu-latest
target: linux-x64
- kind: windows
os: windows-latest
target: win-x64
- kind: macOS
os: macos-latest
target: osx-x64
runs-on: ${{ matrix.os }}

defaults:
run:
Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Publish
on:
release:
types: [published]

jobs:
release:
name: Release
strategy:
matrix:
kind: ['linux', 'windows', 'macOS']
include:
- kind: linux
os: ubuntu-latest
target: linux-x64
- kind: windows
os: windows-latest
target: win-x64
- kind: macOS
os: macos-latest
target: osx-x64
runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x

- name: Build
shell: bash
run: |
# define the tag and name
tag= $(git describe --tags --abbrev=0)

# tag without the v prefix
version= ${tag:1}

release_name="Advent-of-Code-$tag-${{ matrix.kind }}"

# build the 2024
dotnet publish ./2024/Advent/Advent.csproj -c Release -r ${{ matrix.target }} -p:Version=$version -p:DebugType=None -p:DebugSymbols=false -o "$release_name"

# Pack files
if [ "${{ matrix.target }}" == "win-x64" ]; then
7z a -tzip "${release_name}.zip" "./${release_name}/*"
else
tar czvf "${release_name}.tar.gz" "$release_name"
fi

# Delete output directory
rm -r "$release_name"

- name: Publish
uses: softprops/action-gh-release@v1
with:
files: "Advent-of-Code-*"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 2 additions & 3 deletions 2024/Advent.Tests/Commands/Day15CommandTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Advent.Common.Commands;
using Advent.Common.Settings;
using Advent.UseCases.Day15;
using Spectre.Console.Cli;

namespace Advent.Tests.Commands;
Expand All @@ -27,7 +26,7 @@ public async Task Day15Command_Solves_Part1_Correctly()
var command = new Day15Command(mockReader, console);
var result = await command.ExecuteAsync(
new CommandContext(_arguments, _remaining, "day15", null),
new Day15Settings { PartChoice = new(Part.Part1), Live = false, }
new LiveSettings { PartChoice = new(Part.Part1), Live = false, }
);
result.Should().Be(0);
console.Output.Should().Contain("Day 15 Part 1");
Expand All @@ -45,7 +44,7 @@ public async Task Day15Command_Solves_Part2_Correctly()
var command = new Day15Command(mockReader, console);
var result = await command.ExecuteAsync(
new CommandContext(_arguments, _remaining, "day15", null),
new Day15Settings { PartChoice = new(Part.Part2), Live = false, }
new LiveSettings { PartChoice = new(Part.Part2), Live = false, }
);
result.Should().Be(0);
console.Output.Should().Contain("Day 15 Part 2");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
using Advent.UseCases;

namespace Advent.Tests.UseCases;
namespace Advent.Tests.Common;

public class FileReaderTest
{
[Fact]
public async Task ReadInputAsync_ShouldReturnFileContent()
{
// Arrange
var filename = Path.GetRandomFileName();
var filePath = Path.Combine(Path.GetTempPath(), filename);
var expectedContent = "Hello, World!";
await File.WriteAllTextAsync(filePath, expectedContent);
var fileReader = new FileReader();

// Act
var result = await fileReader.ReadInputAsync(filePath);
var result = await fileReader.ReadInputAsync("day1");

// Assert
Assert.Equal(expectedContent, result);

// Cleanup
File.Delete(filePath);
result.Should().StartWith("99006 28305");
}

[Fact]
Expand Down
12 changes: 1 addition & 11 deletions 2024/Advent.Tests/IntegrationTests/CommandAppTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using Advent.UseCases;
using Microsoft.Extensions.DependencyInjection;
using Spectre.Console.Cli;
using Spectre.Console.Cli.Extensions.DependencyInjection;

namespace Advent.Tests.IntegrationTests;

public class CommandAppTests : IClassFixture<TestFixture>
public class CommandAppTests
{
private readonly TestConsole _console = new();
private readonly FileReader _fileReader = new();
Expand Down Expand Up @@ -1185,12 +1184,3 @@ public async Task Day25Part1_IntegrationTest_Success()
}
#endregion
}

public class TestFixture
{
public TestFixture()
{
// One-time setup goes here
Directory.SetCurrentDirectory("../../../");
}
}
6 changes: 5 additions & 1 deletion 2024/Advent/Advent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
</PropertyGroup>

<ItemGroup>
Expand All @@ -22,5 +24,7 @@
<InternalsVisibleTo Include="Advent.Tests" />
</ItemGroup>


<ItemGroup>
<EmbeddedResource Include="../input/*.txt" />
</ItemGroup>
</Project>
4 changes: 1 addition & 3 deletions 2024/Advent/Commands/Day10Command.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Advent.Common;
using Advent.Common.Commands;
using Advent.Common.Settings;
using Advent.UseCases.Day10;
using Advent.UseCases.Day6;
using Spectre.Console;
Expand All @@ -13,7 +11,7 @@ public class Day10Command(IFileReader reader, IAnsiConsole console)
{
public override async Task<int> ExecuteAsync(CommandContext context, AdventSettings settings)
{
var input = await _reader.ReadInputAsync("../input/day10input.txt");
var input = await _reader.ReadInputAsync(context.Name);
var data = Day6Parser.Parse(input);

var choice = settings.PartChoice ?? PromptForPartChoice();
Expand Down
4 changes: 1 addition & 3 deletions 2024/Advent/Commands/Day11Command.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Advent.Common;
using Advent.Common.Commands;
using Advent.Common.Settings;
using Advent.UseCases.Day11;
using Spectre.Console;
using Spectre.Console.Cli;
Expand All @@ -12,7 +10,7 @@ public class Day11Command(IFileReader reader, IAnsiConsole console)
{
public override async Task<int> ExecuteAsync(CommandContext context, AdventSettings settings)
{
var input = await _reader.ReadInputAsync("../input/day11input.txt");
var input = await _reader.ReadInputAsync(context.Name);
var data = Day11Parser.Parse(input);

var choice = settings.PartChoice ?? PromptForPartChoice();
Expand Down
4 changes: 1 addition & 3 deletions 2024/Advent/Commands/Day12Command.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Advent.Common;
using Advent.Common.Commands;
using Advent.Common.Settings;
using Advent.UseCases.Day12;
using Advent.UseCases.Day6;
using Spectre.Console;
Expand All @@ -13,7 +11,7 @@ public class Day12Command(IFileReader reader, IAnsiConsole console)
{
public override async Task<int> ExecuteAsync(CommandContext context, AdventSettings settings)
{
var input = await _reader.ReadInputAsync("../input/day12input.txt");
var input = await _reader.ReadInputAsync(context.Name);
var data = Day6Parser.Parse(input);

var choice = settings.PartChoice ?? PromptForPartChoice();
Expand Down
4 changes: 1 addition & 3 deletions 2024/Advent/Commands/Day13Command.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Advent.Common;
using Advent.Common.Commands;
using Advent.Common.Settings;
using Advent.UseCases.Day13;
using Spectre.Console;
using Spectre.Console.Cli;
Expand All @@ -12,7 +10,7 @@ public class Day13Command(IFileReader reader, IAnsiConsole console)
{
public override async Task<int> ExecuteAsync(CommandContext context, AdventSettings settings)
{
var input = await _reader.ReadInputAsync("../input/day13input.txt");
var input = await _reader.ReadInputAsync(context.Name);
var data = Day13Parser.Parse(input);

var choice = settings.PartChoice ?? PromptForPartChoice();
Expand Down
3 changes: 1 addition & 2 deletions 2024/Advent/Commands/Day14Command.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Advent.Common;
using Advent.Common.Commands;
using Advent.UseCases.Day14;
using Spectre.Console;
Expand All @@ -11,7 +10,7 @@ public class Day14Command(IFileReader reader, IAnsiConsole console)
{
public override async Task<int> ExecuteAsync(CommandContext context, Day14Settings settings)
{
var input = await _reader.ReadInputAsync("../input/day14input.txt");
var input = await _reader.ReadInputAsync(context.Name);
var data = Day14Parser.Parse(input);

var choice = settings.PartChoice ?? PromptForPartChoice();
Expand Down
8 changes: 3 additions & 5 deletions 2024/Advent/Commands/Day15Command.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
using Advent.Common;
using Advent.Common.Commands;
using Advent.Common.Settings;
using Advent.UseCases.Day15;
using Spectre.Console;
using Spectre.Console.Cli;

namespace Advent.Commands;

public class Day15Command(IFileReader reader, IAnsiConsole console)
: AdventCommand<Day15Settings>(reader, console)
: AdventCommand<LiveSettings>(reader, console)
{
public override async Task<int> ExecuteAsync(CommandContext context, Day15Settings settings)
public override async Task<int> ExecuteAsync(CommandContext context, LiveSettings settings)
{
var input = await _reader.ReadInputAsync("../input/day15input.txt");
var input = await _reader.ReadInputAsync(context.Name);
var choice = settings.PartChoice ?? PromptForPartChoice();

Day15Data data;
Expand Down
4 changes: 1 addition & 3 deletions 2024/Advent/Commands/Day16Command.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Advent.Common;
using Advent.Common.Commands;
using Advent.Common.Settings;
using Advent.UseCases.Day16;
using Advent.UseCases.Day6;
using Spectre.Console;
Expand All @@ -13,7 +11,7 @@ public class Day16Command(IFileReader reader, IAnsiConsole console)
{
public override async Task<int> ExecuteAsync(CommandContext context, AdventSettings settings)
{
var input = await _reader.ReadInputAsync("../input/day16input.txt");
var input = await _reader.ReadInputAsync(context.Name);
var data = Day6Parser.Parse(input);

var choice = settings.PartChoice ?? PromptForPartChoice();
Expand Down
4 changes: 1 addition & 3 deletions 2024/Advent/Commands/Day17Command.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Advent.Common;
using Advent.Common.Commands;
using Advent.Common.Settings;
using Advent.UseCases.Day17;
using Spectre.Console;
using Spectre.Console.Cli;
Expand All @@ -12,7 +10,7 @@ public class Day17Command(IFileReader reader, IAnsiConsole console)
{
public override async Task<int> ExecuteAsync(CommandContext context, AdventSettings settings)
{
var input = await _reader.ReadInputAsync("../input/day17input.txt");
var input = await _reader.ReadInputAsync(context.Name);
var data = Day17Parser.Parse(input);

var choice = settings.PartChoice ?? PromptForPartChoice();
Expand Down
3 changes: 1 addition & 2 deletions 2024/Advent/Commands/Day18Command.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Advent.Common;
using Advent.Common.Commands;
using Advent.UseCases.Day18;
using Spectre.Console;
Expand All @@ -11,7 +10,7 @@ public class Day18Command(IFileReader reader, IAnsiConsole console)
{
public override async Task<int> ExecuteAsync(CommandContext context, Day18Settings settings)
{
var input = await _reader.ReadInputAsync("../input/day18input.txt");
var input = await _reader.ReadInputAsync(context.Name);
var data = Day18Parser.Parse(input);

var choice = settings.PartChoice ?? PromptForPartChoice();
Expand Down
4 changes: 1 addition & 3 deletions 2024/Advent/Commands/Day19Command.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Advent.Common;
using Advent.Common.Commands;
using Advent.Common.Settings;
using Advent.UseCases.Day19;
using Spectre.Console;
using Spectre.Console.Cli;
Expand All @@ -12,7 +10,7 @@ public class Day19Command(IFileReader reader, IAnsiConsole console)
{
public override async Task<int> ExecuteAsync(CommandContext context, AdventSettings settings)
{
var input = await _reader.ReadInputAsync("../input/day19input.txt");
var input = await _reader.ReadInputAsync(context.Name);
var (buildingBlocks, targets) = Day19Parser.Parse(input);

var choice = settings.PartChoice ?? PromptForPartChoice();
Expand Down
5 changes: 2 additions & 3 deletions 2024/Advent/Commands/Day1Command.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Advent.Common;
using System.Reflection;
using Advent.Common.Commands;
using Advent.Common.Settings;
using Advent.UseCases.Day1;
using Spectre.Console;
using Spectre.Console.Cli;
Expand All @@ -12,7 +11,7 @@ public class Day1Command(IFileReader reader, IAnsiConsole console)
{
public override async Task<int> ExecuteAsync(CommandContext context, AdventSettings settings)
{
var input = await _reader.ReadInputAsync("../input/day1input.txt");
var input = await _reader.ReadInputAsync(context.Name);
var data = Day1Parser.Parse(input);

var choice = settings.PartChoice ?? PromptForPartChoice();
Expand Down
3 changes: 1 addition & 2 deletions 2024/Advent/Commands/Day20Command.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Advent.Common;
using Advent.Common.Commands;
using Advent.UseCases.Day20;
using Advent.UseCases.Day6;
Expand All @@ -12,7 +11,7 @@ public class Day20Command(IFileReader reader, IAnsiConsole console)
{
public override async Task<int> ExecuteAsync(CommandContext context, Day20Settings settings)
{
var input = await _reader.ReadInputAsync("../input/day20input.txt");
var input = await _reader.ReadInputAsync(context.Name);
var data = Day6Parser.Parse(input);

var choice = settings.PartChoice ?? PromptForPartChoice();
Expand Down
4 changes: 1 addition & 3 deletions 2024/Advent/Commands/Day21Command.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Advent.Common;
using Advent.Common.Commands;
using Advent.Common.Settings;
using Advent.UseCases.Day21;
using Spectre.Console;
using Spectre.Console.Cli;
Expand All @@ -12,7 +10,7 @@ public class Day21Command(IFileReader reader, IAnsiConsole console)
{
public override async Task<int> ExecuteAsync(CommandContext context, AdventSettings settings)
{
var input = await _reader.ReadInputAsync("../input/day21input.txt");
var input = await _reader.ReadInputAsync(context.Name);
var data = Day21Parser.Parse(input);

var choice = settings.PartChoice ?? PromptForPartChoice();
Expand Down
Loading
Loading