Skip to content

Commit 68cbfdd

Browse files
authored
Merge pull request #29 from MobileTeleSystems/feature/alpha
Version 3.2
2 parents c3006a9 + 78da0d8 commit 68cbfdd

34 files changed

+2705
-90
lines changed

.github/workflows/publish.yml

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ jobs:
2626
PackageOutputDir: ".packages"
2727
Prerelease: ${{ github.event.inputs.prerelease || 'false' }}
2828
PushPackage: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/master') || github.event.inputs.push }}
29+
NpmTokenExists: ${{ secrets.NPM_TOKEN != '' }}
30+
Platforms: "linux-x64 linux-musl-x64 osx-x64 osx-arm64 win-x64"
2931

3032
steps:
3133
- uses: actions/checkout@v4
@@ -37,6 +39,11 @@ jobs:
3739
with:
3840
dotnet-version: 9.0.x
3941

42+
- name: Setup Node.js
43+
uses: actions/setup-node@v4
44+
with:
45+
node-version: 20
46+
4047
- name: Install GitVersion
4148
uses: gittools/actions/gitversion/setup@v3.0.0
4249
with:
@@ -46,27 +53,62 @@ jobs:
4653
run: |
4754
${GITVERSION_PATH}/dotnet-gitversion /output buildserver /output json
4855
49-
- name: Pack
56+
- name: Pack Nuget
5057
run: |
5158
dotnet pack --nologo -o ${PackageOutputDir} \
5259
-p:PackageVersion=${GitVersion_SemVer} \
53-
-p:AssemblyVersion=${GitVersion_AssemblySemFileVer} \
5460
-p:FileVersion=${GitVersion_MajorMinorPatch} \
5561
-p:AssemblyVersion=${GitVersion_AssemblySemVer} \
5662
-p:FileVersion=${GitVersion_MajorMinorPatch} \
5763
-p:Configuration=Release
5864
65+
- name: Pack Npm
66+
run: |
67+
ROOT=$(pwd)
68+
cd src/ApiCodeGenerator.Npm
69+
npm install
70+
npm version ${GitVersion_FullSemVer} --no-git-tag-version
71+
npm run pack-ci -- ${ROOT}/${PackageOutputDir}
72+
73+
- name: Pack Npm Binaries
74+
run: |
75+
ROOT=$(pwd)
76+
for PLATFORM in ${{ env.Platforms }}; do
77+
echo "Building for platform: $PLATFORM"
78+
dotnet publish src/ApiCodeGenerator.MSBuild \
79+
-c Release \
80+
-f net8.0 \
81+
-r $PLATFORM \
82+
--self-contained \
83+
-p:PublishTrimmed=false \
84+
-o ./bin/publish/$PLATFORM
85+
86+
# Create tgz archive with platform name only
87+
cd ./bin/publish/$PLATFORM
88+
tar -czf $ROOT/${PackageOutputDir}/${PLATFORM}.tgz *
89+
cd $ROOT
90+
91+
echo "Created archive: ${PLATFORM}.tgz"
92+
done
93+
5994
- name: Nuget Push
6095
if: env.PushPackage == 'true'
6196
working-directory: ${{ env.PackageOutputDir }}
6297
run: dotnet nuget push *.nupkg -s https://api.nuget.org/v3/index.json -k ${{secrets.NUGET_API_KEY}}
6398

