Skip to content

Commit

Permalink
Change supported target frameworks
Browse files Browse the repository at this point in the history
* upgrade from net461 to net462
* drop support for net40, net45
* drop support for < netstandard2.0
* drop netcoreapp2.1, netcoreapp3.1 and net5.0
* upgrade NUKE
* switch back to using windows-latest GH Actions image which now has NET 6 support
  • Loading branch information
lahma committed May 29, 2023
1 parent 92b168a commit 414209f
Show file tree
Hide file tree
Showing 165 changed files with 632 additions and 9,106 deletions.
18 changes: 7 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ on:
- '!**/*.md'

jobs:
windows-2022:
name: windows-2022
runs-on: windows-2022
windows-latest:
name: windows-latest
runs-on: windows-latest
steps:
- name: 'Allow long file path'
run: git config --system core.longpaths true
Expand All @@ -40,27 +40,23 @@ 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: |
2.1.*
5.0.*
- uses: actions/checkout@v3
- name: Cache .nuke/temp, ~/.nuget/packages
- 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 './build.cmd InstallDependencies Compile Test Pack Publish'
- name: 'Run: InstallDependencies, Compile, Test, Pack, Publish'
run: ./build.cmd InstallDependencies Compile Test Pack Publish
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
MYGET_API_KEY: ${{ secrets.MYGET_API_KEY }}
CHOCO_API_KEY: ${{ secrets.CHOCO_API_KEY }}
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
- uses: actions/upload-artifact@v3
- name: 'Publish: artifacts'
uses: actions/upload-artifact@v3
with:
name: artifacts
path: artifacts
15 changes: 5 additions & 10 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ on:
- '!**/*.md'

jobs:
windows-2022:
name: windows-2022
runs-on: windows-2022
windows-latest:
name: windows-latest
runs-on: windows-latest
steps:
- name: 'Allow long file path'
run: git config --system core.longpaths true
Expand All @@ -38,18 +38,13 @@ 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: |
2.1.*
5.0.*
- uses: actions/checkout@v3
- name: Cache .nuke/temp, ~/.nuget/packages
- 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 './build.cmd InstallDependencies Compile Test Pack'
- name: 'Run: InstallDependencies, Compile, Test, Pack'
run: ./build.cmd InstallDependencies Compile Test Pack
4 changes: 2 additions & 2 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Build Schema",
"$ref": "#/definitions/build",
"title": "Build Schema",
"definitions": {
"build": {
"type": "object",
Expand Down Expand Up @@ -137,4 +137,4 @@
}
}
}
}
}
7 changes: 6 additions & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $TempDirectory = "$PSScriptRoot\\.nuke\temp"

$DotNetGlobalFile = "$PSScriptRoot\\global.json"
$DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1"
$DotNetChannel = "Current"
$DotNetChannel = "STS"

$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1
Expand Down Expand Up @@ -65,5 +65,10 @@ else {

Write-Output "Microsoft (R) .NET SDK version $(& $env:DOTNET_EXE --version)"

if (Test-Path env:NUKE_ENTERPRISE_TOKEN) {
& $env:DOTNET_EXE nuget remove source "nuke-enterprise" > $null
& $env:DOTNET_EXE nuget add source "https://f.feedz.io/nuke/enterprise/nuget" --name "nuke-enterprise" --username "PAT" --password $env:NUKE_ENTERPRISE_TOKEN > $null
}

ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet }
ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile --no-build -- $BuildArguments }
7 changes: 6 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TEMP_DIRECTORY="$SCRIPT_DIR//.nuke/temp"

DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json"
DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh"
DOTNET_CHANNEL="Current"
DOTNET_CHANNEL="STS"

export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
Expand Down Expand Up @@ -58,5 +58,10 @@ fi

echo "Microsoft (R) .NET SDK version $("$DOTNET_EXE" --version)"

if [[ ! -z ${NUKE_ENTERPRISE_TOKEN+x} && "NUKE_ENTERPRISE_TOKEN" != "" ]]; then
"$DOTNET_EXE" nuget remove source "nuke-enterprise" &>/dev/null || true
"$DOTNET_EXE" nuget add source "https://f.feedz.io/nuke/enterprise/nuget" --name "nuke-enterprise" --username "PAT" --password "$NUKE_ENTERPRISE_TOKEN" --store-password-in-clear-text &>/dev/null || true
fi

