Skip to content

Commit d539068

Browse files
committed
fix: clean up task files
1 parent 54fbdda commit d539068

File tree

9 files changed

+254
-201
lines changed

9 files changed

+254
-201
lines changed

go.work.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/
66
github.com/dnitsch/simplelog v1.7.1 h1:5RVORNECiXQDLLEvmOnUMoPSwNWyZAGOs6p8xrRBlto=
77
github.com/dnitsch/simplelog v1.7.1/go.mod h1:+6a7bFEUXelqYb9kxJ1rv+bpmlO6nKh2aKkOVv59wlo=
88
github.com/godbus/dbus/v5 v5.0.4 h1:9349emZab16e7zQvpmsbtjc18ykshndd8y2PG3sgJbA=
9+
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5 h1:8Q0qkMVC/MmWkpIdlvZgcv2o2jrlF6zqVOh7W5YHdMA=
910
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
1011
github.com/montanaflynn/stats v0.6.6 h1:Duep6KMIDpY4Yo11iFsvyqJDyfzLF9+sndUKT+v64GQ=
1112
github.com/montanaflynn/stats v0.7.0 h1:r3y12KyNxj/Sb/iOE46ws+3mS1+MZca1wlHQFPsY/JU=
@@ -28,6 +29,7 @@ golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
2829
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
2930
golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=
3031
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
32+
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
3133
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
3234
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
3335
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=

src/dotnet/Schema.Generator/Sample.Generated.DLL.Source/TakeThisModel/Another.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,4 @@ namespace Sample.Generated.DLL.Source.TakeThisModel;
77
[JsonSchemaFlatten]
88
public class Another : BaseWrapper
99
{
10-
//public class BodyPayload
11-
//{
12-
// [JsonPropertyName("orderId")]
13-
// public string OrderId { get; set; }
14-
15-
// [JsonPropertyName("status")]
16-
// public string Status { get; set; }
17-
18-
// [JsonPropertyName("isCancelled")]
19-
// public bool IsCancelled { get; set; }
20-
21-
// // with items reference from another class
22-
// [JsonPropertyName("items")]
23-
// public IEnumerable<DefinedDep> Items { get; set; }
24-
//}
25-
26-
//[JsonPropertyName("payload")]
27-
//public BodyPayload Payload { get; set; }
2810
}

src/dotnet/Schema.Generator/Schema.Generator.CLI.Tests/RunWithFlagsTests.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Diagnostics;
21
using schemagenerator;
32

43
namespace Schema.Generator.CLI.Tests;
@@ -10,7 +9,12 @@ public class RunWithFlags
109
private const string TEST_SOURCE_DLL = "../../../../Sample.Generated.DLL.Source/bin/Release/net8.0/publish/Sample.Generated.DLL.Source.dll";
1110
//
1211
private const string OUT_DIR = "../../../.ignore";
13-
private static string[] _NS_FILTER = ["Sample.Generated.DLL.Source.TakeThisModel"];
12+
private static readonly string[] _NS_FILTER = ["Sample.Generated.DLL.Source.TakeThisModel"];
13+
14+
[TestCleanup]
15+
public void AfterEach (){
16+
Directory.Delete(OUT_DIR, true);
17+
}
1418

1519
[TestMethod]
1620
public void TestWithDereferenceSpecified()
@@ -59,5 +63,30 @@ public void TestWithoutDereferenceSpecified_should_produce_the_same_number_of_fi
5963

6064
Assert.IsTrue(files.Length >= 4);
6165
}
66+
67+
[TestMethod]
68+
public void Test_With_nonexistant_DLL_should_throw()
69+
{
70+
// Arrange
71+
var gen = new Generate("/path/not/found.dll", _NS_FILTER, false, OUT_DIR);
72+
var err = "";
73+
74+
// Act
75+
try
76+
{
77+
gen.SchemaFromTypes();
78+
}
79+
catch (Exception ex)
80+
{
81+
err = $"{ex.Message}. {ex.StackTrace}";
82+
}
83+
string[] files = Directory.GetFiles(OUT_DIR, "", SearchOption.AllDirectories);
84+
85+
// Assert
86+
// Assert.IsTrue(err.Length > 0);
87+
88+
Assert.IsTrue(files.Length == 0);
89+
}
90+
6291
}
6392

src/dotnet/Schema.Generator/Schema.Generator.CLI/PluginLoadContext.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,4 @@ public PluginLoadContext(string pluginPath)
2525
}
2626
return null;
2727
}
28-
29-
protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
30-
{
31-
string libraryPath = _resolver.ResolveUnmanagedDllToPath(unmanagedDllName);
32-
if (libraryPath != null)
33-
{
34-
return LoadUnmanagedDllFromPath(libraryPath);
35-
}
36-
return IntPtr.Zero;
37-
}
3828
}
Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,24 @@
11
using McMaster.Extensions.CommandLineUtils;
2-
using System.ComponentModel.DataAnnotations;
2+
using schemagenerator;
33

4+
var app = new CommandLineApplication();
45

