Skip to content

Add matrix to pr workflow #425

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

Merged
merged 19 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
28 changes: 12 additions & 16 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ on:

permissions:
contents: read
packages: read
id-token: write
pull-requests: write
deployments: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -19,26 +15,26 @@ env:

jobs:
build:
runs-on: ubuntu-latest
steps:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v4

- name: Bootstrap Action Workspace
id: bootstrap
uses: ./.github/actions/bootstrap

- name: Build
run: ./build.sh
run: dotnet run --project build -c release

- name: Test
run: ./build.sh test
run: dotnet run --project build -c release -- test

- name: Publish AOT
run: ./build.sh publishbinaries

- uses: actions/upload-artifact@v4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what we were using this for?

Copy link
Member Author

@reakaleek reakaleek Mar 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was there in the initial implementation of the preview build, where we would download the built binary.

with:
name: docs-builder-binary
path: .artifacts/publish/docs-builder/release/docs-builder
if-no-files-found: error
retention-days: 1
run: dotnet run --project build -c release -- publishbinaries
1 change: 0 additions & 1 deletion docs-builder.sln
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ Global
{10857974-6CF1-42B5-B793-AAA988BD7348}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{10857974-6CF1-42B5-B793-AAA988BD7348}.Debug|Any CPU.Build.0 = Debug|Any CPU
{10857974-6CF1-42B5-B793-AAA988BD7348}.Release|Any CPU.ActiveCfg = Release|Any CPU
{10857974-6CF1-42B5-B793-AAA988BD7348}.Release|Any CPU.Build.0 = Release|Any CPU
{28350800-B44B-479B-86E2-1D39E321C0B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28350800-B44B-479B-86E2-1D39E321C0B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28350800-B44B-479B-86E2-1D39E321C0B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
16 changes: 16 additions & 0 deletions src/Elastic.Markdown.Refactor/Move.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information

using System.IO.Abstractions;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using Elastic.Markdown.IO;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -64,6 +65,9 @@ private async Task SetupChanges(ChangeSet changeSet, Cancel ctx)
var fullPath = Path.GetFullPath(Path.Combine(sourceDirectory, originalPath));
var relativePath = Path.GetRelativePath(targetDirectory, fullPath);

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
relativePath = relativePath.Replace('\\', '/');

newPath = originalPath.StartsWith("./", OrdinalIgnoreCase) && !relativePath.StartsWith("./", OrdinalIgnoreCase)
? "./" + relativePath
: relativePath;
Expand Down Expand Up @@ -258,6 +262,15 @@ string targetPath
var absolutStyleSource = $"/{relativeToDocsFolder}";
var relativeToDocsFolderTarget = Path.GetRelativePath(documentationSet.SourceDirectory.FullName, targetPath);
var absoluteStyleTarget = $"/{relativeToDocsFolderTarget}";

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
relativeSource = relativeSource.Replace('\\', '/');
relativeSourceWithDotSlash = relativeSourceWithDotSlash.Replace('\\', '/');
absolutStyleSource = absolutStyleSource.Replace('\\', '/');
absoluteStyleTarget = absoluteStyleTarget.Replace('\\', '/');
}

