Skip to content

Commit

Permalink
Get build running on Linux and MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma committed Nov 27, 2023
1 parent 9175311 commit 809dec0
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ nswag.js text eol=lf
*.sass text
*.scm text
*.scss text
*.sh text
*.sh text eol=lf
*.sql text
*.styl text
*.tpl text
Expand Down
11 changes: 0 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,7 @@ jobs:
run: |
echo "Adding GNU tar to PATH"
echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%"
- uses: actions/setup-dotnet@v3
with:
dotnet-version: |
8.0.100
- uses: actions/checkout@v3
- name: 'Cache: .nuke/temp, ~/.nuget/packages'
uses: actions/cache@v3
with:
path: |
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('global.json', 'src/**/*.csproj', 'src/**/package.json') }}
- name: 'Run: InstallDependencies, Compile, Test, Pack, Publish'
run: ./build.cmd InstallDependencies Compile Test Pack Publish
env:
Expand Down
28 changes: 14 additions & 14 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ jobs:
windows-latest:
name: windows-latest
runs-on: windows-latest
concurrency:
group: ${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.run_id }}
cancel-in-progress: true
steps:
- name: 'Allow long file path'
run: git config --system core.longpaths true
Expand All @@ -41,17 +38,20 @@ jobs:
run: |
echo "Adding GNU tar to PATH"
echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%"
- uses: actions/setup-dotnet@v3
with:
dotnet-version: |
8.0.100
- uses: actions/checkout@v3
- name: 'Cache: .nuke/temp, ~/.nuget/packages'
uses: actions/cache@v3
with:
path: |
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('global.json', 'src/**/*.csproj', 'src/**/package.json') }}
- name: 'Run: InstallDependencies, Compile, Test, Pack'
run: ./build.cmd InstallDependencies Compile Test Pack
ubuntu-latest:
name: ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: 'Run: InstallDependencies, Compile, Test, Pack'
run: ./build.cmd InstallDependencies Compile Test Pack
macos-latest:
name: macos-latest
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: 'Run: InstallDependencies, Compile, Test, Pack'
run: ./build.cmd InstallDependencies Compile Test Pack
23 changes: 13 additions & 10 deletions build/Build.CI.GitHubActions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.CI.GitHubActions.Configuration;
Expand All @@ -7,29 +8,26 @@
[CustomGitHubActions(
"pr",
GitHubActionsImage.WindowsLatest,
// GitHubActionsImage.UbuntuLatest,
// GitHubActionsImage.MacOsLatest,
GitHubActionsImage.UbuntuLatest,
GitHubActionsImage.MacOsLatest,
OnPullRequestBranches = new[] { "master", "main" },
OnPullRequestIncludePaths = new[] { "**/*.*" },
OnPullRequestExcludePaths = new[] { "**/*.md" },
PublishArtifacts = false,
InvokedTargets = new[] { nameof(InstallDependencies), nameof(Compile), nameof(Test), nameof(Pack) },
CacheKeyFiles = new[] { "global.json", "src/**/*.csproj", "src/**/package.json" },
JobConcurrencyCancelInProgress = true),
CacheKeyFiles = new string[0])
]
[CustomGitHubActions(
"build",
GitHubActionsImage.WindowsLatest,
// GitHubActionsImage.UbuntuLatest,
// GitHubActionsImage.MacOsLatest,
OnPushBranches = new[] { "master", "main" },
OnPushTags = new[] { "v*.*.*" },
OnPushIncludePaths = new[] { "**/*.*" },
OnPushExcludePaths = new[] { "**/*.md" },
PublishArtifacts = true,
InvokedTargets = new[] { nameof(InstallDependencies), nameof(Compile), nameof(Test), nameof(Pack), nameof(Publish) },
ImportSecrets = new[] { "NUGET_API_KEY", "MYGET_API_KEY", "CHOCO_API_KEY", "NPM_AUTH_TOKEN" },
CacheKeyFiles = new[] { "global.json", "src/**/*.csproj", "src/**/package.json" })
CacheKeyFiles = new string[0])
]
public partial class Build
{
Expand All @@ -48,13 +46,18 @@ protected override GitHubActionsJob GetJobs(GitHubActionsImage image, IReadOnlyC
var newSteps = new List<GitHubActionsStep>(job.Steps);

// only need to list the ones that are missing from default image
/*
newSteps.Insert(0, new GitHubActionsSetupDotNetStep(new[]
{
"8.0.100"
}));

newSteps.Insert(0, new GitHubActionsUseGnuTarStep());
newSteps.Insert(0, new GitHubActionsConfigureLongPathsStep());
*/

if (image.ToString().StartsWith("windows", StringComparison.OrdinalIgnoreCase))
{
newSteps.Insert(0, new GitHubActionsUseGnuTarStep());
newSteps.Insert(0, new GitHubActionsConfigureLongPathsStep());
}

job.Steps = newSteps.ToArray();
return job;
Expand Down
48 changes: 23 additions & 25 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Build()
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;

[Solution] readonly Solution Solution;
[Solution] Solution Solution;
[GitRepository] readonly GitRepository GitRepository;

AbsolutePath SourceDirectory => RootDirectory / "src";
Expand Down Expand Up @@ -110,6 +110,15 @@ protected override void OnBuildInitialized()
Serilog.Log.Information("Version prefix:\t{VersionPrefix}", VersionPrefix);
Serilog.Log.Information("Version suffix:\t{VersionSuffix}",VersionSuffix);
Serilog.Log.Information("Tagged build:\t{IsTaggedBuild}", IsTaggedBuild);

if (!IsRunningOnWindows)
{
var solutionFile = SourceDirectory / "NSwag.Linux.slnf";
var deserializer = Type.GetType("Nuke.Common.ProjectModel.SolutionSerializer, Nuke.SolutionModel").NotNull().GetMethod("DeserializeFromFile").NotNull().MakeGenericMethod(typeof(Solution));
Solution = ((Solution) deserializer.Invoke(obj: null, new object[] { solutionFile })).NotNull();

Serilog.Log.Information("Detected non-Windows platform and switched to filtered solution file {SolutionFile}", Solution.FileName);
}
}

Target Clean => _ => _
Expand All @@ -122,6 +131,7 @@ protected override void OnBuildInitialized()

Target InstallDependencies => _ => _
.Before(Restore, Compile)
.OnlyWhenDynamic(() => !IsServerBuild)
.Executes(() =>
{
Chocolatey("install wixtoolset -y");
Expand All @@ -138,13 +148,16 @@ protected override void OnBuildInitialized()
.SetProcessWorkingDirectory(SourceDirectory / "NSwag.Npm")
);
MSBuild(x => x
.SetTargetPath(Solution)
.SetTargets("Restore")
.SetMaxCpuCount(Environment.ProcessorCount)
.SetNodeReuse(IsLocalBuild)
.SetVerbosity(MSBuildVerbosity.Minimal)
);
if (IsRunningOnWindows)
{
MSBuild(x => x
.SetTargetPath(Solution)
.SetTargets("Restore")
.SetMaxCpuCount(Environment.ProcessorCount)
.SetNodeReuse(IsLocalBuild)
.SetVerbosity(MSBuildVerbosity.Minimal)
);
}
DotNetRestore(x => x
.SetProjectFile(Solution)
Expand All @@ -162,22 +175,7 @@ protected override void OnBuildInitialized()
Serilog.Log.Information("Build and copy full .NET command line with configuration {Configuration}", Configuration);
// TODO: Fix build here
MSBuild(x => x
.SetProjectFile(GetProject("NSwagStudio"))
.SetTargets("Build")
.SetAssemblyVersion(VersionPrefix)
.SetFileVersion(VersionPrefix)
.SetInformationalVersion(VersionPrefix)
.SetConfiguration(Configuration)
.SetMaxCpuCount(Environment.ProcessorCount)
.SetNodeReuse(IsLocalBuild)
.SetVerbosity(MSBuildVerbosity.Minimal)
.SetProperty("Deterministic", IsServerBuild)
.SetProperty("ContinuousIntegrationBuild", IsServerBuild)
);
MSBuild(x => x
DotNetMSBuild(x => x
.SetTargetPath(Solution)
.SetTargets("Build")
.SetAssemblyVersion(VersionPrefix)
Expand All @@ -186,7 +184,7 @@ protected override void OnBuildInitialized()
.SetConfiguration(Configuration)
.SetMaxCpuCount(Environment.ProcessorCount)
.SetNodeReuse(IsLocalBuild)
.SetVerbosity(MSBuildVerbosity.Minimal)
.SetVerbosity(DotNetVerbosity.Minimal)
.SetProperty("Deterministic", IsServerBuild)
.SetProperty("ContinuousIntegrationBuild", IsServerBuild)
);
Expand Down
41 changes: 41 additions & 0 deletions src/NSwag.Linux.slnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"solution": {
"path": "NSwag.sln",
"projects": [
"..\\build\\_build.csproj",
"NSwag.Annotations\\NSwag.Annotations.csproj",
"NSwag.AspNet.Owin\\NSwag.AspNet.Owin.csproj",
"NSwag.AspNet.WebApi\\NSwag.AspNet.WebApi.csproj",
"NSwag.AspNetCore.Launcher.x86\\NSwag.AspNetCore.Launcher.x86.csproj",
"NSwag.AspNetCore.Launcher\\NSwag.AspNetCore.Launcher.csproj",
"NSwag.AspNetCore\\NSwag.AspNetCore.csproj",
"NSwag.CodeGeneration.CSharp.Tests\\NSwag.CodeGeneration.CSharp.Tests.csproj",
"NSwag.CodeGeneration.CSharp\\NSwag.CodeGeneration.CSharp.csproj",
"NSwag.CodeGeneration.Tests\\NSwag.CodeGeneration.Tests.csproj",
"NSwag.CodeGeneration.TypeScript.Tests\\NSwag.CodeGeneration.TypeScript.Tests.csproj",
"NSwag.CodeGeneration.TypeScript\\NSwag.CodeGeneration.TypeScript.csproj",
"NSwag.CodeGeneration\\NSwag.CodeGeneration.csproj",
"NSwag.Commands\\NSwag.Commands.csproj",
"NSwag.Console.x86\\NSwag.Console.x86.csproj",
"NSwag.ConsoleCore.Tests\\NSwag.ConsoleCore.Tests.csproj",
"NSwag.ConsoleCore\\NSwag.ConsoleCore.csproj",
"NSwag.Console\\NSwag.Console.csproj",
"NSwag.Core.Tests\\NSwag.Core.Tests.csproj",
"NSwag.Core.Yaml.Tests\\NSwag.Core.Yaml.Tests.csproj",
"NSwag.Core.Yaml\\NSwag.Core.Yaml.csproj",
"NSwag.Core\\NSwag.Core.csproj",
"NSwag.Generation.AspNetCore.Tests.Web\\NSwag.Generation.AspNetCore.Tests.Web.csproj",
"NSwag.Generation.AspNetCore.Tests\\NSwag.Generation.AspNetCore.Tests.csproj",
"NSwag.Generation.AspNetCore\\NSwag.Generation.AspNetCore.csproj",
"NSwag.Generation.Tests\\NSwag.Generation.Tests.csproj",
"NSwag.Generation.WebApi\\NSwag.Generation.WebApi.csproj",
"NSwag.Generation\\NSwag.Generation.csproj",
"NSwag.Sample.NET60Minimal\\NSwag.Sample.NET60Minimal.csproj",
"NSwag.Sample.NET60\\NSwag.Sample.NET60.csproj",
"NSwag.Sample.NET70Minimal\\NSwag.Sample.NET70Minimal.csproj",
"NSwag.Sample.NET70\\NSwag.Sample.NET70.csproj",
"NSwag.Sample.NET80Minimal\\NSwag.Sample.NET80Minimal.csproj",
"NSwag.Sample.NET80\\NSwag.Sample.NET80.csproj"
]
}
}

0 comments on commit 809dec0

Please sign in to comment.