"$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet
"$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@"
12 changes: 2 additions & 10 deletions build/Build.CI.GitHubActions.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System.Collections.Generic;
using System.Linq;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.CI.GitHubActions.Configuration;
using Nuke.Common.Execution;
using Nuke.Common.Utilities;

[CustomGitHubActions(
"pr",
GitHubActionsImage.WindowsServer2022,
GitHubActionsImage.WindowsLatest,
// GitHubActionsImage.UbuntuLatest,
// GitHubActionsImage.MacOsLatest,
OnPullRequestBranches = new[] { "master", "main" },
Expand All @@ -19,7 +18,7 @@
]
[CustomGitHubActions(
"build",
GitHubActionsImage.WindowsServer2022,
GitHubActionsImage.WindowsLatest,
// GitHubActionsImage.UbuntuLatest,
// GitHubActionsImage.MacOsLatest,
OnPushBranches = new[] { "master", "main" },
Expand Down Expand Up @@ -47,13 +46,6 @@ 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[]
{
"2.1.*",
"5.0.*"
}));

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

Expand Down
12 changes: 6 additions & 6 deletions build/Build.Pack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public partial class Build
nugetVersion += "-" + VersionSuffix;
}

EnsureCleanDirectory(ArtifactsDirectory);
ArtifactsDirectory.CreateOrCleanDirectory();

// it seems to cause some headache with publishing, so let's dotnet pack only files we know are suitable
var projects = SourceDirectory.GlobFiles("**/*.csproj")
Expand Down Expand Up @@ -70,7 +70,7 @@ public partial class Build

Serilog.Log.Information("Build WiX installer");

EnsureCleanDirectory(SourceDirectory / "NSwagStudio.Installer" / "bin");
(SourceDirectory / "NSwagStudio.Installer" / "bin").CreateOrCleanDirectory();

