diff --git a/.gitignore b/.gitignore index fe508bd54..6310b1a43 100644 --- a/.gitignore +++ b/.gitignore @@ -82,3 +82,8 @@ _ReSharper.Caches/ /artifacts *.binlog + +# GitLab +.idea/ +.gitlab/packages +**/TestResults.xml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 000000000..6978d22d4 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,39 @@ +variables: + BASE_IMAGE_VERSION: ${CI_COMMIT_REF_SLUG}-${CI_PIPELINE_ID} + DOCKER_VERSION: 24.0.5 + +workflow: + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + - if: $CI_COMMIT_TAG + - when: never + +build-base: + image: docker:${DOCKER_VERSION} + services: + - docker:${DOCKER_VERSION}-dind + script: + - echo "$CI_REGISTRY_PASSWORD" | docker login $CI_REGISTRY -u $CI_REGISTRY_USER --password-stdin + - docker buildx build -f .gitlab/Dockerfile-build -t ${CI_REGISTRY_IMAGE}/base:${BASE_IMAGE_VERSION} --push .gitlab + +build: + needs: + - build-base + image: ${CI_REGISTRY_IMAGE}/base:${BASE_IMAGE_VERSION} + script: + - ./build.sh Compile Test Pack --configuration Release + artifacts: + paths: + - artifacts/*.nupkg + - artifacts/*.snupkg + reports: + junit: "**/TestResults.xml" + +publish: + image: ${CI_REGISTRY_IMAGE}/base:${BASE_IMAGE_VERSION} + needs: + - build + script: + - dotnet nuget add source "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/nuget/index.json" --name gitlab + - dotnet nuget push artifacts/*.nupkg --source gitlab --api-key ${CI_DEPLOY_PASSWORD} + when: manual diff --git a/.gitlab/Dockerfile-build b/.gitlab/Dockerfile-build new file mode 100644 index 000000000..8bea0d65e --- /dev/null +++ b/.gitlab/Dockerfile-build @@ -0,0 +1,8 @@ +FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine + +COPY --from=mcr.microsoft.com/dotnet/sdk:7.0-alpine /usr/share/dotnet/shared /usr/share/dotnet/shared +COPY --from=mcr.microsoft.com/dotnet/sdk:7.0-alpine /usr/share/dotnet/sdk /usr/share/dotnet/sdk +COPY --from=mcr.microsoft.com/dotnet/sdk:6.0-alpine /usr/share/dotnet/shared /usr/share/dotnet/shared +COPY --from=mcr.microsoft.com/dotnet/sdk:6.0-alpine /usr/share/dotnet/sdk /usr/share/dotnet/sdk + +RUN apk add --no-cache bash npm diff --git a/.gitlab/testing.csproj b/.gitlab/testing.csproj new file mode 100644 index 000000000..fa6b6ba9a --- /dev/null +++ b/.gitlab/testing.csproj @@ -0,0 +1,12 @@ + + + + net8.0 + + + + + + + + diff --git a/build/Build.Pack.cs b/build/Build.Pack.cs index 7a0b4e0d7..368b38612 100644 --- a/build/Build.Pack.cs +++ b/build/Build.Pack.cs @@ -23,7 +23,6 @@ public partial class Build Target Pack => _ => _ .DependsOn(Compile) .After(Test) - .OnlyWhenDynamic(() => IsRunningOnWindows) .Executes(() => { if (Configuration != Configuration.Release) @@ -59,59 +58,20 @@ public partial class Build .SetFileVersion(VersionPrefix) .SetInformationalVersion(VersionPrefix) .SetVersion(nugetVersion) - .SetConfiguration(Configuration) + // Some part of the pack (possibly the nuspec) does not lower-case the configuration when finding + // artifact directories like build does + .SetConfiguration(Configuration.ToString().ToLowerInvariant()) .SetOutputDirectory(ArtifactsDirectory) .SetDeterministic(IsServerBuild) .SetContinuousIntegrationBuild(IsServerBuild) ); } - Serilog.Log.Information("Build WiX installer"); - - (SourceDirectory / "NSwagStudio.Installer" / "bin").CreateOrCleanDirectory(); - - MSBuild(x => x - .SetTargetPath(GetProject("NSwagStudio.Installer")) - .SetTargets("Rebuild") - .SetAssemblyVersion(VersionPrefix) - .SetFileVersion(VersionPrefix) - .SetInformationalVersion(VersionPrefix) - .SetConfiguration(Configuration) - .SetMaxCpuCount(Environment.ProcessorCount) - .SetNodeReuse(IsLocalBuild) - .SetVerbosity(MSBuildVerbosity.Minimal) - .SetProperty("Deterministic", IsServerBuild) - .SetProperty("ContinuousIntegrationBuild", IsServerBuild) - ); - - // gather relevant artifacts - Serilog.Log.Information("Package nuspecs"); - - var apiDescriptionClientNuSpec = SourceDirectory / "NSwag.ApiDescription.Client" / "NSwag.ApiDescription.Client.nuspec"; - var content = apiDescriptionClientNuSpec.ReadAllText(); - content = content.Replace("", ""); - apiDescriptionClientNuSpec.WriteAllText(content); - - var nuspecs = new[] - { - apiDescriptionClientNuSpec, - SourceDirectory / "NSwag.MSBuild" / "NSwag.MSBuild.nuspec", - SourceDirectory / "NSwagStudio.Chocolatey" / "NSwagStudio.nuspec" - }; - - foreach (var nuspec in nuspecs) - { - NuGetPack(x => x - .SetOutputDirectory(ArtifactsDirectory) - .SetConfiguration(Configuration) - .SetVersion(nugetVersion) - .SetTargetPath(nuspec) - ); - } + // GitLab: Removed windows-only and other problematic and unnecessary packages var artifacts = Array.Empty() .Concat(RootDirectory.GlobFiles("**/Release/**/NSwag*.nupkg")) - .Concat(SourceDirectory.GlobFiles("**/Release/**/NSwagStudio.msi")); + ; foreach (var artifact in artifacts) { @@ -120,16 +80,13 @@ public partial class Build // patch npm version var npmPackagesFile = SourceDirectory / "NSwag.Npm" / "package.json"; - content = npmPackagesFile.ReadAllText(); + var content = npmPackagesFile.ReadAllText(); content = Regex.Replace(content, @"""version"": "".*""", @"""version"": """ + nugetVersion + @""""); npmPackagesFile.WriteAllText(content); // ZIP directories ZipFile.CreateFromDirectory(NSwagNpmBinaries, ArtifactsDirectory / "NSwag.Npm.zip"); ZipFile.CreateFromDirectory(NSwagStudioBinaries, ArtifactsDirectory / "NSwag.zip"); - - // NSwagStudio.msi - CopyFileToDirectory(ArtifactsDirectory / "bin" / "NSwagStudio.Installer" / Configuration / "NSwagStudio.msi", ArtifactsDirectory); }); } diff --git a/build/Build.cs b/build/Build.cs index fe6a75402..bb1e7ee0d 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Xml.Linq; @@ -145,6 +146,11 @@ protected override void OnBuildInitialized() .SetProcessWorkingDirectory(SourceDirectory / "NSwag.Npm") ); + DotNetRestore(x => x + .SetProjectFile(".gitlab") + .SetPackageDirectory(".gitlab/packages") + ); + DotNetRestore(x => x .SetProjectFile(SolutionFile) .SetVerbosity(DotNetVerbosity.minimal) @@ -230,6 +236,8 @@ protected override void OnBuildInitialized() .EnableNoRestore() .EnableNoBuild() .SetConfiguration(Configuration) + .SetLoggers("junit;MethodFormat=Full;FailureBodyFormat=Verbose") + .SetTestAdapterPath(".gitlab/packages/junitxml.testlogger/3.1.12/build/_common/") ); } }); diff --git a/src/NSwag.ConsoleCore.Tests/GenerateSampleSpecificationTests.cs b/src/NSwag.ConsoleCore.Tests/GenerateSampleSpecificationTests.cs index f9db6bf17..7a4246737 100644 --- a/src/NSwag.ConsoleCore.Tests/GenerateSampleSpecificationTests.cs +++ b/src/NSwag.ConsoleCore.Tests/GenerateSampleSpecificationTests.cs @@ -1,3 +1,4 @@ +using System; using System.Diagnostics; using System.IO; using System.Threading.Tasks; @@ -59,6 +60,8 @@ public async Task Should_generate_openapi_for_project(string projectName, string finally { process.Kill(); + // Process is not guaranteed to have ended when Kill returns + process.WaitForExit(); } // Assert