5-
namespace schemagenerator
6-
{
7-
[Command]
8-
public class Program
9-
{
10-
public static Task<int> Main(string[] args) => CommandLineApplication.ExecuteAsync<Program>(args);
6+
app.HelpOption();
117

12-
[Required]
13-
[Option(Description = "Path to the DLL", ShortName = "p")]
14-
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
15-
public string DllPath { get; }
16-
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
8+
var path = app.Option("-p|--path <PATH_TO_DLL>", "The path to DLL", CommandOptionType.SingleValue);
9+
var nsFilter = app.Option("-f|--filter <NAMESPACE>", "Namespace Filter, multiple can be provided", CommandOptionType.MultipleValue);
10+
var derefSchema = app.Option("-d|--deref", "Dereference Schema. Removes addtional schema elements and inlines them in a single top level property", CommandOptionType.NoValue);
11+
var output = app.Option("-o|--output <OUTPUT_DIR>", "Output directory", CommandOptionType.SingleValue);
12+
output.DefaultValue = ".autogened";
1713

18-
[Required]
19-
[Option(Description = "Namespace Filter, multiple can be provided with a comma used as a separator", LongName = "namespace-filter", ShortName = "f", ShowInHelpText = true)]
20-
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
21-
public string NamespaceFilter { get; }
22-
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
14+
var contextToken = new CancellationToken();
2315

24-
[Option(Description = "Output directory", LongName = "output-dir", ShortName = "o")]
25-
public string OutputDir { get; } = ".autogened";
16+
app.OnExecuteAsync((contextToken) =>
17+
{
18+
var gen = new Generate(path.Value(), nsFilter?.Values.ToArray(), derefSchema.Values.Count > 0, output.Value());
19+
gen.SchemaFromTypes();
20+
return Task.FromResult(true);
2621

27-
[Option(Description = "Dereference Schema", LongName = "deref-schema", ShortName = "d")]
28-
public bool Deref { get; } = false;
22+
});
2923

30-
private void OnExecuteAsync()
31-
{
32-
var gen = new Generate(DllPath, NamespaceFilter.Split(","), Deref, OutputDir);
33-
gen.SchemaFromTypes();
34-
}
35-
}
36-
}
24+
return app.Execute(args);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# yaml-language-server: $schema=https://taskfile.dev/schema.json
2+
version: '3'
3+
4+
env:
5+
NETCORE_TARGET_ARCH: "osx-arm64"
6+
7+
tasks:
8+
clean_dotnet:
9+
internal: true
10+
cmds:
11+
- rm -rf dist/dotnet/*
12+
- mkdir -p dist/dotnet
13+
# SchemaGenerator DOTNET
14+
schemagenerator_bin-gen:
15+
desc: Builds a single binary of the schema generator for each platform
16+
deps:
17+
- clean_dotnet
18+
cmds:
19+
- cmd: |
20+
cd src/dotnet
21+
dotnet clean Schema.Generator/Schema.Generator.sln
22+
- for: { var: NETCORE_TARGET_ARCHS, as: NETCORE_TARGET_ARCH }
23+
cmd: |
24+
cd src/dotnet
25+
dotnet publish Schema.Generator/Schema.Generator.CLI/Schema.Generator.CLI.csproj -r {{.NETCORE_TARGET_ARCH}} -o ../../dist/dotnet/{{.NETCORE_TARGET_ARCH}};
26+
vars:
27+
NETCORE_TARGET_ARCHS: win-x64 osx-x64 osx-arm64 linux-x64 linux-musl-x64
28+
env:
29+
VERSION: "{{.GIT_TAG}}"
30+
31+
schemagenerator_test:
32+
desc: Runs the tests for SchemaGenerator
33+
cmd: |
34+
cd src/dotnet/Schema.Generator
35+
rm -rf .coverage
36+
dotnet build Sample.Generated.DLL.Source/Sample.Generated.DLL.Source.csproj
37+
dotnet test -l trx --collect "XPlat Code Coverage" --results-directory .coverage
38+
env:
39+
VERSION: 0.0.1
40+
41+
schemagenerator_show-coverage:
42+
desc: Shows coverage in a visual tool
43+
preconditions:
44+
- dotnet --help
45+
deps:
46+
- schemagenerator_test
47+
cmds:
48+
- cmd: dotnet tool install -g dotnet-reportgenerator-globaltool
49+
- |
50+
cd src/dotnet/Schema.Generator
51+
reportgenerator -reports:".coverage/*/coverage.cobertura.xml" -targetdir:".coverage/report" -reporttypes:Html
52+
{{if eq OS "windows"}}start ""{{else}}open{{end}} .coverage/report/index.html

