Skip to content

Commit 2c70b99

Browse files
committed
Extract converter.yml and add tests.
1 parent e193540 commit 2c70b99

5 files changed

Lines changed: 115 additions & 24 deletions

File tree

.github/workflows/converter.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Build the converter and optionally run it
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
test:
7+
type: boolean
8+
run:
9+
type: boolean
10+
is_index:
11+
type: boolean
12+
13+
jobs:
14+
15+
build:
16+
env:
17+
build_config: Release
18+
book_folder: ${{ github.event.repository.name }}${{ case(inputs.is_index, '/index', '') }}
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Set $build_config_lower
22+
run: echo "build_config_lower=${build_config@L}" >> "$GITHUB_ENV"
23+
- name: Checkout Book
24+
if: ${{ run && !inputs.is_index }}
25+
uses: actions/checkout@v6
26+
with:
27+
path: ${{ env.book_folder }}
28+
- name: Checkout Index with Converter
29+
uses: actions/checkout@v6
30+
with:
31+
repository: originlab/originlab.github.io
32+
path: originlab.github.io
33+
- uses: actions/setup-dotnet@v5
34+
with:
35+
dotnet-version: '10.x'
36+
#- run: ls -l -R
37+
- name: Build converter
38+
run: dotnet build -c $build_config originlab.github.io/converter/generator/generator.csproj
39+
- name: Test converter
40+
if: ${{ inputs.test }}
41+
run: dotnet run -c $build_config --project originlab.github.io/converter/tests/tests.csproj
42+
- name: Run Converter
43+
if: ${{ inputs.run }}
44+
run: dotnet "originlab.github.io/converter/artifacts/bin/generator/$build_config_lower/generator.dll" "$book_folder" ${{ case(inputs.is_index, 'merge', '') }}
45+
- name: Upload pages artifact
46+
if: ${{ inputs.run }}
47+
uses: actions/upload-pages-artifact@v5
48+
with:
49+
path: public_html
50+

.github/workflows/publish_book.yml

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,11 @@ concurrency:
1313
jobs:
1414

1515
build:
16-
env:
17-
book_folder: ${{ github.event.repository.name }}${{ case(inputs.is_index, '/index', '') }}
18-
runs-on: ubuntu-latest
19-
steps:
20-
- name: Checkout Book
21-
if: ${{ !inputs.is_index }}
22-
uses: actions/checkout@v6
23-
with:
24-
path: ${{ env.book_folder }}
25-
- name: Checkout Index with Converter
26-
uses: actions/checkout@v6
27-
with:
28-
repository: originlab/originlab.github.io
29-
path: originlab.github.io
30-
- uses: actions/setup-dotnet@v5
31-
with:
32-
dotnet-version: '10.x'
33-
#- run: ls -l -R
34-
- name: Run Converter
35-
run: dotnet run -c Release --project originlab.github.io/converter/generator/generator.csproj -- ${{ env.book_folder }} ${{ case(inputs.is_index, 'merge', '') }}
36-
- name: Upload pages artifact
37-
uses: actions/upload-pages-artifact@v5
38-
with:
39-
path: public_html
16+
uses: ./.github/workflows/converter.yml
17+
with:
18+
test: ${{ inputs.is_index }}
19+
run: true
20+
is_index: ${{ inputs.is_index }}
4021

4122
deploy:
4223
needs: build

converter/converter.slnx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
<File Path=".editorconfig" />
55
</Folder>
66
<Folder Name="/Solution Items/Workflows/">
7+
<File Path="../.github/workflows/converter.yml" />
78
<File Path="../.github/workflows/deploy.yml" />
89
<File Path="../.github/workflows/publish_book.yml" />
910
</Folder>
1011
<Project Path="generator/generator.csproj" />
1112
<Project Path="templates/templates.csproj" />
13+
<Project Path="tests/tests.csproj" Id="0ced4798-e7da-48fa-8462-9c8c97036502" />
1214
<Project Path="utils/utils.csproj" Id="a84489a3-d5e2-4908-b1a4-6947fab586d4" />
1315
</Solution>

converter/tests/UtilsTests.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
namespace OriginLab.DocumentGeneration.Tests;
2+
3+
public class UtilsTests
4+
{
5+
[Theory]
6+
[InlineData("", new string[0])]
7+
[InlineData("", new string?[] { null })]
8+
[InlineData("", new[] { "" })]
9+
[InlineData("", new[] { "", null })]
10+
[InlineData("/a", new[] { "a", null })]
11+
[InlineData("/a", new[] { "a", "" })]
12+
[InlineData("/a/b", new[] { "a", "b" })]
13+
[InlineData("/b", new[] { null, "b" })]
14+
[InlineData("/b", new[] { "", "b" })]
15+
public void TryPrefixEachSkipsEmptyItems(string expected, string?[] items)
16+
{
17+
Assert.Equal(expected, '/'.TryPrefixEach(items));
18+
}
19+
20+
[Theory]
21+
[InlineData("", new string[0])]
22+
[InlineData("", new string?[] { null })]
23+
[InlineData("", new[] { "" })]
24+
[InlineData("", new[] { "", null })]
25+
[InlineData("/a/", new[] { "a", null })]
26+
[InlineData("/a/", new[] { "a", "" })]
27+
[InlineData("/a/b/", new[] { "a", "b" })]
28+
[InlineData("/b/", new[] { null, "b" })]
29+
[InlineData("/b/", new[] { "", "b" })]
30+
public void TrySurroundEachSkipsEmptyItems(string expected, string?[] items)
31+
{
32+
Assert.Equal(expected, '/'.TrySurroundEach(items));
33+
}
34+
35+
}

converter/tests/tests.csproj

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<IsPackable>false</IsPackable>
6+
<IsTestProject>true</IsTestProject>
7+
<RootNamespace>OriginLab.DocumentGeneration.Tests</RootNamespace>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="xunit.v3" Version="1.0.1" />
12+
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.14.1" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\generator\generator.csproj" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<Using Include="Xunit" />
21+
</ItemGroup>
22+
23+
</Project>

0 commit comments

Comments
 (0)