Skip to content

Commit

Permalink
Added pull request CI
Browse files Browse the repository at this point in the history
  • Loading branch information
veler committed Apr 7, 2024
1 parent 6f8c304 commit 421ecf8
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 95 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/continuous_integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# ------------------------------------------------------------------------------
# <auto-generated>
#
# This code was generated.
#
# - To turn off auto-generation set:
#
# [GitHubActions (AutoGenerate = false)]
#
# - To trigger manual generation invoke:
#
# nuke --generate-configuration GitHubActions_continuous_integration --host GitHubActions
#
# </auto-generated>
# ------------------------------------------------------------------------------

name: continuous_integration

on: [push, pull_request]

jobs:
windows-latest:
name: windows-latest
runs-on: windows-latest
timeout-minutes: 30
steps:
- 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', '**/*.csproj', '**/Directory.Packages.props') }}
- name: 'Run: RunTests'
run: ./build.cmd RunTests
ubuntu-latest:
name: ubuntu-latest
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- 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', '**/*.csproj', '**/Directory.Packages.props') }}
- name: 'Run: RunTests'
run: ./build.cmd RunTests
macos-latest:
name: macos-latest
runs-on: macos-latest
timeout-minutes: 30
steps:
- 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', '**/*.csproj', '**/Directory.Packages.props') }}
- name: 'Run: RunTests'
run: ./build.cmd RunTests
28 changes: 4 additions & 24 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,6 @@
"type": "boolean",
"description": "Shows the execution plan (HTML)"
},
"PlatformTargets": {
"type": "array",
"description": "The target platform",
"items": {
"type": "string",
"enum": [
"CLI",
"Linux",
"MacOS",
"Wasm",
"Windows"
]
}
},
"Profile": {
"type": "array",
"description": "Defines the profiles to load",
Expand All @@ -88,25 +74,20 @@
"type": "string",
"description": "Root directory during build execution"
},
"RunTests": {
"type": "boolean",
"description": "Runs unit tests"
},
"Skip": {
"type": "array",
"description": "List of targets to be skipped. Empty list skips all dependencies",
"items": {
"type": "string",
"enum": [
"BuildGenerators",
"BuildPlugins",
"Clean",
"GenerateSdkNuGet",
"PreliminaryCheck",
"PublishApp",
"Restore",
"SetVersion",
"UnitTests"
"RunTests",
"SetVersion"
]
}
},
Expand All @@ -117,14 +98,13 @@
"type": "string",
"enum": [
"BuildGenerators",
"BuildPlugins",
"Clean",
"GenerateSdkNuGet",
"PreliminaryCheck",
"PublishApp",
"Restore",
"SetVersion",
"UnitTests"
"RunTests",
"SetVersion"
]
}
},
Expand Down
85 changes: 22 additions & 63 deletions src/build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using Nuke.Common;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
Expand All @@ -13,13 +13,20 @@
using Nuke.Common.Utilities.Collections;
using Serilog;
using static AppVersionTask;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.IO.PathConstruction;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static RestoreTask;
using Project = Nuke.Common.ProjectModel.Project;

#pragma warning disable IDE1006 // Naming Styles
[GitHubActions(
name: "continuous_integration",
GitHubActionsImage.WindowsLatest,
GitHubActionsImage.UbuntuLatest,
GitHubActionsImage.MacOsLatest,
On = [GitHubActionsTrigger.Push, GitHubActionsTrigger.PullRequest],
InvokedTargets = [nameof(RunTests)],
TimeoutMinutes = 30,
AutoGenerate = true)]
class Build : NukeBuild
{
/// Support plugins are available for:
Expand All @@ -33,12 +40,6 @@ class Build : NukeBuild
[Parameter("Configuration to build - Default is 'Release'")]
readonly Configuration Configuration = Configuration.Release;

[Parameter("The target platform")]
readonly PlatformTarget[]? PlatformTargets;

[Parameter("Runs unit tests")]
readonly bool RunTests;

[Solution]
readonly Solution? WindowsSolution;

Expand All @@ -52,30 +53,12 @@ class Build : NukeBuild
.Before(Clean)
.Executes(() =>
{
if (PlatformTargets == null || PlatformTargets.Length == 0)
{
Assert.Fail("Parameter `--platform-targets` is missing. Please check `build.sh --help`.");
return;
}
if (PlatformTargets.Contains(PlatformTarget.Windows) && !OperatingSystem.IsWindowsVersionAtLeast(10, 0, 0, 0))
if (OperatingSystem.IsWindows() && !OperatingSystem.IsWindowsVersionAtLeast(10, 0, 0, 0))
{
Assert.Fail("To build Windows app, you need to run on Windows 10 or later.");
return;
}
if (PlatformTargets.Contains(PlatformTarget.MacOS) && !OperatingSystem.IsMacOS())
{
Assert.Fail("To build macOS app, you need to run on macOS Ventura 13.1 or later.");
return;
}
if (PlatformTargets.Contains(PlatformTarget.Linux) && !OperatingSystem.IsLinux())
{
Assert.Fail("To build Linux app, you need to run on Linux.");
return;
}
Log.Information("Preliminary checks are successful.");
});

Expand Down Expand Up @@ -126,32 +109,12 @@ class Build : NukeBuild
.SetVerbosity(DotNetVerbosity.quiet)));
});