return (
relativeSource,
relativeSourceWithDotSlash,
Expand Down Expand Up @@ -298,6 +311,9 @@ private string ReplaceLinks(
: $"[{match.Groups[1].Value}]({relativeTarget}{anchor})";
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
newLink = newLink.Replace('\\', '/');

var lineNumber = content[..match.Index].Count(c => c == '\n') + 1;
var columnNumber = match.Index - content.LastIndexOf('\n', match.Index);
if (!_linkModifications.ContainsKey(changeSet))
Expand Down
3 changes: 3 additions & 0 deletions src/Elastic.Markdown/IO/MarkdownFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information

using System.IO.Abstractions;
using System.Runtime.InteropServices;
using Elastic.Markdown.Diagnostics;
using Elastic.Markdown.Helpers;
using Elastic.Markdown.IO.Navigation;
Expand Down Expand Up @@ -95,6 +96,8 @@ public string Url
get
{
var relativePath = RelativePathUrl;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
relativePath = relativePath.Replace('\\', '/');
return Path.GetFileName(relativePath) == "index.md"
? $"{UrlPathPrefix}/{relativePath.Remove(relativePath.LastIndexOf("index.md", StringComparison.Ordinal), "index.md".Length)}"
: $"{UrlPathPrefix}/{relativePath.Remove(relativePath.LastIndexOf(SourceFile.Extension, StringComparison.Ordinal), SourceFile.Extension.Length)}";
Expand Down
5 changes: 4 additions & 1 deletion src/Elastic.Markdown/IO/State/LinkReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +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.Runtime.InteropServices;
using System.Text.Json;
using System.Text.Json.Serialization;
using Elastic.Markdown.IO.Discovery;
Expand Down Expand Up @@ -70,7 +71,9 @@ public static LinkReference Create(DocumentationSet set)
var crossLinks = set.Build.Collector.CrossLinks.ToHashSet().ToArray();
var links = set.MarkdownFiles.Values
.Select(m => (m.RelativePath, File: m))
.ToDictionary(k => k.RelativePath, v =>
.ToDictionary(k => RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? k.RelativePath.Replace('\\', '/')
: k.RelativePath, v =>
{
var anchors = v.File.Anchors.Count == 0 ? null : v.File.Anchors.ToArray();
return new LinkMetadata { Anchors = anchors, Hidden = v.File.Hidden };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.IO.Abstractions;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using Elastic.Markdown.Diagnostics;
using Elastic.Markdown.Helpers;
Expand Down Expand Up @@ -271,6 +272,10 @@ private static void UpdateLinkUrl(LinkInline link, string url, ParserContext con
if (!string.IsNullOrWhiteSpace(url) && !string.IsNullOrWhiteSpace(urlPathPrefix))
url = $"{urlPathPrefix.TrimEnd('/')}{url}";

// When running on Windows, path traversal results must be normalized prior to being used in a URL
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
url = url.Replace('\\', '/');

link.Url = string.IsNullOrEmpty(anchor) ? url : $"{url}#{anchor}";
}

Expand Down
12 changes: 6 additions & 6 deletions tests/Elastic.Markdown.Tests/CodeBlocks/CallOutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void ParsesMagicCallOuts() => Block!.CallOuts

[Fact]
public void RendersExpectedHtml() =>
Html.Should().Contain("""
Html.ReplaceLineEndings().Should().Contain("""
<div class="highlight-csharp notranslate">
<div class="highlight">
<pre><code class="language-csharp">var x = 1; <span class="code-callout" data-index="1">1</span>
Expand All @@ -132,7 +132,7 @@ public void RendersExpectedHtml() =>
<li>Marking the first callout</li>
<li>Marking the second callout</li>
</ol>
""");
""".ReplaceLineEndings());


[Fact]
Expand Down Expand Up @@ -367,12 +367,12 @@ public void ParsesCallouts() => Block!.CallOuts

[Fact]
public void RenderedHtmlContainsCallouts() =>
Html.Should().Contain("""
Html.ReplaceLineEndings().Should().Contain("""
<ol class="code-callouts">
<li>First callout</li>
<li>Second callout</li>
</ol>
""");
""".ReplaceLineEndings());
}

public class CodeBlockWithMultipleCommentTypesThenList(ITestOutputHelper output) : CodeBlockCallOutTests(output, "csharp",
Expand Down Expand Up @@ -426,10 +426,10 @@ public void ParsesCallouts() => Block!.CallOuts

[Fact]
public void RendersIntermediateParagraph() =>
Html.Should().Contain("""
Html.ReplaceLineEndings().Should().Contain("""
<p><strong>This is an intermediate paragraph</strong></p>
<ol class="code-callouts">
""");
""".ReplaceLineEndings());
}

public class CodeBlockWithCommentBlocksTwoParagraphsThenList(ITestOutputHelper output) : CodeBlockCallOutTests(output, "csharp",
Expand Down
2 changes: 1 addition & 1 deletion tests/Elastic.Markdown.Tests/DocSet/BreadCrumbTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class BreadCrumbTests(ITestOutputHelper output) : NavigationTestsBase(out
[Fact]
public void ParsesATableOfContents()
{
var doc = Generator.DocumentationSet.Files.FirstOrDefault(f => f.RelativePath == "testing/nested/index.md") as MarkdownFile;
var doc = Generator.DocumentationSet.Files.FirstOrDefault(f => f.RelativePath == Path.Combine("testing", "nested", "index.md")) as MarkdownFile;

doc.Should().NotBeNull();

Expand Down
4 changes: 2 additions & 2 deletions tests/Elastic.Markdown.Tests/DocSet/NavigationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public void ParsesNestedFoldersAndPrefixesPaths()
{
Configuration.ImplicitFolders.Should().NotBeNullOrEmpty();
Configuration.ImplicitFolders.Should()
.Contain("testing/nested");
.Contain(Path.Combine("testing", "nested"));
}

[Fact]
public void ParsesFilesAndPrefixesPaths() =>
Configuration.Files.Should()
.Contain("index.md")
.And.Contain("syntax/index.md");
.And.Contain(Path.Combine("syntax", "index.md"));

[Fact]
public void ParsesRedirects()
Expand Down
2 changes: 1 addition & 1 deletion tests/Elastic.Markdown.Tests/DocSet/NestedTocTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class NestedTocTests(ITestOutputHelper output) : NavigationTestsBase(outp
[Fact]
public void InjectsNestedTocsIntoDocumentationSet()
{
var doc = Generator.DocumentationSet.Files.FirstOrDefault(f => f.RelativePath == "development/index.md") as MarkdownFile;
var doc = Generator.DocumentationSet.Files.FirstOrDefault(f => f.RelativePath == Path.Combine("development", "index.md")) as MarkdownFile;

doc.Should().NotBeNull();

Expand Down
8 changes: 4 additions & 4 deletions tests/Elastic.Markdown.Tests/Inline/InlineAnchorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ public class InlineAnchorInHeading(ITestOutputHelper output) : BlockTest<Heading
[Fact]
public void GeneratesAttributesInHtml() =>
// language=html
Html.Should().Be(
Html.ReplaceLineEndings().TrimEnd().Should().Be(
"""
<div class="heading-wrapper" id="hello-world"><h2><a class="headerlink" href="#hello-world">Hello world <a id="my-anchor"></a></a></h2>
</div>
""".TrimEnd()
""".ReplaceLineEndings().TrimEnd()
);
}

Expand All @@ -128,11 +128,11 @@ public class ExplicitSlugInHeader(ITestOutputHelper output) : BlockTest<HeadingB
[Fact]
public void GeneratesAttributesInHtml() =>
// language=html
Html.Should().Be(
Html.ReplaceLineEndings().TrimEnd().Should().Be(
"""
<div class="heading-wrapper" id="my-anchor"><h2><a class="headerlink" href="#my-anchor">Hello world</a></h2>
</div>
""".TrimEnd()
""".ReplaceLineEndings().TrimEnd()
);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,15 @@ public class CommentedNonExistingLinks2(ITestOutputHelper output) : LinkTestBase
[Fact]
public void GeneratesHtml() =>
// language=html
Html.TrimEnd().Should().Be("""
Html.ReplaceLineEndings().TrimEnd().Should().Be("""
<p>Links:</p>
<ul>
<li><a href="/docs/testing/req" hx-get="/docs/testing/req" hx-select-oob="#primary-nav,#secondary-nav,#content-container" hx-swap="none" hx-push-url="true" hx-indicator="#htmx-indicator" preload="true">Special Requirements</a></li>
</ul>
<ul>
<li><a href="/docs/testing/req" hx-get="/docs/testing/req" hx-select-oob="#primary-nav,#secondary-nav,#content-container" hx-swap="none" hx-push-url="true" hx-indicator="#htmx-indicator" preload="true">Special Requirements</a></li>
</ul>
""");
""".ReplaceLineEndings());

[Fact]
public void HasErrors() => Collector.Diagnostics.Should().HaveCount(0);
Expand Down
7 changes: 5 additions & 2 deletions tests/Elastic.Markdown.Tests/Inline/InlneBaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +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.TestingHelpers;
using System.Runtime.InteropServices;
using Elastic.Markdown.IO;
using FluentAssertions;
using JetBrains.Annotations;
Expand Down Expand Up @@ -103,8 +104,10 @@ protected InlineTest(
// ReSharper disable once VirtualMemberCallInConstructor
// nasty but sub implementations won't use class state.
AddToFileSystem(FileSystem);

var root = FileSystem.DirectoryInfo.New(Path.Combine(Paths.Root.FullName, "docs/"));
var baseRootPath = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? Paths.Root.FullName.Replace('\\', '/')
: Paths.Root.FullName;
var root = FileSystem.DirectoryInfo.New($"{baseRootPath}/docs/");
FileSystem.GenerateDocSetYaml(root, globalVariables);

Collector = new TestDiagnosticsCollector(output);
Expand Down
18 changes: 9 additions & 9 deletions tests/Elastic.Markdown.Tests/Mover/MoverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public async Task RelativeLinks()
linkModifications.Should().HaveCount(3);


Path.GetRelativePath(".", linkModifications[0].SourceFile).Should().Be("testing/mover/first-page.md");
Path.GetRelativePath(".", linkModifications[0].SourceFile).Should().Be(Path.Combine("testing", "mover", "first-page.md"));
linkModifications[0].OldLink.Should().Be("[Link to second page](second-page.md)");
linkModifications[0].NewLink.Should().Be("[Link to second page](../testing/mover/second-page.md)");

Path.GetRelativePath(".", linkModifications[1].SourceFile).Should().Be("testing/mover/second-page.md");
Path.GetRelativePath(".", linkModifications[1].SourceFile).Should().Be(Path.Combine("testing", "mover", "second-page.md"));
linkModifications[1].OldLink.Should().Be("[Link to first page](first-page.md)");
linkModifications[1].NewLink.Should().Be("[Link to first page](../../new-folder/hello-world.md)");

Path.GetRelativePath(".", linkModifications[2].SourceFile).Should().Be("testing/mover/second-page.md");
Path.GetRelativePath(".", linkModifications[2].SourceFile).Should().Be(Path.Combine("testing", "mover", "second-page.md"));
linkModifications[2].OldLink.Should().Be("[Absolut link to first page](/testing/mover/first-page.md)");
linkModifications[2].NewLink.Should().Be("[Absolut link to first page](/new-folder/hello-world.md)");
}
Expand All @@ -56,15 +56,15 @@ public async Task MoveToFolder()
var linkModifications = mover.LinkModifications[changeSet];
linkModifications.Should().HaveCount(3);

Path.GetRelativePath(".", linkModifications[0].SourceFile).Should().Be("testing/mover/first-page.md");
Path.GetRelativePath(".", linkModifications[0].SourceFile).Should().Be(Path.Combine("testing", "mover", "first-page.md"));
linkModifications[0].OldLink.Should().Be("[Link to second page](second-page.md)");
linkModifications[0].NewLink.Should().Be("[Link to second page](../testing/mover/second-page.md)");

Path.GetRelativePath(".", linkModifications[1].SourceFile).Should().Be("testing/mover/second-page.md");
Path.GetRelativePath(".", linkModifications[1].SourceFile).Should().Be(Path.Combine("testing", "mover", "second-page.md"));
linkModifications[1].OldLink.Should().Be("[Link to first page](first-page.md)");
linkModifications[1].NewLink.Should().Be("[Link to first page](../../new-folder/first-page.md)");

Path.GetRelativePath(".", linkModifications[2].SourceFile).Should().Be("testing/mover/second-page.md");
Path.GetRelativePath(".", linkModifications[2].SourceFile).Should().Be(Path.Combine("testing", "mover", "second-page.md"));
linkModifications[2].OldLink.Should().Be("[Absolut link to first page](/testing/mover/first-page.md)");
linkModifications[2].NewLink.Should().Be("[Absolut link to first page](/new-folder/first-page.md)");
}
Expand All @@ -84,15 +84,15 @@ public async Task MoveFolderToFolder()
var linkModifications = mover.LinkModifications[changeSet];
linkModifications.Should().HaveCount(3);

Path.GetRelativePath(".", linkModifications[0].SourceFile).Should().Be("testing/mover/first-page.md");
Path.GetRelativePath(".", linkModifications[0].SourceFile).Should().Be(Path.Combine("testing", "mover", "first-page.md"));
linkModifications[0].OldLink.Should().Be("[Link to second page](second-page.md)");
linkModifications[0].NewLink.Should().Be("[Link to second page](../testing/mover/second-page.md)");

Path.GetRelativePath(".", linkModifications[1].SourceFile).Should().Be("testing/mover/second-page.md");
Path.GetRelativePath(".", linkModifications[1].SourceFile).Should().Be(Path.Combine("testing", "mover", "second-page.md"));
linkModifications[1].OldLink.Should().Be("[Link to first page](first-page.md)");
linkModifications[1].NewLink.Should().Be("[Link to first page](../../new-folder/first-page.md)");

Path.GetRelativePath(".", linkModifications[2].SourceFile).Should().Be("testing/mover/second-page.md");
Path.GetRelativePath(".", linkModifications[2].SourceFile).Should().Be(Path.Combine("testing", "mover", "second-page.md"));
linkModifications[2].OldLink.Should().Be("[Absolut link to first page](/testing/mover/first-page.md)");
linkModifications[2].NewLink.Should().Be("[Absolut link to first page](/new-folder/first-page.md)");
}
Expand Down
3 changes: 2 additions & 1 deletion tests/authoring/Framework/MarkdownResultsAssertions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ open DiffPlex.DiffBuilder.Model
open FsUnit.Xunit
open JetBrains.Annotations
open Xunit.Sdk
open System.IO

[<AutoOpen>]
module ResultsAssertions =
Expand Down Expand Up @@ -50,7 +51,7 @@ module ResultsAssertions =

let result =
results.MarkdownResults
|> Seq.tryFind (fun m -> m.File.RelativePath = file)
|> Seq.tryFind (fun m -> m.File.RelativePath = (string file).Replace('/', Path.DirectorySeparatorChar))

match result with
| None ->
Expand Down