Skip to content

Commit

Permalink
Use preprocessor defines for building
Browse files Browse the repository at this point in the history
Use E5RENEWER_AOT as a flag in code.

Adjust CI based on this change.

Merge test ci into build.
  • Loading branch information
arenekosreal committed Feb 12, 2025
1 parent c04386c commit e5f9804
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

jobs:
build:
name: "Build packages"
test-and-publish:
name: "Test app and publish packages"
strategy:
matrix:
os:
Expand All @@ -27,17 +32,30 @@ jobs:
exclude:
- aot: "true"
self-contained: "false"

runs-on: ${{ matrix.os }}
steps:
- name: "Fix long path on windows"
if: matrix.os == 'windows-latest'
run: "git config --system core.longpaths true"

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

- name: "Setup .NET"
uses: "actions/setup-dotnet@v4"
with:
dotnet-version: ${{ matrix.dotnet }}

- name: Check whitespace
run: dotnet format whitespace --verify-no-changes

- name: Check style
run: dotnet format style --verify-no-changes

- name: Run mstest
run: dotnet test --collect "XPlat Code Coverage"

- name: "Get build environment info"
id: build-env-info
shell: bash
Expand All @@ -54,11 +72,21 @@ jobs:
echo "rid=$rid" >> "$GITHUB_OUTPUT"
echo "suffix=$suffix" >> "$GITHUB_OUTPUT"
- name: "Publish binary"
run: "dotnet publish E5Renewer/E5Renewer.csproj --runtime ${{ steps.build-env-info.outputs.rid }} ${{ matrix.aot == 'false' && '-p:PublishAot=false' || '' }} --sc ${{ matrix.self-contained }}"
run: |
dotnet publish E5Renewer/E5Renewer.csproj \
--runtime ${{ steps.build-env-info.outputs.rid }} \
-p:E5RenewerAot=${{ matrix.aot }} \
--sc ${{ matrix.self-contained }}"
- name: "Create archive"
run: "7z a E5Renewer-${{ steps.build-env-info.outputs.suffix }}.7z E5Renewer/bin/Release/net${{ matrix.dotnet }}/${{ steps.build-env-info.outputs.rid }}/publish/*"
run: |
7z a E5Renewer-${{ steps.build-env-info.outputs.suffix }}.7z \
E5Renewer/bin/Release/net${{ matrix.dotnet }}/${{ steps.build-env-info.outputs.rid }}/publish/*
- name: "Upload archive"
if: github.ref_type == 'tag'
uses: "actions/upload-artifact@v4"
with:
name: "E5Renewer-${{ steps.build-env-info.outputs.suffix }}"
Expand All @@ -74,6 +102,7 @@ jobs:
steps:
- name: "Download archive"
uses: "actions/download-artifact@v4"

- name: "Create release"
uses: "softprops/action-gh-release@v2"
with:
Expand Down
36 changes: 0 additions & 36 deletions .github/workflows/test.yaml

This file was deleted.

4 changes: 3 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
<Deterministic>true</Deterministic>
</PropertyGroup>

<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">
<PropertyGroup Condition="'$(E5RenewerAot)' == 'true' And $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">
<PublishAot>true</PublishAot>
<IsAotCompatible>true</IsAotCompatible>
<JsonSerializerIsReflectionEnabledByDefault>false</JsonSerializerIsReflectionEnabledByDefault>
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
<DefineConstaints>$(DefineConstaints);E5RENEWER_AOT</DefineConstaints>
</PropertyGroup>

</Project>
3 changes: 3 additions & 0 deletions E5Renewer.Models.Modules/ModuleLoadContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace E5Renewer.Models.Modules;

#if ! E5RENEWER_AOT

/// <summary> AssemblyLoadContext for loading modules.</summary>
public class ModuleLoadContext : AssemblyLoadContext
{
Expand Down Expand Up @@ -38,3 +40,4 @@ protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
}
}

#endif // ! E5RENEWER_AOT
2 changes: 2 additions & 0 deletions E5Renewer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
.GetCustomAttributes<AssemblyContainsModuleAttribute>()
.Select((attribute) => attribute.assembly);

#if ! E5RENEWER_AOT
DirectoryInfo modulesInFilesystemBaseDirectory = new(Path.Combine(AppContext.BaseDirectory, modulesInFilesystemBaseDirectoryName));
if (modulesInFilesystemBaseDirectory.Exists)
{
Expand Down Expand Up @@ -78,6 +79,7 @@
.OfType<Assembly>();
assembliesToLoad = assembliesToLoad.Concat(assembliesInFilesystem);
}
#endif // ! E5RENEWER_AOT

builder.Logging.AddConsole(systemd);

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ A tool to renew e5 subscription by calling msgraph APIs

Run `dotnet publish -c Release` and you can get binary at `E5Renewer/bin/Release/net8.0/publish`

> [!TIP]
> You can pass `-p:E5RenewerAot=true` to create an AoT build.

## Get running statistics

Using `curl` or any tool which can send http request, send request to endpoints like `http://127.0.0.1:5000` or unix socket `/path/to/socket`,
Expand Down

0 comments on commit e5f9804

Please sign in to comment.