Target BuildPlugins => _ => _
Target RunTests => _ => _
.DependentFor(GenerateSdkNuGet)
.After(Restore)
.After(SetVersion)
.After(BuildGenerators)
.Executes(() =>
{
Log.Information($"Building plugins ...");
Project project = WindowsSolution!.GetAllProjects("DevToys.Tools").Single();
DotNetBuild(s => s
.SetProjectFile(project)
.SetConfiguration(Configuration)
.SetSelfContained(false)
.SetPublishTrimmed(false)
.SetVerbosity(DotNetVerbosity.quiet));
});

#pragma warning disable IDE0051 // Remove unused private members
Target UnitTests => _ => _
.DependentFor(GenerateSdkNuGet)
.After(Restore)
.After(SetVersion)
.After(BuildGenerators)
.After(BuildPlugins)
.OnlyWhenDynamic(() => RunTests)
.Executes(() =>
{
RootDirectory
.GlobFiles("**/*Tests.csproj")
Expand All @@ -161,7 +124,6 @@ class Build : NukeBuild
.SetConfiguration(Configuration)
.SetVerbosity(DotNetVerbosity.quiet)));
});
#pragma warning restore IDE0051 // Remove unused private members

Target GenerateSdkNuGet => _ => _
.Description("Generate the DevToys SDK NuGet package")
Expand All @@ -186,25 +148,22 @@ class Build : NukeBuild
.DependsOn(GenerateSdkNuGet)
.Executes(() =>
{
if (PlatformTargets!.Contains(PlatformTarget.Windows))
if (OperatingSystem.IsWindows())
{
PublishWindowsApp();
}
if (PlatformTargets!.Contains(PlatformTarget.MacOS))
if (OperatingSystem.IsMacOS())
{
PublishMacApp();
}
if (PlatformTargets!.Contains(PlatformTarget.Linux))
if (OperatingSystem.IsLinux())
{
PublishLinuxApp();
}
if (PlatformTargets!.Contains(PlatformTarget.CLI))
{
PublishCliApp();
}
PublishCliApp();
});

void PublishWindowsApp()
Expand Down Expand Up @@ -309,7 +268,7 @@ IEnumerable<DotnetParameters> GetDotnetParametersForCliApp()
string publishProject = "DevToys.CLI";
Project project;

if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
if (OperatingSystem.IsMacOS())
{
project = MacSolution!.GetProject(publishProject);
foreach (string targetFramework in project.GetTargetFrameworks())
Expand All @@ -321,7 +280,7 @@ IEnumerable<DotnetParameters> GetDotnetParametersForCliApp()
yield return new DotnetParameters(project.Path, "osx-arm64", targetFramework, portable: true);
}
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
else if (OperatingSystem.IsWindows())
{
project = WindowsSolution!.GetAllProjects(publishProject).Single();
foreach (string targetFramework in project.GetTargetFrameworks())
Expand All @@ -336,7 +295,7 @@ IEnumerable<DotnetParameters> GetDotnetParametersForCliApp()
yield return new DotnetParameters(project.Path, "win-x86", targetFramework, portable: true);
}
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
else if (OperatingSystem.IsLinux())
{
project = LinuxSolution!.GetAllProjects(publishProject).Single();
foreach (string targetFramework in project.GetTargetFrameworks())
Expand All @@ -355,7 +314,7 @@ IEnumerable<DotnetParameters> GetDotnetParametersForWindowsApp()
string publishProject = "DevToys.Windows";
Project project;

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (OperatingSystem.IsWindows())
{
project = WindowsSolution!.GetAllProjects(publishProject).Single();
foreach (string targetFramework in project.GetTargetFrameworks())
Expand All @@ -380,7 +339,7 @@ IEnumerable<DotnetParameters> GetDotnetParametersForLinuxApp()
string publishProject = "DevToys.Linux";
Project project;

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
if (OperatingSystem.IsLinux())
{
project = LinuxSolution!.GetAllProjects(publishProject).Single();
foreach (string targetFramework in project.GetTargetFrameworks())
Expand All @@ -403,7 +362,7 @@ IEnumerable<DotnetParameters> GetDotnetParametersForMacOSApp()
string publishProject = "DevToys.MacOS";
Project project;

if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
if (OperatingSystem.IsMacOS())
{
project = MacSolution!.GetAllProjects(publishProject).Single();
foreach (string targetFramework in project.GetTargetFrameworks())
Expand Down
8 changes: 0 additions & 8 deletions src/build/PlatformTarget.cs

This file was deleted.

0 comments on commit 421ecf8

Please sign in to comment.