Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to .NET 9 #121

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/.github.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<IsPackable>False</IsPackable>
</PropertyGroup>
<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions .github/actions/bootstrap/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ runs:
run: |
git fetch --prune --unshallow --tags
git tag --list
- uses: actions/setup-dotnet@v4
with:
global-json-file: global.json

- id: dotnet
shell: bash
Expand Down
55 changes: 0 additions & 55 deletions Dockerfile

This file was deleted.

6 changes: 2 additions & 4 deletions build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@
{
var source = "src/docs-builder/docs-builder.csproj";
await $"""
dotnet publish {source} -c Release -o .artifacts/publish \
--self-contained true /p:PublishTrimmed=true /p:PublishSingleFile=false /p:PublishAot=true
dotnet publish {source}
""";

var generatorSource = "src/docs-generator/docs-generator.csproj";
await $"""
dotnet publish {generatorSource} -c Release -o .artifacts/publish \
--self-contained true /p:PublishTrimmed=true /p:PublishSingleFile=false /p:PublishAot=true
dotnet publish {generatorSource}
""";
});

Expand Down
2 changes: 1 addition & 1 deletion build/build.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<OutputType>Exe</OutputType>
<NoWarn>$(NoWarn);NU1701</NoWarn>
<IsPackable>false</IsPackable>
Expand Down
3 changes: 1 addition & 2 deletions docs-builder.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "root", "root", "{94AC66E5-38C3-4625-92D3-08990FD5F429}"
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
Dockerfile = Dockerfile
README.md = README.md
run.sh = run.sh
build.bat = build.bat
build.sh = build.sh
dotnet-tools.json = dotnet-tools.json
global.json = global.json
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{BE6011CC-1200-4957-B01F-FCCA10C5CF5A}"
Expand Down
2 changes: 1 addition & 1 deletion docs/docs.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<IsPackable>False</IsPackable>
</PropertyGroup>

Expand Down
12 changes: 5 additions & 7 deletions docs/source/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ This repository is host to:
* *`docs-builder`* command line tool to generate single doc-sets (13mb native code, no dependencies)
* *`docs-assembler`* command line tool to assemble all the doc sets. (IN PROGRESS)
* `elastic/docs-builder@main` Github Action to build and validate a repositories documentation
* *`docs-generator`* command line tool to deterministically generate a docset and incremental updates to generated content

## Command line interface

```
```bash
$ docs-builder --help
Usage: [command] [options...] [-h|--help] [--version]

Expand Down Expand Up @@ -130,16 +131,13 @@ https://github.com/elastic/{your-repository}/settings/pages
## Run without docker

If you have dotnet 8 installed you can use its CLI to publish a self-contained `docs-builder` native code
binary. (On my M2 Pro mac the binary is currently 13mb)
binary. (On my M2 Pro mac the binary is currently 16mb)

```bash
$ dotnet publish "src/docs-builder/docs-builder.csproj" -c Release -o .artifacts/publish \
--self-contained true /p:PublishTrimmed=true /p:PublishSingleFile=false /p:PublishAot=true -a arm64
$ dotnet publish "src/docs-builder/docs-builder.csproj"
```

**Note**: `-a` should be the machines CPU architecture

The resulting binary `./.artifacts/publish/docs-builder` will run on machines without .NET installed
The resulting binary `./.artifacts/publish/docs-builder/release/docs-builder` will run on machines without .NET installed

# Performance

Expand Down
7 changes: 7 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sdk": {
"version": "9.0.100",
"rollForward": "latestFeature",
"allowPrerelease": false
}
}
44 changes: 0 additions & 44 deletions run.sh

This file was deleted.