MSBuild(x => x
.SetTargetPath(Solution.GetProject("NSwagStudio.Installer"))
Expand All @@ -90,9 +90,9 @@ public partial class Build
Serilog.Log.Information("Package nuspecs");

var apiDescriptionClientNuSpec = SourceDirectory / "NSwag.ApiDescription.Client" / "NSwag.ApiDescription.Client.nuspec";
var content = TextTasks.ReadAllText(apiDescriptionClientNuSpec);
var content = apiDescriptionClientNuSpec.ReadAllText();
content = content.Replace("<dependency id=\"NSwag.MSBuild\" version=\"1.0.0\" />", "<dependency id=\"NSwag.MSBuild\" version=\"" + VersionPrefix + "\" />");
TextTasks.WriteAllText(apiDescriptionClientNuSpec, content);
apiDescriptionClientNuSpec.WriteAllText(content);

var nuspecs = new[]
{
Expand Down Expand Up @@ -122,9 +122,9 @@ public partial class Build

// patch npm version
var npmPackagesFile = SourceDirectory / "NSwag.Npm" / "package.json";
content = TextTasks.ReadAllText(npmPackagesFile);
content = npmPackagesFile.ReadAllText();
content = Regex.Replace(content, @"""version"": "".*""", @"""version"": """ + VersionPrefix + @"""");
TextTasks.WriteAllText(npmPackagesFile, content);
npmPackagesFile.WriteAllText(content);

// ZIP directories
ZipFile.CreateFromDirectory(NSwagNpmBinaries, ArtifactsDirectory / "NSwag.Npm.zip");
Expand Down
54 changes: 25 additions & 29 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public Build()
[GitRepository] readonly GitRepository GitRepository;

AbsolutePath SourceDirectory => RootDirectory / "src";
AbsolutePath SamplesDirectory => RootDirectory / "samples";
AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";

AbsolutePath NSwagStudioBinaries => SourceDirectory / "NSwagStudio" / "bin" / Configuration;
Expand All @@ -75,11 +76,11 @@ string DetermineVersionPrefix()
if (!string.IsNullOrWhiteSpace(versionPrefix))
{
IsTaggedBuild = true;
Serilog.Log.Information($"Tag version {VersionPrefix} from Git found, using it as version prefix", versionPrefix);
Serilog.Log.Information("Tag version {VersionPrefix} from Git found, using it as version prefix", versionPrefix);
}
else
{
var propsDocument = XDocument.Parse(TextTasks.ReadAllText(SourceDirectory / "Directory.Build.props"));
var propsDocument = XDocument.Parse((SourceDirectory / "Directory.Build.props").ReadAllText());
versionPrefix = propsDocument.Element("Project").Element("PropertyGroup").Element("VersionPrefix").Value;
Serilog.Log.Information("Version prefix {VersionPrefix} read from Directory.Build.props", versionPrefix);
}
Expand Down Expand Up @@ -111,8 +112,9 @@ protected override void OnBuildInitialized()
.Before(Restore)
.Executes(() =>
{
SourceDirectory.GlobDirectories("**/bin", "**/obj").ForEach(DeleteDirectory);
EnsureCleanDirectory(ArtifactsDirectory);
SamplesDirectory.GlobDirectories("**/bin", "**/obj").ForEach(x => x.DeleteDirectory());
SourceDirectory.GlobDirectories("**/bin", "**/obj").ForEach(x => x.DeleteDirectory());
ArtifactsDirectory.CreateOrCleanDirectory();
});


Expand All @@ -121,7 +123,6 @@ protected override void OnBuildInitialized()
.Executes(() =>
{
Chocolatey("install wixtoolset -y");
Chocolatey("install netfx-4.6.1-devpack -y");
NpmInstall(x => x
.EnableGlobal()
.AddPackages("dotnettools")
Expand Down Expand Up @@ -159,8 +160,8 @@ protected override void OnBuildInitialized()
.DependsOn(Restore)
.Executes(() =>
{
EnsureCleanDirectory(SourceDirectory / "NSwag.Npm" / "bin" / "binaries");
EnsureCleanDirectory(NSwagStudioBinaries);
(SourceDirectory / "NSwag.Npm" / "bin" / "binaries").CreateOrCleanDirectory();
NSwagStudioBinaries.CreateOrCleanDirectory();

Serilog.Log.Information("Build and copy full .NET command line with configuration {Configuration}", Configuration);

Expand All @@ -171,7 +172,7 @@ protected override void OnBuildInitialized()
.SetFileVersion(VersionPrefix)
.SetInformationalVersion(VersionPrefix)
.SetConfiguration(Configuration)
.SetMaxCpuCount(Environment.ProcessorCount)
.SetMaxCpuCount(1) // wix's heat has problems
.SetNodeReuse(IsLocalBuild)
.SetVerbosity(MSBuildVerbosity.Minimal)
.SetProperty("Deterministic", IsServerBuild)
Expand Down Expand Up @@ -232,9 +233,6 @@ protected override void OnBuildInitialized()
// project name + runtime pairs
var dotnetTargets = new[]
{
("NSwag.Sample.NETCore21", "NetCore21"),
("NSwag.Sample.NETCore31", "NetCore31"),
("NSwag.Sample.NET50", "Net50"),
("NSwag.Sample.NET60", "Net60"),
("NSwag.Sample.NET60Minimal", "Net60"),
("NSwag.Sample.NET70", "Net70"),
Expand Down Expand Up @@ -291,7 +289,7 @@ void NSwagRun(
var nswagConfigurationFile = project.Directory / $"{configurationFile}.nswag";
var nswagSwaggerFile = project.Directory / $"{configurationFile}_swagger.json";

DeleteFile(nswagSwaggerFile);
nswagSwaggerFile.DeleteFile();

if (build)
{
Expand All @@ -317,14 +315,15 @@ void NSwagRun(
}

var samplesPath = RootDirectory / "samples";
var sampleSolution = ProjectModelTasks.ParseSolution(samplesPath / "Samples.sln");
NSwagRun(sampleSolution.GetProject("Sample.AspNetCore21"), "nswag_assembly", "NetCore21", Configuration.Release, true);
NSwagRun(sampleSolution.GetProject("Sample.AspNetCore21"), "nswag_project", "NetCore21", Configuration.Release, false);
NSwagRun(sampleSolution.GetProject("Sample.AspNetCore21"), "nswag_reflection", "NetCore21", Configuration.Release, true);

NSwagRun(sampleSolution.GetProject("Sample.AspNetCore21"), "nswag_assembly", "NetCore21", Configuration.Debug, true);
NSwagRun(sampleSolution.GetProject("Sample.AspNetCore21"), "nswag_project", "NetCore21", Configuration.Debug, false);
NSwagRun(sampleSolution.GetProject("Sample.AspNetCore21"), "nswag_reflection", "NetCore21", Configuration.Debug, true);
var sampleSolution = SolutionModelTasks.ParseSolution(samplesPath / "Samples.sln");
var sampleProject = sampleSolution.AllProjects.First(x => x.ProjectId == new Guid("55E2BF82-3ECE-45E2-96BD-65C09C42843D"));
NSwagRun(sampleProject, "nswag_assembly", "Net60", Configuration.Release, true);
NSwagRun(sampleProject, "nswag_project", "Net60", Configuration.Release, false);
NSwagRun(sampleProject, "nswag_reflection", "Net60", Configuration.Release, true);

NSwagRun(sampleProject, "nswag_assembly", "Net60", Configuration.Debug, true);
NSwagRun(sampleProject, "nswag_project", "Net60", Configuration.Debug, false);
NSwagRun(sampleProject, "nswag_reflection", "Net60", Configuration.Debug, true);
});

void PublishAndCopyConsoleProjects()
Expand All @@ -335,7 +334,7 @@ void PublishAndCopyConsoleProjects()

Serilog.Log.Information("Publish command line projects");

void PublishConsoleProject(Nuke.Common.ProjectModel.Project project, string[] targetFrameworks)
void PublishConsoleProject(Project project, string[] targetFrameworks)
{
foreach (var targetFramework in targetFrameworks)
{
Expand All @@ -352,23 +351,20 @@ void PublishConsoleProject(Nuke.Common.ProjectModel.Project project, string[] ta
}
}

PublishConsoleProject(consoleX86Project, new[] { "net461" });
PublishConsoleProject(consoleProject, new[] { "net461" });
PublishConsoleProject(consoleCoreProject, new[] { "netcoreapp2.1", "netcoreapp3.1", "net5.0", "net6.0", "net7.0" });
PublishConsoleProject(consoleX86Project, new[] { "net462" });
PublishConsoleProject(consoleProject, new[] { "net462" });
PublishConsoleProject(consoleCoreProject, new[] { "net6.0", "net7.0" });

void CopyConsoleBinaries(AbsolutePath target)
{
// take just exe from X86 as other files are shared with console project
var consoleX86Directory = consoleX86Project.Directory / "bin" / Configuration / "net461" / "publish";
var consoleX86Directory = consoleX86Project.Directory / "bin" / Configuration / "net462" / "publish";
CopyFileToDirectory(consoleX86Directory / "NSwag.x86.exe", target / "Win");
CopyFileToDirectory(consoleX86Directory / "NSwag.x86.exe.config", target / "Win");

CopyDirectoryRecursively(consoleProject.Directory / "bin" / Configuration / "net461" / "publish", target / "Win", DirectoryExistsPolicy.Merge);
CopyDirectoryRecursively(consoleProject.Directory / "bin" / Configuration / "net462" / "publish", target / "Win", DirectoryExistsPolicy.Merge);

var consoleCoreDirectory = consoleCoreProject.Directory / "bin" / Configuration;
CopyDirectoryRecursively(consoleCoreDirectory / "netcoreapp2.1" / "publish", target / "NetCore21");
CopyDirectoryRecursively(consoleCoreDirectory / "netcoreapp3.1" / "publish", target / "NetCore31");
CopyDirectoryRecursively(consoleCoreDirectory / "net5.0" / "publish", target / "Net50");
CopyDirectoryRecursively(consoleCoreDirectory / "net6.0" / "publish", target / "Net60");
CopyDirectoryRecursively(consoleCoreDirectory / "net7.0" / "publish", target / "Net70");
}
Expand Down
2 changes: 1 addition & 1 deletion build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nuke.Common" Version="6.3.0" />
<PackageReference Include="Nuke.Common" Version="7.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 414209f

Please sign in to comment.