Skip to content

Commit

Permalink
feat: Prepare AOT support
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn committed Feb 19, 2025
1 parent 4a6679a commit 1fa0251
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
run: |
git config --global user.email "[email protected]"
git config --global user.name "Andre Hofmeister"
echo "${{ github.WORKSPACE }}/src/Accelerate/bin/${{ env.CONFIGURATION }}/net6.0/" >> $GITHUB_PATH
echo "${{ github.WORKSPACE }}/src/Accelerate/bin/${{ env.CONFIGURATION }}/net8.0/" >> $GITHUB_PATH
- name: Test Workflow
run: |
workflow_git_dir="HofmeisterAn/GitHub/_git/testcontainers-dotnet-docker-compose/"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ After initializing a new campaign using the command `dotnet accelerate init --na
## Copyright

Copyright (c) 2024 Andre Hofmeister and other authors.
Copyright (c) 2025 Andre Hofmeister and other authors.
14 changes: 9 additions & 5 deletions src/Accelerate/Accelerate.csproj
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<PackAsTool>true</PackAsTool>
<PublishAot>false</PublishAot>
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
<ToolCommandName>dotnet-accelerate</ToolCommandName>
</PropertyGroup>
<PropertyGroup>
<Copyright>Copyright (c) 2024 Andre Hofmeister and other authors</Copyright>
<Copyright>Copyright (c) 2025 Andre Hofmeister and other authors</Copyright>
<Authors>Andre Hofmeister and contributors</Authors>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/HofmeisterAn/accelerate</RepositoryUrl>
</PropertyGroup>
<ItemGroup>
<!-- It looks like this change https://github.com/Tyrrrz/CliWrap/issues/261 breaks our
GitHub Actions workflow. We need to address this before bumping the version. -->
<PackageReference Include="CliWrap" Version="3.6.4"/>
<PackageReference Include="CommandLineParser" Version="2.9.1"/>
<PackageReference Include="Markdig" Version="0.34.0"/>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1"/>
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0"/>
<PackageReference Include="Markdig" Version="0.40.0"/>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1"/>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1"/>
</ItemGroup>
<ItemGroup>
<None Include="../../LICENSE" Pack="true" PackagePath=""/>
Expand Down
7 changes: 4 additions & 3 deletions src/Accelerate/Campaign.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public async Task CloneAsync(CancellationToken ct = default)
throw new AccelerateException(AccelerateErrorCode.GitCommandExecutionFailed);
}

var visualStudioCodeWorkspaceJson = JsonSerializer.Serialize(new VisualStudioCodeWorkspace(this, _repositories));
var visualStudioCodeWorkspace = new VisualStudioCodeWorkspace(this, _repositories);
var visualStudioCodeWorkspaceJson = JsonSerializer.Serialize(visualStudioCodeWorkspace, SourceGenerationContext.Default.VisualStudioCodeWorkspace);
await File.WriteAllTextAsync(VisualStudioCodeWorkspaceFileName, visualStudioCodeWorkspaceJson, ct);
}

Expand Down Expand Up @@ -198,7 +199,7 @@ public async Task ForeachAsync(IEnumerable<string> command, CancellationToken ct
}
}

private sealed class VisualStudioCodeWorkspace
public sealed class VisualStudioCodeWorkspace
{
public VisualStudioCodeWorkspace(Campaign campaign, IEnumerable<Repository> repositories)
{
Expand All @@ -209,7 +210,7 @@ public VisualStudioCodeWorkspace(Campaign campaign, IEnumerable<Repository> repo
public IReadOnlyList<VisualStudioCodeFolder> Folders { get; }
}

private sealed class VisualStudioCodeFolder
public sealed class VisualStudioCodeFolder
{
public VisualStudioCodeFolder(string name, string path)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Accelerate/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public AccelerateHostBuilder(params string[] args)
{
ConfigureAppConfiguration((_, configurationBuilder) =>
{
configurationBuilder.SetBasePath(Path.GetDirectoryName(GetType().Assembly.Location));
configurationBuilder.SetBasePath(AppContext.BaseDirectory);
})
.ConfigureServices((hostBuilder, serviceCollection) =>
{
Expand Down
44 changes: 37 additions & 7 deletions src/Accelerate/Repositories/AzureDevOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,55 @@ public async Task<bool> CloneAsync(Campaign campaign, AzureDevOps repository, Ca
var workDir = Path.Combine(campaign.WorkingDirectoryPath, repository.WorkingDirectoryPath);
var args = new[] { "clone", repository.Url.ToString(), "." };
_ = Directory.CreateDirectory(workDir);
var commandResult = await Cli.Wrap(GitCli).WithWorkingDirectory(workDir).WithArguments(args).WithValidation(CommandResultValidation.None).ExecuteBufferedAsync(ct);

var commandResult = await Cli.Wrap(GitCli)
.WithWorkingDirectory(workDir)
.WithArguments(args)
.WithValidation(CommandResultValidation.None)
.ExecuteBufferedAsync(ct);

return LogAndValidate(campaign, repository, commandResult, 0, 128);
}

public async Task<bool> CheckoutAsync(Campaign campaign, AzureDevOps repository, CancellationToken ct = default)
{
var workDir = Path.Combine(campaign.WorkingDirectoryPath, repository.WorkingDirectoryPath);
var args = new[] { "checkout", "-b", campaign.Name, "--track" };
var commandResult = await Cli.Wrap(GitCli).WithWorkingDirectory(workDir).WithArguments(args).WithValidation(CommandResultValidation.None).ExecuteBufferedAsync(ct);

var commandResult = await Cli.Wrap(GitCli)
.WithWorkingDirectory(workDir)
.WithArguments(args)
.WithValidation(CommandResultValidation.None)
.ExecuteBufferedAsync(ct);

return LogAndValidate(campaign, repository, commandResult, 0);
}

public async Task<bool> CommitAsync(Campaign campaign, AzureDevOps repository, string message, CancellationToken ct = default)
{
var workDir = Path.Combine(campaign.WorkingDirectoryPath, repository.WorkingDirectoryPath);
var args = new[] { "commit", "--all", "--message", message };
var commandResult = await Cli.Wrap(GitCli).WithWorkingDirectory(workDir).WithArguments(args).WithValidation(CommandResultValidation.None).ExecuteBufferedAsync(ct);

var commandResult = await Cli.Wrap(GitCli)
.WithWorkingDirectory(workDir)
.WithArguments(args)
.WithValidation(CommandResultValidation.None)
.ExecuteBufferedAsync(ct);

return LogAndValidate(campaign, repository, commandResult, 0);
}

public async Task<bool> PushAsync(Campaign campaign, AzureDevOps repository, CancellationToken ct = default)
{
var workDir = Path.Combine(campaign.WorkingDirectoryPath, repository.WorkingDirectoryPath);
var args = new[] { "push", "--set-upstream", "origin", campaign.Name };
var commandResult = await Cli.Wrap(GitCli).WithWorkingDirectory(workDir).WithArguments(args).WithValidation(CommandResultValidation.None).ExecuteBufferedAsync(ct);

var commandResult = await Cli.Wrap(GitCli)
.WithWorkingDirectory(workDir)
.WithArguments(args)
.WithValidation(CommandResultValidation.None)
.ExecuteBufferedAsync(ct);

return LogAndValidate(campaign, repository, commandResult, 0);
}

Expand Down Expand Up @@ -97,7 +121,7 @@ public async Task<bool> CreatePullRequestsAsync(Campaign campaign, AzureDevOps r

var parameter = Convert.ToBase64String(Encoding.Default.GetBytes(":" + _azureDevOpsSettings.Value.AuthToken));

var jsonString = JsonSerializer.Serialize(prRequestBody);
var jsonString = JsonSerializer.Serialize(prRequestBody, SourceGenerationContext.Default.DictionaryStringString);

using var httpClient = new HttpClient();

Expand All @@ -122,11 +146,17 @@ public async Task<bool> ForeachAsync(Campaign campaign, AzureDevOps repository,
{
var workDir = Path.Combine(campaign.WorkingDirectoryPath, repository.WorkingDirectoryPath);
var args = new[] { "-c", string.Join(' ', command) };
var commandResult = await Cli.Wrap(_shellSettings.Value.Shell).WithWorkingDirectory(workDir).WithArguments(args).WithValidation(CommandResultValidation.None).ExecuteBufferedAsync(ct);

var commandResult = await Cli.Wrap(_shellSettings.Value.Shell)
.WithWorkingDirectory(workDir)
.WithArguments(args)
.WithValidation(CommandResultValidation.None)
.ExecuteBufferedAsync(ct);

return LogAndValidate(campaign, repository, commandResult, 0);
}

private bool LogAndValidate(Campaign campaign, AzureDevOps repository, BufferedCommandResult result, params int[] successExitCodes)
private bool LogAndValidate(Campaign _, AzureDevOps repository, BufferedCommandResult result, params int[] successExitCodes)
{
if (_logger.IsEnabled(LogLevel.Debug))
{
Expand Down
4 changes: 2 additions & 2 deletions src/Accelerate/Repositories/RepositoryCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public RepositoryCollection(string jsonString)
switch (typeName)
{
case "Accelerate.Repositories.AzureDevOps":
repository = repoProperty.Deserialize<AzureDevOps>();
repository = repoProperty.Deserialize<AzureDevOps>(SourceGenerationContext.Default.AzureDevOps);
break;
case "Accelerate.Repositories.GitHub":
repository = repoProperty.Deserialize<GitHub>();
repository = repoProperty.Deserialize<GitHub>(SourceGenerationContext.Default.GitHub);
break;
default:
throw new AccelerateException(AccelerateErrorCode.Undefined);
Expand Down
8 changes: 8 additions & 0 deletions src/Accelerate/SourceGenerationContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Accelerate;

[JsonSerializable(typeof(Campaign.VisualStudioCodeWorkspace))]
[JsonSerializable(typeof(Campaign.VisualStudioCodeFolder))]
[JsonSerializable(typeof(AzureDevOps))]
[JsonSerializable(typeof(GitHub))]
[JsonSerializable(typeof(Dictionary<string, string>))]
internal partial class SourceGenerationContext : JsonSerializerContext;
8 changes: 4 additions & 4 deletions tests/Accelerate.Tests/Accelerate.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0"/>
<PackageReference Include="xunit" Version="2.5.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0"/>
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2"/>
<PackageReference Include="xunit" Version="2.9.3"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../src/Accelerate/Accelerate.csproj"/>
Expand Down
1 change: 0 additions & 1 deletion tests/Accelerate.Tests/RepositoryCollectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ namespace Accelerate.Tests;
public sealed class RepositoryCollectionTest
{
[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData("{}")]
public void Constructor_WithInvalidJson_ThrowsAccelerateException(string jsonString)
Expand Down
12 changes: 6 additions & 6 deletions tests/Accelerate.Tests/Workflow/WorkflowTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ namespace Accelerate.Tests.Workflow;

public sealed class WorkflowTest : IGitCommand<AzureDevOps>, IShellCommand<AzureDevOps>, IDisposable
{
private readonly IList<string> _actualCmds = new List<string>();
private readonly List<string> _actualCmds = new List<string>();

private readonly CampaignId _campaignId = new CampaignId();

[Fact]
public void Should_Configure_Workflow_Successfully()
{
// Given
var inMemorySettings = new Dictionary<string, string>();
inMemorySettings.Add(string.Join(':', nameof(AzureDevOpsSettings), nameof(AzureDevOpsSettings.AuthToken)), _campaignId.Id);
inMemorySettings.Add(string.Join(':', nameof(ShellSettings), nameof(ShellSettings.Shell)), _campaignId.Id);
var inMemorySettings = new List<KeyValuePair<string, string?>>();
inMemorySettings.Add(new KeyValuePair<string, string?>(string.Join(':', nameof(AzureDevOpsSettings), nameof(AzureDevOpsSettings.AuthToken)), _campaignId.Id));
inMemorySettings.Add(new KeyValuePair<string, string?>(string.Join(':', nameof(ShellSettings), nameof(ShellSettings.Shell)), _campaignId.Id));

// When
var cmd = new Cmd.Init(_campaignId, this, this)
Expand Down Expand Up @@ -45,10 +45,10 @@ public async Task Should_Execute_Workflow_Successfully()
using var cmd = cmds[step];

await cmd.InitializeAsync()
.ConfigureAwait(false);
.ConfigureAwait(true);

await cmd.DisposeAsync()
.ConfigureAwait(false);
.ConfigureAwait(true);
}

// Then
Expand Down

0 comments on commit 1fa0251

Please sign in to comment.