1 change: 1 addition & 0 deletions src/Elastic.Markdown/DocumentationGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public record GenerationState
{
[JsonPropertyName("last_seen_changes")]
public required DateTimeOffset LastSeenChanges { get; init; }

[JsonPropertyName("invalid_files")]
public required string[] InvalidFiles { get; init; } = [];

Expand Down
4 changes: 2 additions & 2 deletions src/Elastic.Markdown/Elastic.Markdown.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<InvariantGlobalization>true</InvariantGlobalization>
Expand All @@ -16,7 +16,7 @@

<ItemGroup>
<PackageReference Include="DotNet.Glob" Version="3.1.3" />
<PackageReference Include="ini-parser-netstandard" Version="2.5.2" />
<PackageReference Include="SoftCircuits.IniFileParser" Version="2.6.0" />
<PackageReference Include="Markdig" Version="0.37.0"/>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="RazorSlices" Version="0.8.1" />
Expand Down
30 changes: 19 additions & 11 deletions src/Elastic.Markdown/IO/GitConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

using System.IO.Abstractions;
using System.Text.Json.Serialization;
using IniParser;
using IniParser.Model;
using SoftCircuits.IniFileParser;

namespace Elastic.Markdown.IO;

Expand Down Expand Up @@ -42,15 +41,16 @@ public static GitConfiguration Create(IFileSystem fileSystem)
else
branch = "detached/head";

var ini = new FileIniDataParser();
var ini = new IniFile();
using var stream = gitConfig.OpenRead();
using var streamReader = new StreamReader(stream);
var config = ini.ReadData(streamReader);
var remote = BranchTrackingRemote(branch, config);
ini.Load(streamReader);

var remote = BranchTrackingRemote(branch, ini);
if (string.IsNullOrEmpty(remote))
remote = BranchTrackingRemote("main", config);
remote = BranchTrackingRemote("main", ini);
if (string.IsNullOrEmpty(remote))
remote = BranchTrackingRemote("master", config);
remote = BranchTrackingRemote("master", ini);
if (string.IsNullOrEmpty(remote))
remote = Environment.GetEnvironmentVariable("GITHUB_REPOSITORY") ?? "elastic/docs-builder-unknown";

Expand All @@ -61,11 +61,19 @@ public static GitConfiguration Create(IFileSystem fileSystem)
string Read(string path) =>
fileSystem.File.ReadAllText(Git(path).FullName).Trim(Environment.NewLine.ToCharArray());

string BranchTrackingRemote(string b, IniData c)
string BranchTrackingRemote(string b, IniFile c)
{
var remoteName = c[$"branch \"{b}\""]["remote"];
remote = c[$"remote \"{remoteName}\""]["url"];
return remote;
var sections = c.GetSections();
var branchSection = $"branch \"{b}\"";
if (!sections.Contains(branchSection))
return string.Empty;

var remoteName = ini.GetSetting(branchSection, "remote");

var remoteSection = $"remote \"{remoteName}\"";

remote = ini.GetSetting(remoteSection, "url");
return remote ?? string.Empty;
}
}
}
2 changes: 0 additions & 2 deletions src/Elastic.Markdown/IO/LinkReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System.IO.Abstractions;
using System.Text.Json.Serialization;
using IniParser;

namespace Elastic.Markdown.IO;

Expand Down
34 changes: 0 additions & 34 deletions src/docs-builder/Cli/ArgsFilter.cs

This file was deleted.

16 changes: 16 additions & 0 deletions src/docs-builder/ConsoleApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System.Diagnostics.CodeAnalysis;

// this is a temporary workaround for https://github.com/Cysharp/ConsoleAppFramework/issues/154
// it generates code that is not AOT safe, but it's in a code path we don't use.
// therefor I am comfortable running with this band-aid for now

// ReSharper disable once CheckNamespace
namespace ConsoleAppFramework;

[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode", Justification = "Manually verified")]
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL3050:RequiresDynamicCode", Justification = "Manually verified")]
internal static partial class ConsoleApp;
2 changes: 1 addition & 1 deletion src/docs-builder/Http/DocumentationWebHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public DocumentationWebHost(string? path, ILoggerFactory logger, IFileSystem fil
{
Collector = new ConsoleDiagnosticsCollector(logger)
};
builder.Services.AddLiveReload(s =>
builder.Services.AddAotLiveReload(s =>
{
s.FolderToMonitor = context.SourcePath.FullName;
s.ClientFileExtensions = ".md,.yml";
Expand Down
Loading
Loading