99+
- name: Npm Push
100+
if: env.PushPackage == 'true' && env.NpmTokenExists == 'true'
101+
uses: JS-DevTools/npm-publish@v4
102+
with:
103+
token: ${{ secrets.NPM_TOKEN }}
104+
package: ${{ env.PackageOutputDir }}
105+
64106
- name: Create Release
65107
uses: ncipollo/release-action@v1
66108
with:
67109
name: v${{ env.GitVersion_SemVer }}
68110
tag: v${{ env.GitVersion_SemVer }}
69-
artifacts: ${{ env.PackageOutputDir }}/*.nupkg
111+
artifacts: ${{ env.PackageOutputDir }}/*.nupkg,${{ env.PackageOutputDir }}/*.tgz
70112
generateReleaseNotes: true
71113
commit: ${{ env.GitVersion_Sha}}
72114
prerelease: ${{ env.Prerelease }}

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
.vs/
66
bin/
77
obj/
8+
binaries/
9+
coverage/
10+
dist/
11+
node_modules/
812

913
*.user
1014
msbuild.binlog
15+
package-lock.json
16+
acg.js
17+
acg.d.ts

ApiCodeGenerator.code-workspace

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"folders": [
3+
{
4+
"path": "."
5+
},
6+
{
7+
"path": "src/ApiCodeGenerator.Npm"
8+
}
9+
],
10+
"settings": {
11+
"autoHide.hideSideBarsOnDebug": false,
12+
"autoHide.hidePanelOnDebug": false
13+
}
14+
}

GitVersion.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
next-version: "3.2.0"
12
mode: ContinuousDelivery
23
branches:
3-
main:
4-
mode: ContinuousDeployment
5-
label: ''
6-
increment: Patch
7-
is-main-branch: true
8-
develop:
9-
label: rc
4+
main:
5+
mode: ContinuousDeployment
6+
label: ""
7+
increment: Patch
8+
is-main-branch: true
9+
develop:
10+
label: rc
1011
ignore:
1112
sha: []
1213
merge-message-formats: {}
13-

src/ApiCodeGenerator.AsyncApi/ApiCodeGenerator.AsyncApi.nuspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
<file src="bin\$configuration$\netstandard2.0\ApiCodeGenerator.*.dll" target="lib\netstandard2.0" />
2323
<file src="..\Sdk\Sdk.props" target="Sdk\Sdk.props" />
2424
<file src="..\Sdk\Sdk.targets" target="Sdk\Sdk.targets" />
25+
<file src="..\Sdk\NpmPack.targets" target="Sdk\NpmPack.targets" />
26+
<file src="..\Sdk\postinstall.js" target="Sdk\postinstall.js" />
2527
<file src="..\..\LICENSE" target="LICENSE" />
2628
</files>
2729
</package>

src/ApiCodeGenerator.Core/GenerationTask.cs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
44
using System.Diagnostics.CodeAnalysis;
@@ -91,8 +91,9 @@ public async Task<bool> ExecuteAsync(string nswagFilePath,
9191
vars["OutFile"] = outFilePath;
9292
var roVariables = new ReadOnlyDictionary<string, string>(vars);
9393

94-
LogMessage("Values of nswag variables");
95-
LogMessage(string.Join(Environment.NewLine, vars.Select(_ => $"\t[{_.Key}] = {_.Value}")));
94+
LogMessage("Values of nswag variables: {0}{1}",
95+
Environment.NewLine,
96+
string.Join(Environment.NewLine, vars.Select(_ => $"\t[{_.Key}] = {_.Value}")));
9697

9798
JObject? baseNswagDocument = LoadBaseNswag(baseNswagFilePath);
9899
var nswagDocument = _documentFactory.LoadNswagDocument(nswagFilePath, roVariables, baseNswagDocument);
@@ -110,18 +111,18 @@ public async Task<bool> ExecuteAsync(string nswagFilePath,
110111
return false;
111112
}
112113

113-
var context = await CreateGenerationContext(nswagDocument, nswagFilePath, roVariables);
114-
115-
if (context is not null)
114+
try
116115
{
117-
if (context.DocumentReader is null)
118-
{
119-
Log?.LogWarning(NotSetInput, nswagFilePath, "Source not set. Skip generation.");
120-
return true;
121-
}
116+
var context = await CreateGenerationContext(nswagDocument, nswagFilePath, roVariables);
122117

123-
try
118+
if (context is not null)
124119
{
120+
if (context.DocumentReader is null)
121+
{
122+
Log?.LogWarning(NotSetInput, nswagFilePath, "Source not set. Skip generation.");
123+
return true;
124+
}
125+
125126
LogMessage($"Use settings: {generatorSettings.Key}");
126127
var contentGenerator = await contentGeneratorFactory.Invoke(context);
127128

@@ -137,14 +138,14 @@ public async Task<bool> ExecuteAsync(string nswagFilePath,
137138
{
138139
Log?.LogError(WriteFileErr, outFilePath, "Unable write file. Error: {0}", ex.Message);
139140
}
140-
}
141-
catch (InvalidOperationException ex)
142-
{
143-
Log?.LogError(GenerationErr, nswagFilePath, ex.Message);
144-
return false;
145-
}
146141

147-
return true;
142+
return true;
143+
}
144+
}
145+
catch (InvalidOperationException ex)
146+
{
147+
Log?.LogError(GenerationErr, nswagFilePath, ex.Message);
148+
return false;
148149
}
149150

150151
return false;

src/ApiCodeGenerator.MSBuild/ApiCodeGenerator.MSBuild.csproj

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net6.0;net9.0;net8.0;netstandard2.0</TargetFrameworks>
3+
<TargetFrameworks>net9.0;net8.0;netstandard2.0</TargetFrameworks>
44
<IsPackable>true</IsPackable>
55
<Nullable>enable</Nullable>
6+
<InvariantGlobalization>true</InvariantGlobalization>
67
<!--Параметры пакета в Directory.Build.targets-->
78
</PropertyGroup>
89

@@ -23,13 +24,19 @@
2324
<None Include="..\ApiCodeGenerator.Core\bin\$(Configuration)\netstandard2.0\ApiCodeGenerator.Core.dll" Link="ApiCodeGenerator.Core.dll">
2425
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
2526
</None>
27+
<None Include="..\ApiCodeGenerator.OpenApi\bin\$(Configuration)\netstandard2.0\ApiCodeGenerator.OpenApi.dll" CopyToPublishDirectory="Always" />
28+
<None Include="..\ApiCodeGenerator.AsyncApi\bin\$(Configuration)\netstandard2.0\ApiCodeGenerator.AsyncApi.dll" CopyToPublishDirectory="Always" />
2629
</ItemGroup>
2730

2831
<ItemGroup>
2932
<ProjectReference Include="..\ApiCodeGenerator.Abstraction\ApiCodeGenerator.Abstraction.csproj" />
3033
</ItemGroup>
3134

35+
<ItemGroup Label="Nswag prerequiries">
36+
<PackageReference Include="Microsoft.Extensions.FileProviders.Abstractions" Version="9.0.0" />
37+
</ItemGroup>
38+
3239
<Import Project="./ApiCodeGenerator.MSBuild.Console.targets" Condition="'$(TargetFramework)' != 'netstandard2.0'" />
3340
<Import Project="./ApiCodeGenerator.MSBuild.Task.targets" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
3441

35-
</Project>
42+
</Project>

src/ApiCodeGenerator.MSBuild/ApiCodeGenerator.MSBuild.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<description>Adds API client generation to the project based on the NSwag file and the API description document.</description>
99
<repository type="git" url="$repository$" />
1010
<dependencies>
11-
<dependency id="Microsoft.Extensions.ApiDescription.Client" version="5.0" />
11+
<dependency id="Microsoft.Extensions.ApiDescription.Client" version="10.0" />
1212
<dependency id="NSwag.MSBuild" version="$nswagVersion$" />
1313
</dependencies>
1414
<license type="file">LICENSE</license>
Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
2+
using System.IO;
63
using ApiCodeGenerator.Abstraction;
74

85
namespace ApiCodeGenerator.MSBuild
96
{
107
internal class ConsoleLogAdapter : ILogger
118
{
129
public void LogError(string? code, string? sourceFile, string message, params object[] messageArgs)
13-
=> Console.Error.WriteLine($"{sourceFile}: {string.Format(message, messageArgs)}");
10+
=> Log(Console.Error, "error", code, sourceFile, string.Format(message, messageArgs));
1411

1512
public void LogMessage(string? code, string? sourceFile, string message, params object[] messageArgs)
16-
=> Console.WriteLine($"INFO: {string.Format(message, messageArgs)}");
13+
=> Log(Console.Out, code is null ? null : "info", code, sourceFile, string.Format(message, messageArgs));
1714

1815
public void LogWarning(string? code, string? sourceFile, string message, params object[] messageArgs)
19-
=> Console.WriteLine($"WARNING {sourceFile}: {string.Format(message, messageArgs)}");
16+
=> Log(Console.Out, "warning", code, sourceFile, string.Format(message, messageArgs));
17+
18+
private static void Log(TextWriter writer, string? type, string? code, string? file, string message)
19+
{
20+
if (file is not null)
21+
{
22+
writer.Write(Path.IsPathFullyQualified(file)
23+
? file
24+
: Path.GetFullPath(file));
25+
writer.Write("(1,1): ");
26+
}
27+
28+
if (type is not null)
29+
{
30+
writer.Write(type);
31+
if (code is not null)
32+
{
33+
writer.Write(" ");
34+
writer.Write(code);
35+
}
36+
37+
writer.Write(": ");
38+
}
39+
40+
writer.WriteLine(message);
41+
}
2042
}
2143
}

src/ApiCodeGenerator.MSBuild/Console/GenerateCommand.cs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public GenerateCommand()
5050
this.SetHandler(ExecuteAsync);
5151
}
5252

53-
private Task ExecuteAsync(InvocationContext context)
53+
private async Task ExecuteAsync(InvocationContext context)
5454
{
5555
#if DEBUG
5656
System.Diagnostics.Debugger.Launch();
@@ -66,7 +66,8 @@ private Task ExecuteAsync(InvocationContext context)
6666
var factory = GetGenerationTaskFactory(nswagToolPath);
6767
AddExtesionsProbingPaths(extPaths);
6868
var generator = factory.Create(extPaths, new ConsoleLogAdapter());
69-
return generator.ExecuteAsync(nswagFile, openApiFile, outFile, variables, baseNswagFile);
69+
var result = await generator.ExecuteAsync(nswagFile, openApiFile, outFile, variables, baseNswagFile);
70+
context.ExitCode = result ? 0 : 1;
7071
}
7172

7273
private IGenerationTaskFactory GetGenerationTaskFactory(string? nswagToolsPath)
@@ -77,7 +78,7 @@ private IGenerationTaskFactory GetGenerationTaskFactory(string? nswagToolsPath)
7778
AssemblyResolver.Register(context);
7879

7980
var thisAssemblyPath = GetThisAssemblyPath();
80-
AssemblyResolver.AddProbingPath(SelectToolsFrameworkFolder(nswagToolsPath ?? Path.Combine(thisAssemblyPath, NswagToolsDirName)));
81+
AssemblyResolver.AddProbingPath(nswagToolsPath ?? Path.Combine(thisAssemblyPath, NswagToolsDirName));
8182
AssemblyResolver.AddProbingPath(thisAssemblyPath);
8283

8384
var coreAsm = context.LoadFromAssemblyName(new AssemblyName("ApiCodeGenerator.Core"));
@@ -103,24 +104,5 @@ private static string GetThisAssemblyPath()
103104
var thisAsmPath = Assembly.GetExecutingAssembly().Location;
104105
return Path.GetDirectoryName(thisAsmPath)!;
105106
}
106-
107-
private static string[] SelectToolsFrameworkFolder(string path)
108-
{
109-
// Для NET >= 6 добавляем в список источников папку с фрейворком AspNetCore
110-
var aspVersion = $"{Environment.Version.Major}.{Environment.Version.Minor}.*";
111-
return new[]
112-
{
113-
path,
114-
GetAspSharedFrameworkFolder(aspVersion),
115-
};
116-
117-
static string GetAspSharedFrameworkFolder(string version)
118-
{
119-
var asm = Assembly.Load("System.Threading");
120-
var shared = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(asm.Location)))!;
121-
var asp = Path.Combine(shared, "Microsoft.AspNetCore.App");
122-
return Directory.GetDirectories(asp, version).OrderBy(_ => _).Last();
123-
}
124-
}
125107
}
126108
}

0 commit comments

Comments
 (0)