src/go/taskfile.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# yaml-language-server: $schema=https://taskfile.dev/schema.json
2+
version: '3'
3+
4+
env:
5+
GO_TARGET_ARCH: "darwin"
6+
7+
tasks:
8+
test_prereq:
9+
internal: true
10+
preconditions:
11+
- go version
12+
cmd: |
13+
cd ./src/go/async-api-gen-doc && mkdir -p .coverage
14+
go install github.com/jstemmer/go-junit-report/v2@latest
15+
go install github.com/axw/gocov/gocov@latest
16+
go install github.com/AlekSi/gocov-xml@latest
17+
18+
clean_go:
19+
internal: true
20+
cmds:
21+
- rm -rf dist/go/*
22+
- mkdir -p dist/go
23+
24+
test:
25+
desc: Install dependencies
26+
internal: false
27+
deps:
28+
- test_prereq
29+
cmd: |
30+
set -exo pipefail
31+
cd ./src/go/async-api-gen-doc
32+
go test ./... -timeout 30s -v -mod=readonly -race -coverprofile=.coverage/out > .coverage/test.out
33+
34+
35+
install:
36+
desc: Install dependencies
37+
internal: true
38+
cmd: |
39+
cd src/go/async-api-gen-doc
40+
go mod tidy
41+
42+
lint:
43+
desc: Runs lint and vet
44+
cmd: |
45+
cd src/go/async-api-gen-doc
46+
go vet
47+
48+
coverage:
49+
desc: generate coverage
50+
deps:
51+
- test_asyncapi_doc_generator
52+
cmds:
53+
- |
54+
cd src/go/async-api-gen-doc
55+
go-junit-report -in .coverage/test.out > .coverage/go-junit.xml
56+
- |
57+
cd src/go/async-api-gen-doc
58+
gocov convert .coverage/out | gocov-xml > .coverage/cobertura.xml
59+
60+
show_coverage:
61+
desc: Opens the current coverage viewer for the the gendoc utility.
62+
deps:
63+
- test
64+
cmd: go tool cover -html=./src/go/async-api-gen-doc/.coverage/out
65+
66+
show_docs:
67+
desc: Opens a webview with godoc running
68+
dir: src/go/async-api-gen-doc
69+
summary: |
70+
Already filters the packages to this one and enables
71+
internal/private package documentation
72+
cmd: |
73+
go install golang.org/x/tools/cmd/godoc@latest
74+
open http://localhost:6060/pkg/github.com/dnitsch/async-api-generator/?m=all
75+
godoc -notes "BUG|TODO" -play -http=:6060
76+
77+
bin:
78+
desc: Generates binaries in a dist folder
79+
summary: |
80+
Generates all the binaries for the gendoc utility.
81+
82+
can be called from inside CI like this:
83+
84+
`task async-api-generator:bin GIT_TAG=0.1.2 REVISION=$commit_sha`
85+
deps:
86+
- clean_go
87+
cmds:
88+
- for: { var: GO_ARCHS, as: GO_TARGET_ARCH }
89+
cmd: |
90+
mkdir -p ./dist/go/{{.GO_TARGET_ARCH}}
91+
GOOS={{.GO_TARGET_ARCH}} CGO_ENABLED=0 go build -mod=readonly -buildvcs=false {{.LDFLAGS}} -o ./dist/go/{{.GO_TARGET_ARCH}}/gendoc ./src/go/async-api-gen-doc/cmd
92+
cp README.md ./dist/go/{{.GO_TARGET_ARCH}}/README.md
93+
vars:
94+
LDFLAGS: -ldflags="-s -w -X \"github.com/dnitsch/async-api-generator/cmd/async-api-gen-doc.Version=${VERSION}\" -X \"github.com/dnitsch/async-api-generator/cmd/async-api-gen-doc.Revision={{.REVISION}}\" -extldflags -static"
95+
GO_ARCHS: darwin windows linux
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# yaml-language-server: $schema=https://taskfile.dev/schema.json
2+
version: '3'
3+
4+
tasks:
5+
node_prereq:
6+
internal: true
7+
cmds:
8+
- npm i -g [email protected]
9+
- rm -rf dist node_modules .coverage
10+
11+
install_node:
12+
desc: Install dependencies
13+
internal: true
14+
deps:
15+
- node_prereq
16+
cmds:
17+
- pnpm i
18+
19+
# EventCatalog Plugin tasks
20+
test:
21+
desc: Builds and tests the EventCatalog plugin
22+
summary: |
23+
24+
Testing of the plugin and any local dependencies against a licence checker
25+
deps:
26+
- install_node
27+
cmds:
28+
- pnpm run license:check
29+
- pnpm run test
30+
31+
build:
32+
desc: Builds the EventCatalog plugin
33+
summary: |
34+
Building and testing of the plugin and any local dependencies
35+
deps:
36+
- test
37+
cmds:
38+
- pnpm run build
39+
40+
show_coverage:
41+
desc: Opens the current coverage viewer for the the event catalog plugin.
42+
deps:
43+
- test_eventcatalog_plugin
44+
cmd: pnpm run --filter @dnitsch/plugin-doc-generator-asyncapi-remote-source view:coverage
45+
46+
publish:
47+
desc: Publishes to local NPM
48+
cmds:
49+
- pnpm run build
50+
- pnpm publish --no-git-checks --filter "@dnitsch/*"
51+

0 commit comments

Comments
 (0)