diff --git a/.github/workflows/nuke-cicd.yml b/.github/workflows/nuke-cicd.yml index f8d545d5..746b4bb0 100644 --- a/.github/workflows/nuke-cicd.yml +++ b/.github/workflows/nuke-cicd.yml @@ -22,6 +22,9 @@ jobs: - id: NUKE_PRE_SETUP_HAS_RELEASE name: Output NUKE_PRE_SETUP_HAS_RELEASE run: echo "NUKE_PRE_SETUP_HAS_RELEASE=$(cat ./.nuke/temp/pre_setup_has_release.txt)" >> $GITHUB_OUTPUT + - id: NUKE_PRE_SETUP_HAS_ENTRIES + name: Output NUKE_PRE_SETUP_HAS_ENTRIES + run: echo "NUKE_PRE_SETUP_HAS_ENTRIES=$(cat ./.nuke/temp/pre_setup_has_entries.txt)" >> $GITHUB_OUTPUT - id: NUKE_PRE_SETUP_OUTPUT name: Output NUKE_PRE_SETUP_OUTPUT run: echo "NUKE_PRE_SETUP_OUTPUT=$(cat ./.nuke/temp/pre_setup_output.json)" >> $GITHUB_OUTPUT @@ -38,6 +41,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} outputs: NUKE_PRE_SETUP_HAS_RELEASE: ${{ steps.NUKE_PRE_SETUP_HAS_RELEASE.outputs.NUKE_PRE_SETUP_HAS_RELEASE }} + NUKE_PRE_SETUP_HAS_ENTRIES: ${{ steps.NUKE_PRE_SETUP_HAS_ENTRIES.outputs.NUKE_PRE_SETUP_HAS_ENTRIES }} NUKE_PRE_SETUP_OUTPUT: ${{ steps.NUKE_PRE_SETUP_OUTPUT.outputs.NUKE_PRE_SETUP_OUTPUT }} NUKE_PRE_SETUP_OUTPUT_TEST_MATRIX: ${{ steps.NUKE_PRE_SETUP_OUTPUT_TEST_MATRIX.outputs.NUKE_PRE_SETUP_OUTPUT_TEST_MATRIX }} NUKE_PRE_SETUP_OUTPUT_BUILD_MATRIX: ${{ steps.NUKE_PRE_SETUP_OUTPUT_BUILD_MATRIX.outputs.NUKE_PRE_SETUP_OUTPUT_BUILD_MATRIX }} @@ -63,13 +67,16 @@ jobs: runs-on: ${{ matrix.runs_on }} steps: - uses: actions/checkout@v4 + if: ${{ matrix.id != 'skip' }} - name: Run Nuke PipelineBuild run: ${{ matrix.build_script }} PipelineBuild --args "${{ matrix.ids_to_run }}" + if: ${{ matrix.id != 'skip' }} env: NUKE_NUGET_AUTH_TOKEN: ${{ secrets.NUGET_AUTH_TOKEN }} NUKE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Upload artifacts uses: actions/upload-artifact@v4 + if: ${{ matrix.id != 'skip' }} with: name: ${{ matrix.id }} path: ./.nuke/output/* @@ -78,7 +85,7 @@ jobs: needs: - pre_setup - test - if: ${{ needs.pre_setup.outputs.NUKE_PRE_SETUP_HAS_RELEASE == 'true' }} + if: ${{ needs.pre_setup.outputs.NUKE_PRE_SETUP_HAS_ENTRIES == 'true' }} env: NUKE_PRE_SETUP_OUTPUT: ${{ needs.pre_setup.outputs.NUKE_PRE_SETUP_OUTPUT }} strategy: @@ -89,14 +96,17 @@ jobs: runs-on: ${{ matrix.runs_on }} steps: - uses: actions/checkout@v4 + if: ${{ matrix.id != 'skip' }} - name: Download artifacts uses: actions/download-artifact@v4 + if: ${{ matrix.id != 'skip' }} with: path: ./.nuke/output pattern: ${{ matrix.id }} merge-multiple: true - name: Run Nuke PipelinePublish run: ${{ matrix.build_script }} PipelinePublish --args "${{ matrix.ids_to_run }}" + if: ${{ matrix.id != 'skip' }} env: NUKE_NUGET_AUTH_TOKEN: ${{ secrets.NUGET_AUTH_TOKEN }} NUKE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -104,7 +114,7 @@ jobs: - pre_setup - test - build - if: ${{ needs.pre_setup.outputs.NUKE_PRE_SETUP_HAS_RELEASE == 'true' }} + if: ${{ needs.pre_setup.outputs.NUKE_PRE_SETUP_HAS_ENTRIES == 'true' }} env: NUKE_PRE_SETUP_OUTPUT: ${{ needs.pre_setup.outputs.NUKE_PRE_SETUP_OUTPUT }} strategy: diff --git a/NukeBuildHelpers/AppEntry.cs b/NukeBuildHelpers/AppEntry.cs index e9d123cd..85c678e0 100644 --- a/NukeBuildHelpers/AppEntry.cs +++ b/NukeBuildHelpers/AppEntry.cs @@ -4,6 +4,7 @@ using Nuke.Common.IO; using NukeBuildHelpers.Common; using NukeBuildHelpers.Enums; +using NukeBuildHelpers.Models.RunContext; using System; using System.Collections.Generic; using System.Linq; @@ -19,13 +20,17 @@ public abstract class AppEntry : Entry public abstract RunsOnType PublishRunsOn { get; } + public virtual RunType RunBuildOn { get; } = RunType.Bump; + + public virtual RunType RunPublishOn { get; } = RunType.Bump; + public virtual bool MainRelease { get; } = true; - public NewVersion? NewVersion { get; internal set; } + public virtual void Build(AppRunContext appRunContext) { } - public virtual void Build() { } + public virtual void Publish(AppRunContext appRunContext) { } - public virtual void Publish() { } + internal AppRunContext? AppRunContext { get; set; } } public abstract class AppEntry : AppEntry diff --git a/NukeBuildHelpers/AppTestEntry.cs b/NukeBuildHelpers/AppTestEntry.cs index 22eff075..d1e8015b 100644 --- a/NukeBuildHelpers/AppTestEntry.cs +++ b/NukeBuildHelpers/AppTestEntry.cs @@ -8,6 +8,7 @@ using Nuke.Common.IO; using NukeBuildHelpers.Common; using NukeBuildHelpers.Enums; +using NukeBuildHelpers.Models.RunContext; namespace NukeBuildHelpers; @@ -15,11 +16,13 @@ public abstract class AppTestEntry : Entry { public abstract RunsOnType RunsOn { get; } - public virtual TestRunType RunType { get; } = TestRunType.Always; + public virtual RunTestType RunTestOn { get; } = RunTestType.All; - public abstract Type[] AppEntryTargets { get; } + public virtual Type[] AppEntryTargets { get; } = []; - public virtual void Run() { } + public virtual void Run(AppTestRunContext appTestContext) { } + + internal AppTestRunContext? AppTestContext { get; set; } } public abstract class AppTestEntry : AppTestEntry diff --git a/NukeBuildHelpers/BaseNukeBuildHelpers.Helpers.cs b/NukeBuildHelpers/BaseNukeBuildHelpers.Helpers.cs index 594c998d..0cbf6368 100644 --- a/NukeBuildHelpers/BaseNukeBuildHelpers.Helpers.cs +++ b/NukeBuildHelpers/BaseNukeBuildHelpers.Helpers.cs @@ -26,6 +26,7 @@ using ICSharpCode.SharpZipLib.Zip; using System; using System.Linq; +using NukeBuildHelpers.Models.RunContext; namespace NukeBuildHelpers; @@ -46,83 +47,164 @@ internal void SetupWorkflowBuilder(List workflowBuilders, Pipel } } - private void SetupWorkflowRun(List workflowSteps, Dictionary Tests)> appEntries, PreSetupOutput? preSetupOutput) + private void SetupWorkflowRun(List workflowSteps, AppConfig appConfig, PreSetupOutput? preSetupOutput) { var appEntrySecretMap = GetEntrySecretMap(); var appTestEntrySecretMap = GetEntrySecretMap(); PipelineType pipelineType; + IPipeline pipeline; + PipelineInfo pipelineInfo; + if (Host is AzurePipelines) { pipelineType = PipelineType.Azure; + pipeline = new AzurePipeline(this); } else if (Host is GitHubActions) { pipelineType = PipelineType.Github; + pipeline = new GithubPipeline(this); } else { throw new NotImplementedException(); } + pipelineInfo = pipeline.GetPipelineInfo(); + foreach (var workflowStep in workflowSteps) { workflowStep.PipelineType = pipelineType; workflowStep.NukeBuild = this; } - foreach (var appEntry in appEntries) + foreach (var appTestEntry in appConfig.AppTestEntries.Values) { - if (appEntrySecretMap.TryGetValue(appEntry.Value.Entry.Id, out var appSecretMap) && - appSecretMap.EntryType == appEntry.Value.Entry.GetType()) + if (appTestEntrySecretMap.TryGetValue(appTestEntry.Id, out var testSecretMap) && + testSecretMap.EntryType == appTestEntry.GetType()) { - foreach (var secret in appSecretMap.SecretHelpers) + foreach (var secret in testSecretMap.SecretHelpers) { var envVarName = string.IsNullOrEmpty(secret.SecretHelper.EnvironmentVariableName) ? "NUKE_" + secret.SecretHelper.SecretVariableName : secret.SecretHelper.EnvironmentVariableName; var secretValue = Environment.GetEnvironmentVariable(envVarName); - secret.MemberInfo.SetValue(appEntry.Value.Entry, secretValue); + secret.MemberInfo.SetValue(appTestEntry, secretValue); } } + appTestEntry.PipelineType = pipelineType; + appTestEntry.NukeBuild = this; + RunTestType runTestType = RunTestType.Local; + foreach (var appEntry in appConfig.AppEntries.Values) + { + if (appTestEntry.AppEntryTargets.Any(i => i == appEntry.GetType())) + { + runTestType = RunTestType.Target; + break; + } + } + appTestEntry.AppTestContext = new() + { + OutputDirectory = BaseHelper.OutputDirectory, + RunTestType = runTestType + }; + } - appEntry.Value.Entry.PipelineType = pipelineType; - appEntry.Value.Entry.NukeBuild = this; - - foreach (var appTestEntry in appEntry.Value.Tests) + RunType runType = RunType.Local; + if (preSetupOutput != null) + { + if (preSetupOutput.TriggerType == TriggerType.PullRequest) + { + runType = RunType.PullRequest; + } + else if (preSetupOutput.TriggerType == TriggerType.Commit) + { + runType = RunType.Commit; + } + else if (preSetupOutput.TriggerType == TriggerType.Tag) { - if (appTestEntrySecretMap.TryGetValue(appTestEntry.Id, out var testSecretMap) && - testSecretMap.EntryType == appTestEntry.GetType()) + if (preSetupOutput.HasRelease) { - foreach (var secret in testSecretMap.SecretHelpers) - { - var envVarName = string.IsNullOrEmpty(secret.SecretHelper.EnvironmentVariableName) ? "NUKE_" + secret.SecretHelper.SecretVariableName : secret.SecretHelper.EnvironmentVariableName; - var secretValue = Environment.GetEnvironmentVariable(envVarName); - secret.MemberInfo.SetValue(appTestEntry, secretValue); - } + runType = RunType.Bump; + } + else + { + runType = RunType.Commit; } - appTestEntry.PipelineType = pipelineType; - appTestEntry.NukeBuild = this; } - if (preSetupOutput != null && preSetupOutput.HasRelease) + } + + foreach (var appEntry in appConfig.AppEntries) + { + if (appEntrySecretMap.TryGetValue(appEntry.Value.Id, out var appSecretMap) && + appSecretMap.EntryType == appEntry.Value.GetType()) { - foreach (var release in preSetupOutput.Releases) + foreach (var secret in appSecretMap.SecretHelpers) { - if (appEntry.Value.Entry.Id == release.Key) - { - appEntry.Value.Entry.NewVersion = new NewVersion() - { - Environment = release.Value.Environment, - Version = SemVersion.Parse(release.Value.Version, SemVersionStyles.Strict), - BuildId = preSetupOutput.BuildId, - ReleaseNotes = preSetupOutput.ReleaseNotes - }; - } + var envVarName = string.IsNullOrEmpty(secret.SecretHelper.EnvironmentVariableName) ? "NUKE_" + secret.SecretHelper.SecretVariableName : secret.SecretHelper.EnvironmentVariableName; + var secretValue = Environment.GetEnvironmentVariable(envVarName); + secret.MemberInfo.SetValue(appEntry.Value, secretValue); } } + + appEntry.Value.PipelineType = pipelineType; + appEntry.Value.NukeBuild = this; + + AppVersion? appVersion = null; + + if (preSetupOutput != null && + preSetupOutput.Entries.TryGetValue(appEntry.Value.Id, out var preSetupOutputVersion)) + { + appVersion = new AppVersion() + { + AppId = appEntry.Value.Id, + Environment = preSetupOutputVersion.Environment, + Version = SemVersion.Parse(preSetupOutputVersion.Version, SemVersionStyles.Strict), + BuildId = preSetupOutput.BuildId, + ReleaseNotes = preSetupOutput.ReleaseNotes + }; + } + + if (appVersion == null) + { + appEntry.Value.AppRunContext = new AppLocalRunContext() + { + OutputDirectory = BaseHelper.OutputDirectory, + RunType = runType, + }; + } + else if (runType == RunType.Bump) + { + appEntry.Value.AppRunContext = new AppBumpRunContext() + { + OutputDirectory = BaseHelper.OutputDirectory, + RunType = runType, + AppVersion = appVersion + }; + } + else if (runType == RunType.PullRequest) + { + appEntry.Value.AppRunContext = new AppPullRequestRunContext() + { + OutputDirectory = BaseHelper.OutputDirectory, + RunType = runType, + AppVersion = appVersion, + PullRequestNumber = pipelineInfo.PullRequestNumber + }; + } + else + { + appEntry.Value.AppRunContext = new AppCommitRunContext() + { + OutputDirectory = BaseHelper.OutputDirectory, + RunType = runType, + AppVersion = appVersion + }; + } } } - private Task TestAppEntries(Dictionary Tests)> appEntries, IEnumerable idsToRun, PreSetupOutput? preSetupOutput) + private Task TestAppEntries(AppConfig appConfig, IEnumerable idsToRun, PreSetupOutput? preSetupOutput) { List tasks = []; List nonParallels = []; @@ -130,15 +212,16 @@ private Task TestAppEntries(Dictionary workflowSteps = [.. GetInstances().OrderByDescending(i => i.Priority)]; - SetupWorkflowRun(workflowSteps, appEntries, preSetupOutput); + SetupWorkflowRun(workflowSteps, appConfig, preSetupOutput); - foreach (var appEntry in appEntries) + foreach (var appEntry in appConfig.AppEntries) { if (idsToRun.Any() && !idsToRun.Any(i => i == appEntry.Key)) { continue; } - foreach (var appEntryTest in appEntry.Value.Tests) + var appEntryType = appEntry.Value.GetType(); + foreach (var appEntryTest in appConfig.AppTestEntries.Values.Where(i => i.AppEntryTargets.Any(j => j == appEntryType))) { if (idsToRun.Any() && !idsToRun.Any(i => i == appEntryTest.Id)) { @@ -157,7 +240,7 @@ private Task TestAppEntries(Dictionary Tests)> appEntries, IEnumerable idsToRun, PreSetupOutput? preSetupOutput) + private Task BuildAppEntries(AppConfig appConfig, IEnumerable idsToRun, PreSetupOutput? preSetupOutput) { List tasks = []; List nonParallels = []; List workflowSteps = [.. GetInstances().OrderByDescending(i => i.Priority)]; - SetupWorkflowRun(workflowSteps, appEntries, preSetupOutput); + SetupWorkflowRun(workflowSteps, appConfig, preSetupOutput); if (preSetupOutput != null) { @@ -200,21 +283,21 @@ private Task BuildAppEntries(Dictionary i == appEntry.Key)) { continue; } - if (appEntry.Value.Entry.RunParallel) + if (appEntry.Value.RunParallel) { tasks.Add(Task.Run(() => { foreach (var workflowStep in workflowSteps) { - workflowStep.AppBuild(appEntry.Value.Entry); + workflowStep.AppBuild(appEntry.Value); } - appEntry.Value.Entry.Build(); + appEntry.Value.Build(appEntry.Value.AppRunContext!); })); } else @@ -223,9 +306,9 @@ private Task BuildAppEntries(Dictionary Tests)> appEntries, IEnumerable idsToRun, PreSetupOutput? preSetupOutput) + private Task PublishAppEntries(AppConfig appConfig, IEnumerable idsToRun, PreSetupOutput? preSetupOutput) { List tasks = []; List nonParallels = []; List workflowSteps = [.. GetInstances().OrderByDescending(i => i.Priority)]; - SetupWorkflowRun(workflowSteps, appEntries, preSetupOutput); + SetupWorkflowRun(workflowSteps, appConfig, preSetupOutput); - foreach (var appEntry in appEntries) + foreach (var appEntry in appConfig.AppEntries) { if (idsToRun.Any() && !idsToRun.Any(i => i == appEntry.Key)) { continue; } - if (appEntry.Value.Entry.RunParallel) + if (appEntry.Value.RunParallel) { tasks.Add(Task.Run(() => { foreach (var workflowStep in workflowSteps) { - workflowStep.AppPublish(appEntry.Value.Entry); + workflowStep.AppPublish(appEntry.Value); } - appEntry.Value.Entry.Publish(); + appEntry.Value.Publish(appEntry.Value.AppRunContext!); })); } else @@ -273,9 +356,9 @@ private Task PublishAppEntries(Dictionary GetInstances() return instances; } - internal static Dictionary Tests)> GetAppEntryConfigs() + internal static AppConfig GetAppConfig() { - Dictionary Tests)> configs = []; + Dictionary appEntryConfigs = []; bool hasMainReleaseEntry = false; List appEntries = []; @@ -346,7 +429,7 @@ internal static List GetInstances() foreach (var appEntry in appEntries) { - if (configs.ContainsKey(appEntry.Id)) + if (appEntryConfigs.ContainsKey(appEntry.Id)) { throw new Exception($"Contains multiple app entry id \"{appEntry.Id}\""); } @@ -359,7 +442,7 @@ internal static List GetInstances() appTestEntries[i] = (true, appTestEntries[i].AppTestEntry); } } - configs.Add(appEntry.Id, (appEntry, appTestEntriesFound)); + appEntryConfigs.Add(appEntry.Id, new() { Entry = appEntry, Tests = appTestEntriesFound }); } var nonAdded = appTestEntries.Where(i => !i.IsAdded); @@ -378,7 +461,12 @@ internal static List GetInstances() } } - return configs; + return new() + { + AppEntryConfigs = appEntryConfigs, + AppEntries = appEntries.ToDictionary(i => i.Id), + AppTestEntries = appTestEntries.ToDictionary(i => i.AppTestEntry.Id, i => i.AppTestEntry) + }; } internal static Dictionary SecretHelpers)> GetEntrySecretMap() @@ -429,7 +517,7 @@ internal static List GetInstances() return entry; } - private AllVersions GetAllVersions(string appId, Dictionary Tests)> appEntryConfigs, ref IReadOnlyCollection? lsRemoteOutput) + private AllVersions GetAllVersions(string appId, Dictionary appEntryConfigs, ref IReadOnlyCollection? lsRemoteOutput) { GetOrFail(appId, appEntryConfigs, out _, out var appEntry); @@ -561,6 +649,7 @@ private AllVersions GetAllVersions(string appId, Dictionary(Func valFactory, out T valOut) } } - internal static void GetOrFail(string appId, Dictionary Tests)> appEntryConfigs, out string appIdOut, out (AppEntry Entry, List Tests) appEntryConfig) + internal static void GetOrFail(string appId, Dictionary appEntryConfigs, out string appIdOut, out AppEntryConfig appEntryConfig) { try { @@ -696,10 +785,11 @@ internal static void GetOrFail(string appId, Dictionary headers, params IEnumerable[] rows) { List<(int Length, string Text, HorizontalAlignment Alignment)> columns = []; @@ -871,7 +945,7 @@ private static int LogInfoTableWatch(IEnumerable<(string Text, HorizontalAlignme public async Task StartStatusWatch(bool cancelOnDone = false, params (string AppId, string Environment)[] appIds) { - GetOrFail(GetAppEntryConfigs, out var appEntryConfigs); + GetOrFail(GetAppConfig, out var appConfig); List<(string Text, HorizontalAlignment Alignment)> headers = [ @@ -900,15 +974,15 @@ public async Task StartStatusWatch(bool cancelOnDone = false, params (string App List<(string AppId, string Environment)> appIdsPassed = []; List<(string AppId, string Environment)> appIdsFailed = []; - foreach (var key in appEntryConfigs.Select(i => i.Key)) + foreach (var key in appConfig.AppEntryConfigs.Select(i => i.Key)) { string appId = key; - GetOrFail(appId, appEntryConfigs, out appId, out var appEntry); + GetOrFail(appId, appConfig.AppEntryConfigs, out appId, out var appEntry); AllVersions allVersions; try { - GetOrFail(() => GetAllVersions(appId, appEntryConfigs, ref lsRemote), out allVersions); + GetOrFail(() => GetAllVersions(appId, appConfig.AppEntryConfigs, ref lsRemote), out allVersions); } catch { diff --git a/NukeBuildHelpers/BaseNukeBuildHelpers.Targets.Pipeline.cs b/NukeBuildHelpers/BaseNukeBuildHelpers.Targets.Pipeline.cs index 0c9818d7..0e700502 100644 --- a/NukeBuildHelpers/BaseNukeBuildHelpers.Targets.Pipeline.cs +++ b/NukeBuildHelpers/BaseNukeBuildHelpers.Targets.Pipeline.cs @@ -33,9 +33,9 @@ partial class BaseNukeBuildHelpers .Executes(async () => { GetOrFail(() => SplitArgs, out var splitArgs); - GetOrFail(() => GetAppEntryConfigs(), out var appEntries); + GetOrFail(() => GetAppConfig(), out var appConfig); - await TestAppEntries(appEntries, splitArgs.Select(i => i.Key), GetPreSetupOutput()); + await TestAppEntries(appConfig, splitArgs.Select(i => i.Key), GetPreSetupOutput()); }); public Target PipelineBuild => _ => _ @@ -44,9 +44,9 @@ partial class BaseNukeBuildHelpers .Executes(async () => { GetOrFail(() => SplitArgs, out var splitArgs); - GetOrFail(() => GetAppEntryConfigs(), out var appEntries); + GetOrFail(() => GetAppConfig(), out var appConfig); - await BuildAppEntries(appEntries, splitArgs.Select(i => i.Key), GetPreSetupOutput()); + await BuildAppEntries(appConfig, splitArgs.Select(i => i.Key), GetPreSetupOutput()); }); public Target PipelinePublish => _ => _ @@ -55,9 +55,9 @@ partial class BaseNukeBuildHelpers .Executes(async () => { GetOrFail(() => SplitArgs, out var splitArgs); - GetOrFail(() => GetAppEntryConfigs(), out var appEntries); + GetOrFail(() => GetAppConfig(), out var appConfig); - await PublishAppEntries(appEntries, splitArgs.Select(i => i.Key), GetPreSetupOutput()); + await PublishAppEntries(appConfig, splitArgs.Select(i => i.Key), GetPreSetupOutput()); }); public Target PipelinePreSetup => _ => _ @@ -66,9 +66,7 @@ partial class BaseNukeBuildHelpers .Executes(() => { GetOrFail(() => SplitArgs, out var splitArgs); - GetOrFail(() => GetAppEntryConfigs(), out var appEntryConfigs); - GetOrFail(() => GetInstances(), out var appEntries); - GetOrFail(() => GetInstances(), out var appTestEntries); + GetOrFail(() => GetAppConfig(), out var appConfig); IPipeline pipeline = (Args?.ToLowerInvariant()) switch { @@ -97,17 +95,17 @@ partial class BaseNukeBuildHelpers IReadOnlyCollection? lsRemote = null; - List<(AppEntry AppEntry, string Env, SemVersion Version)> toRelease = []; + Dictionary toEntry = []; long targetBuildId = 0; long lastBuildId = 0; - foreach (var key in appEntryConfigs.Select(i => i.Key)) + foreach (var key in appConfig.AppEntryConfigs.Select(i => i.Key)) { string appId = key; - GetOrFail(appId, appEntryConfigs, out appId, out var appEntry); - GetOrFail(() => GetAllVersions(appId, appEntryConfigs, ref lsRemote), out var allVersions); + GetOrFail(appId, appConfig.AppEntryConfigs, out appId, out var appEntry); + GetOrFail(() => GetAllVersions(appId, appConfig.AppEntryConfigs, ref lsRemote), out var allVersions); if (allVersions.BuildIdCommitPaired.Count > 0) { @@ -115,11 +113,13 @@ partial class BaseNukeBuildHelpers lastBuildId = Math.Max(maxBuildId, lastBuildId); } - if (pipelineInfo.TriggerType == TriggerType.Tag && - allVersions.EnvSorted.Count != 0 && + if (allVersions.EnvSorted.Count != 0 && allVersions.EnvVersionGrouped.TryGetValue(envGroupKey, out var versionGroup) && versionGroup.Count > 0) { var lastVersionGroup = versionGroup.Last(); + + bool hasBumped = false; + if (!allVersions.EnvLatestVersionPaired.TryGetValue(envGroupKey, out var value) || value != lastVersionGroup) { if (allVersions.VersionBump.Contains(lastVersionGroup) && @@ -129,50 +129,79 @@ partial class BaseNukeBuildHelpers { allVersions.EnvLatestBuildIdPaired.TryGetValue(envGroupKey, out var allVersionLastId); targetBuildId = targetBuildId == 0 ? allVersionLastId : Math.Min(allVersionLastId, targetBuildId); - toRelease.Add((appEntry.Entry, env, lastVersionGroup)); - Log.Information("{appId} Tag: {current}, current latest: {latest}", appId, lastVersionGroup.ToString()); + if (pipelineInfo.TriggerType == TriggerType.Tag) + { + hasBumped = true; + Log.Information("{appId} Tag: {current}, current latest: {latest}", appId, lastVersionGroup.ToString()); + } } } else { - Log.Information("{appId} Tag: {current}, already latest", appId, lastVersionGroup.ToString()); + if (pipelineInfo.TriggerType == TriggerType.Tag) + { + Log.Information("{appId} Tag: {current}, already latest", appId, lastVersionGroup.ToString()); + } } + + toEntry.Add(appId, new() + { + AppEntry = appEntry.Entry, + Env = env, + Version = lastVersionGroup, + HasRelease = hasBumped + }); } } - foreach (var rel in toRelease) + foreach (var rel in toEntry.Values.Where(i => i.HasRelease)) { Log.Information("{appId} on {env} has new version {newVersion}", rel.AppEntry.Id, rel.Env, rel.Version); } - Dictionary releases = toRelease.ToDictionary(i => i.AppEntry.Id, i => new PreSetupOutputVersion() - { - AppId = i.AppEntry.Id, - AppName = i.AppEntry.Name, - Environment = i.Env, - Version = i.Version.ToString() - }); - var releaseNotes = ""; var buildId = lastBuildId + 1; var buildTag = "build." + buildId; var targetBuildTag = "build." + targetBuildId; var isFirstRelease = targetBuildId == 0; - var hasRelease = toRelease.Count != 0; + var hasEntries = toEntry.Count != 0; + var hasRelease = toEntry.Any(i => i.Value.HasRelease); + + string versionFactory(SemVersion version) + { + if (pipelineInfo.TriggerType == TriggerType.PullRequest) + { + return $"{version}+build.{buildId}-pr.{pipelineInfo.PullRequestNumber}"; + } + else + { + return $"{version}+build.{buildId}"; + } + } + + Dictionary entries = toEntry.Values.ToDictionary(i => i.AppEntry.Id, i => new PreSetupOutputVersion() + { + AppId = i.AppEntry.Id, + AppName = i.AppEntry.Name, + Environment = i.Env, + Version = versionFactory(i.Version), + HasRelease = i.HasRelease + }); if (hasRelease) { - foreach (var release in toRelease) + foreach (var entry in toEntry.Values.Where(i => i.HasRelease)) { - if (release.AppEntry.MainRelease) + var version = entry.Version.WithoutMetadata(); + if (entry.AppEntry.MainRelease) { - Git.Invoke("tag -f " + release.Version + "-queue"); - Git.Invoke("tag -f " + release.Version); + Git.Invoke("tag -f " + version + "-queue"); + Git.Invoke("tag -f " + version); } else { - Git.Invoke("tag -f " + release.AppEntry.Id.ToLowerInvariant() + "/" + release.Version + "-queue"); - Git.Invoke("tag -f " + release.AppEntry.Id.ToLowerInvariant() + "/" + release.Version); + Git.Invoke("tag -f " + entry.AppEntry.Id.ToLowerInvariant() + "/" + version + "-queue"); + Git.Invoke("tag -f " + entry.AppEntry.Id.ToLowerInvariant() + "/" + version); } } @@ -210,20 +239,22 @@ partial class BaseNukeBuildHelpers Branch = pipelineInfo.Branch, TriggerType = pipelineInfo.TriggerType, Environment = env, + HasEntries = hasEntries, HasRelease = hasRelease, ReleaseNotes = releaseNotes, IsFirstRelease = isFirstRelease, BuildId = buildId, LastBuildId = targetBuildId, - Releases = releases, + Entries = entries, }; File.WriteAllText(TemporaryDirectory / "pre_setup_output.json", JsonSerializer.Serialize(output, JsonExtension.SnakeCaseNamingOption)); + File.WriteAllText(TemporaryDirectory / "pre_setup_has_entries.txt", hasEntries ? "true" : "false"); File.WriteAllText(TemporaryDirectory / "pre_setup_has_release.txt", hasRelease ? "true" : "false"); Log.Information("NUKE_PRE_SETUP_OUTPUT: {output}", JsonSerializer.Serialize(output, JsonExtension.SnakeCaseNamingOptionIndented)); - pipeline.Prepare(output, appTestEntries, appEntryConfigs, toRelease); + pipeline.Prepare(output, appConfig, toEntry); }); public Target PipelinePostSetup => _ => _ @@ -232,7 +263,7 @@ partial class BaseNukeBuildHelpers .Executes(() => { GetOrFail(() => SplitArgs, out var splitArgs); - GetOrFail(() => GetAppEntryConfigs(), out var appEntryConfigs); + GetOrFail(() => GetAppConfig(), out var appConfig); var preSetupOutput = GetPreSetupOutput(); @@ -242,7 +273,7 @@ partial class BaseNukeBuildHelpers { foreach (var release in OutputDirectory.GetDirectories()) { - if (!preSetupOutput.Releases.TryGetValue(release.Name, out var preSetupOutputVersion)) + if (!preSetupOutput.Entries.TryGetValue(release.Name, out var preSetupOutputVersion)) { continue; } @@ -256,12 +287,13 @@ partial class BaseNukeBuildHelpers Log.Information("Publish: {name}", release.Name); } - foreach (var release in preSetupOutput.Releases.Values) + foreach (var release in preSetupOutput.Entries.Values) { - if (!appEntryConfigs.TryGetValue(release.AppId, out var appEntry)) + if (!appConfig.AppEntryConfigs.TryGetValue(release.AppId, out var appEntry)) { continue; } + var version = SemVersion.Parse(release.Version, SemVersionStyles.Strict).WithoutMetadata(); string latestTag = "latest"; if (!release.Environment.Equals("main", StringComparison.InvariantCultureIgnoreCase)) { @@ -269,14 +301,14 @@ partial class BaseNukeBuildHelpers } if (appEntry.Entry.MainRelease) { - Git.Invoke("tag -f " + release.Version + "-passed"); - Git.Invoke("tag -f " + release.Version); + Git.Invoke("tag -f " + version + "-passed"); + Git.Invoke("tag -f " + version); Git.Invoke("tag -f " + latestTag); } else { - Git.Invoke("tag -f " + appEntry.Entry.Id.ToLowerInvariant() + "/" + release.Version + "-passed"); - Git.Invoke("tag -f " + appEntry.Entry.Id.ToLowerInvariant() + "/" + release.Version); + Git.Invoke("tag -f " + appEntry.Entry.Id.ToLowerInvariant() + "/" + version + "-passed"); + Git.Invoke("tag -f " + appEntry.Entry.Id.ToLowerInvariant() + "/" + version); Git.Invoke("tag -f " + appEntry.Entry.Id.ToLowerInvariant() + "/" + latestTag); } } @@ -289,12 +321,13 @@ partial class BaseNukeBuildHelpers } else { - foreach (var release in preSetupOutput.Releases.Values) + foreach (var release in preSetupOutput.Entries.Values) { - if (!appEntryConfigs.TryGetValue(release.AppId, out var appEntry)) + if (!appConfig.AppEntryConfigs.TryGetValue(release.AppId, out var appEntry)) { continue; } + var version = SemVersion.Parse(release.Version, SemVersionStyles.Strict).WithoutMetadata(); string latestTag = "latest"; if (!release.Environment.Equals("main", StringComparison.InvariantCultureIgnoreCase)) { @@ -302,13 +335,13 @@ partial class BaseNukeBuildHelpers } if (appEntry.Entry.MainRelease) { - Git.Invoke("tag -f " + release.Version + "-failed"); - Git.Invoke("tag -f " + release.Version); + Git.Invoke("tag -f " + version + "-failed"); + Git.Invoke("tag -f " + version); } else { - Git.Invoke("tag -f " + appEntry.Entry.Id.ToLowerInvariant() + "/" + release.Version + "-failed"); - Git.Invoke("tag -f " + appEntry.Entry.Id.ToLowerInvariant() + "/" + release.Version); + Git.Invoke("tag -f " + appEntry.Entry.Id.ToLowerInvariant() + "/" + version + "-failed"); + Git.Invoke("tag -f " + appEntry.Entry.Id.ToLowerInvariant() + "/" + version); } } diff --git a/NukeBuildHelpers/BaseNukeBuildHelpers.Targets.User.Unlisted.cs b/NukeBuildHelpers/BaseNukeBuildHelpers.Targets.User.Unlisted.cs index 8c1ee9a3..e64aa98e 100644 --- a/NukeBuildHelpers/BaseNukeBuildHelpers.Targets.User.Unlisted.cs +++ b/NukeBuildHelpers/BaseNukeBuildHelpers.Targets.User.Unlisted.cs @@ -39,7 +39,7 @@ partial class BaseNukeBuildHelpers else { GetOrFail(() => SplitArgs, out var splitArgs); - GetOrFail(() => GetAppEntryConfigs(), out var appEntryConfigs); + GetOrFail(() => GetAppConfig(), out var appConfig); IReadOnlyCollection? lsRemote = null; @@ -47,8 +47,8 @@ partial class BaseNukeBuildHelpers { string appId = key; - GetOrFail(appId, appEntryConfigs, out appId, out var appEntry); - GetOrFail(() => GetAllVersions(appId, appEntryConfigs, ref lsRemote), out var allVersions); + GetOrFail(appId, appConfig.AppEntryConfigs, out appId, out var appEntry); + GetOrFail(() => GetAllVersions(appId, appConfig.AppEntryConfigs, ref lsRemote), out var allVersions); if (appEntry.Entry.MainRelease) { diff --git a/NukeBuildHelpers/BaseNukeBuildHelpers.Targets.User.cs b/NukeBuildHelpers/BaseNukeBuildHelpers.Targets.User.cs index c57f4f94..ddce233f 100644 --- a/NukeBuildHelpers/BaseNukeBuildHelpers.Targets.User.cs +++ b/NukeBuildHelpers/BaseNukeBuildHelpers.Targets.User.cs @@ -38,7 +38,7 @@ partial class BaseNukeBuildHelpers .Executes(() => { GetOrFail(() => SplitArgs, out var splitArgs); - GetOrFail(() => GetAppEntryConfigs(), out var appEntryConfigs); + GetOrFail(() => GetAppConfig(), out var appConfig); Log.Information("Commit: {Value}", Repository.Commit); Log.Information("Branch: {Value}", Repository.Branch); @@ -56,12 +56,12 @@ partial class BaseNukeBuildHelpers IReadOnlyCollection? lsRemote = null; - foreach (var key in splitArgs.Keys.Any() ? splitArgs.Keys.ToList() : appEntryConfigs.Select(i => i.Key)) + foreach (var key in splitArgs.Keys.Any() ? splitArgs.Keys.ToList() : appConfig.AppEntryConfigs.Select(i => i.Key)) { string appId = key; - GetOrFail(appId, appEntryConfigs, out appId, out var appEntry); - GetOrFail(() => GetAllVersions(appId, appEntryConfigs, ref lsRemote), out var allVersions); + GetOrFail(appId, appConfig.AppEntryConfigs, out appId, out var appEntry); + GetOrFail(() => GetAllVersions(appId, appConfig.AppEntryConfigs, ref lsRemote), out var allVersions); bool firstEntryRow = true; @@ -120,7 +120,7 @@ partial class BaseNukeBuildHelpers Assert.Fail($"{Repository.Branch} is not on environment branches"); } - GetOrFail(() => GetAppEntryConfigs(), out var appEntryConfigs); + GetOrFail(() => GetAppConfig(), out var appConfig); string currentEnvIdentifier; if (Repository.Branch.Equals(MainEnvironmentBranch, StringComparison.InvariantCultureIgnoreCase)) @@ -136,12 +136,12 @@ partial class BaseNukeBuildHelpers List<(AppEntry? AppEntry, AllVersions? AllVersions)> appEntryVersions = []; - foreach (var pair in appEntryConfigs) + foreach (var pair in appConfig.AppEntryConfigs) { string appId = pair.Key; - GetOrFail(appId, appEntryConfigs, out appId, out var appEntryConfig); - GetOrFail(() => GetAllVersions(appId, appEntryConfigs, ref lsRemote), out var allVersions); + GetOrFail(appId, appConfig.AppEntryConfigs, out appId, out var appEntryConfig); + GetOrFail(() => GetAllVersions(appId, appConfig.AppEntryConfigs, ref lsRemote), out var allVersions); appEntryVersions.Add((pair.Value.Entry, allVersions)); } @@ -318,9 +318,9 @@ await StartStatusWatch(true, appEntryVersionsToBump.Select(i => .Executes(async () => { GetOrFail(() => SplitArgs, out var splitArgs); - GetOrFail(() => GetAppEntryConfigs(), out var appEntries); + GetOrFail(() => GetAppConfig(), out var appConfig); - await TestAppEntries(appEntries, splitArgs.Select(i => i.Key), null); + await TestAppEntries(appConfig, splitArgs.Select(i => i.Key), null); }); public Target Build => _ => _ @@ -329,9 +329,9 @@ await StartStatusWatch(true, appEntryVersionsToBump.Select(i => .Executes(async () => { GetOrFail(() => SplitArgs, out var splitArgs); - GetOrFail(() => GetAppEntryConfigs(), out var appEntries); + GetOrFail(() => GetAppConfig(), out var appConfig); - await BuildAppEntries(appEntries, splitArgs.Select(i => i.Key), null); + await BuildAppEntries(appConfig, splitArgs.Select(i => i.Key), null); }); public Target Publish => _ => _ @@ -340,9 +340,9 @@ await StartStatusWatch(true, appEntryVersionsToBump.Select(i => .Executes(async () => { GetOrFail(() => SplitArgs, out var splitArgs); - GetOrFail(() => GetAppEntryConfigs(), out var appEntries); + GetOrFail(() => GetAppConfig(), out var appConfig); - await PublishAppEntries(appEntries, splitArgs.Select(i => i.Key), null); + await PublishAppEntries(appConfig, splitArgs.Select(i => i.Key), null); }); public Target GithubWorkflow => _ => _ diff --git a/NukeBuildHelpers/Common/EnumExtensions.cs b/NukeBuildHelpers/Common/EnumExtensions.cs new file mode 100644 index 00000000..6082f287 --- /dev/null +++ b/NukeBuildHelpers/Common/EnumExtensions.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NukeBuildHelpers.Common; + +internal static class EnumExtensions +{ + public static bool Has(this Enum type, T value) + { + try + { + return (((int)(object)type & (int)(object)value!) == (int)(object)value); + } + catch + { + return false; + } + } + + public static bool Is(this Enum type, T value) + { + try + { + return (int)(object)type == (int)(object)value!; + } + catch + { + return false; + } + } + + + public static T Add(this Enum type, T value) + { + try + { + return (T)(object)(((int)(object)type | (int)(object)value!)); + } + catch (Exception ex) + { + throw new ArgumentException( + string.Format( + "Could not append value from enumerated type '{0}'.", + typeof(T).Name + ), ex); + } + } + + + public static T Remove(this Enum type, T value) + { + try + { + return (T)(object)(((int)(object)type & ~(int)(object)value!)); + } + catch (Exception ex) + { + throw new ArgumentException( + string.Format( + "Could not remove value from enumerated type '{0}'.", + typeof(T).Name + ), ex); + } + } +} diff --git a/NukeBuildHelpers/Enums/TestRunType.cs b/NukeBuildHelpers/Enums/RunTestType.cs similarity index 53% rename from NukeBuildHelpers/Enums/TestRunType.cs rename to NukeBuildHelpers/Enums/RunTestType.cs index 07b5e2c0..e276c157 100644 --- a/NukeBuildHelpers/Enums/TestRunType.cs +++ b/NukeBuildHelpers/Enums/RunTestType.cs @@ -1,15 +1,16 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.Serialization; using System.Text; -using System.Text.Json.Serialization; using System.Threading.Tasks; namespace NukeBuildHelpers.Enums; -public enum TestRunType +[Flags] +public enum RunTestType { - Always, - OnAppEntryVersionBump + None = 0b00, + Local = 0b01, + Target = 0b10, + All = 0b11, } diff --git a/NukeBuildHelpers/Enums/RunType.cs b/NukeBuildHelpers/Enums/RunType.cs new file mode 100644 index 00000000..8fc8c3bc --- /dev/null +++ b/NukeBuildHelpers/Enums/RunType.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NukeBuildHelpers.Enums; + +[Flags] +public enum RunType +{ + None = 0b0000, + Local = 0b0001, + PullRequest = 0b0010, + Commit = 0b0100, + Bump = 0b1000, + All = 0b1111 +} diff --git a/NukeBuildHelpers/Interfaces/IPipeline.cs b/NukeBuildHelpers/Interfaces/IPipeline.cs index 73ae7e28..c00470eb 100644 --- a/NukeBuildHelpers/Interfaces/IPipeline.cs +++ b/NukeBuildHelpers/Interfaces/IPipeline.cs @@ -19,7 +19,7 @@ internal interface IPipeline PipelineInfo GetPipelineInfo(); - void Prepare(PreSetupOutput preSetupOutput, List appTestEntries, Dictionary Tests)> appEntryConfigs, List<(AppEntry AppEntry, string Env, SemVersion Version)> toRelease); + void Prepare(PreSetupOutput preSetupOutput, AppConfig appConfig, Dictionary toEntry); void BuildWorkflow(); } diff --git a/NukeBuildHelpers/Models/AppConfig.cs b/NukeBuildHelpers/Models/AppConfig.cs new file mode 100644 index 00000000..33d0161e --- /dev/null +++ b/NukeBuildHelpers/Models/AppConfig.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NukeBuildHelpers.Models; + +public class AppConfig +{ + public required Dictionary AppEntryConfigs { get; init; } + + public required Dictionary AppEntries { get; init; } + + public required Dictionary AppTestEntries { get; init; } +} diff --git a/NukeBuildHelpers/Models/AppEntryConfig.cs b/NukeBuildHelpers/Models/AppEntryConfig.cs new file mode 100644 index 00000000..a487e2fa --- /dev/null +++ b/NukeBuildHelpers/Models/AppEntryConfig.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NukeBuildHelpers.Models; + +public class AppEntryConfig +{ + public required AppEntry Entry { get; init; } + + public required List Tests { get; init; } +} diff --git a/NukeBuildHelpers/Models/AppRunEntry.cs b/NukeBuildHelpers/Models/AppRunEntry.cs new file mode 100644 index 00000000..e9db76b7 --- /dev/null +++ b/NukeBuildHelpers/Models/AppRunEntry.cs @@ -0,0 +1,19 @@ +using Semver; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NukeBuildHelpers.Models; + +internal class AppRunEntry +{ + public required AppEntry AppEntry { get; init; } + + public required string Env { get; init; } + + public required SemVersion Version { get; init; } + + public required bool HasRelease { get; init; } +} diff --git a/NukeBuildHelpers/Models/NewVersion.cs b/NukeBuildHelpers/Models/AppVersion.cs similarity index 88% rename from NukeBuildHelpers/Models/NewVersion.cs rename to NukeBuildHelpers/Models/AppVersion.cs index ad123032..b552126e 100644 --- a/NukeBuildHelpers/Models/NewVersion.cs +++ b/NukeBuildHelpers/Models/AppVersion.cs @@ -13,8 +13,10 @@ namespace NukeBuildHelpers; -public class NewVersion +public class AppVersion { + public required string AppId { get; init; } + public required string Environment { get; init; } public required SemVersion Version { get; init; } diff --git a/NukeBuildHelpers/Models/PipelineInfo.cs b/NukeBuildHelpers/Models/PipelineInfo.cs index e9c06f19..709d0bbc 100644 --- a/NukeBuildHelpers/Models/PipelineInfo.cs +++ b/NukeBuildHelpers/Models/PipelineInfo.cs @@ -13,4 +13,6 @@ public class PipelineInfo public required string Branch { get; init; } public required TriggerType TriggerType { get; init; } + + public required long PullRequestNumber { get; init; } } diff --git a/NukeBuildHelpers/Models/PreSetupOutput.cs b/NukeBuildHelpers/Models/PreSetupOutput.cs index 38c73bcc..8fac1a92 100644 --- a/NukeBuildHelpers/Models/PreSetupOutput.cs +++ b/NukeBuildHelpers/Models/PreSetupOutput.cs @@ -19,6 +19,8 @@ internal class PreSetupOutput public required TriggerType TriggerType { get; init; } + public required bool HasEntries { get; init; } + public required bool HasRelease { get; init; } public required string ReleaseNotes { get; init; } @@ -31,5 +33,5 @@ internal class PreSetupOutput public required string Environment { get; init; } - public required Dictionary Releases { get; init; } + public required Dictionary Entries { get; init; } } diff --git a/NukeBuildHelpers/Models/PreSetupOutputVersion.cs b/NukeBuildHelpers/Models/PreSetupOutputVersion.cs index 4f30e6f8..4a7e25ff 100644 --- a/NukeBuildHelpers/Models/PreSetupOutputVersion.cs +++ b/NukeBuildHelpers/Models/PreSetupOutputVersion.cs @@ -22,4 +22,6 @@ internal class PreSetupOutputVersion public required string Environment { get; init; } public required string Version { get; init; } + + public required bool HasRelease { get; init; } } diff --git a/NukeBuildHelpers/Models/RunContext/AppBumpRunContext.cs b/NukeBuildHelpers/Models/RunContext/AppBumpRunContext.cs new file mode 100644 index 00000000..38447a14 --- /dev/null +++ b/NukeBuildHelpers/Models/RunContext/AppBumpRunContext.cs @@ -0,0 +1,18 @@ +using Microsoft.Build.Tasks; +using Nuke.Common; +using Nuke.Common.IO; +using NukeBuildHelpers.Common; +using NukeBuildHelpers.Enums; +using Semver; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace NukeBuildHelpers.Models.RunContext; + +public class AppBumpRunContext : AppPipelineRunContext +{ +} diff --git a/NukeBuildHelpers/Models/RunContext/AppCommitRunContext.cs b/NukeBuildHelpers/Models/RunContext/AppCommitRunContext.cs new file mode 100644 index 00000000..c42d3b18 --- /dev/null +++ b/NukeBuildHelpers/Models/RunContext/AppCommitRunContext.cs @@ -0,0 +1,18 @@ +using Microsoft.Build.Tasks; +using Nuke.Common; +using Nuke.Common.IO; +using NukeBuildHelpers.Common; +using NukeBuildHelpers.Enums; +using Semver; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace NukeBuildHelpers.Models.RunContext; + +public class AppCommitRunContext : AppPipelineRunContext +{ +} diff --git a/NukeBuildHelpers/Models/RunContext/AppLocalRunContext.cs b/NukeBuildHelpers/Models/RunContext/AppLocalRunContext.cs new file mode 100644 index 00000000..8f8ed04a --- /dev/null +++ b/NukeBuildHelpers/Models/RunContext/AppLocalRunContext.cs @@ -0,0 +1,18 @@ +using Microsoft.Build.Tasks; +using Nuke.Common; +using Nuke.Common.IO; +using NukeBuildHelpers.Common; +using NukeBuildHelpers.Enums; +using Semver; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace NukeBuildHelpers.Models.RunContext; + +public class AppLocalRunContext : AppRunContext +{ +} diff --git a/NukeBuildHelpers/Models/RunContext/AppPipelineRunContext.cs b/NukeBuildHelpers/Models/RunContext/AppPipelineRunContext.cs new file mode 100644 index 00000000..be6b8f1f --- /dev/null +++ b/NukeBuildHelpers/Models/RunContext/AppPipelineRunContext.cs @@ -0,0 +1,19 @@ +using Microsoft.Build.Tasks; +using Nuke.Common; +using Nuke.Common.IO; +using NukeBuildHelpers.Common; +using NukeBuildHelpers.Enums; +using Semver; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace NukeBuildHelpers.Models.RunContext; + +public class AppPipelineRunContext : AppRunContext +{ + public required AppVersion AppVersion { get; init; } +} diff --git a/NukeBuildHelpers/Models/RunContext/AppPullRequestRunContext.cs b/NukeBuildHelpers/Models/RunContext/AppPullRequestRunContext.cs new file mode 100644 index 00000000..e7381a97 --- /dev/null +++ b/NukeBuildHelpers/Models/RunContext/AppPullRequestRunContext.cs @@ -0,0 +1,19 @@ +using Microsoft.Build.Tasks; +using Nuke.Common; +using Nuke.Common.IO; +using NukeBuildHelpers.Common; +using NukeBuildHelpers.Enums; +using Semver; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace NukeBuildHelpers.Models.RunContext; + +public class AppPullRequestRunContext : AppPipelineRunContext +{ + public long PullRequestNumber { get; internal set; } +} diff --git a/NukeBuildHelpers/Models/RunContext/AppRunContext.cs b/NukeBuildHelpers/Models/RunContext/AppRunContext.cs new file mode 100644 index 00000000..0595c7d7 --- /dev/null +++ b/NukeBuildHelpers/Models/RunContext/AppRunContext.cs @@ -0,0 +1,19 @@ +using Microsoft.Build.Tasks; +using Nuke.Common; +using Nuke.Common.IO; +using NukeBuildHelpers.Common; +using NukeBuildHelpers.Enums; +using Semver; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace NukeBuildHelpers.Models.RunContext; + +public abstract class AppRunContext : RunContext +{ + public required RunType RunType { get; init; } +} diff --git a/NukeBuildHelpers/Models/RunContext/AppTestRunContext.cs b/NukeBuildHelpers/Models/RunContext/AppTestRunContext.cs new file mode 100644 index 00000000..38911f7a --- /dev/null +++ b/NukeBuildHelpers/Models/RunContext/AppTestRunContext.cs @@ -0,0 +1,19 @@ +using Microsoft.Build.Tasks; +using Nuke.Common; +using Nuke.Common.IO; +using NukeBuildHelpers.Common; +using NukeBuildHelpers.Enums; +using Semver; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace NukeBuildHelpers.Models.RunContext; + +public class AppTestRunContext : RunContext +{ + public required RunTestType RunTestType { get; init; } +} diff --git a/NukeBuildHelpers/Models/RunContext/RunContext.cs b/NukeBuildHelpers/Models/RunContext/RunContext.cs new file mode 100644 index 00000000..6dac4d49 --- /dev/null +++ b/NukeBuildHelpers/Models/RunContext/RunContext.cs @@ -0,0 +1,19 @@ +using Microsoft.Build.Tasks; +using Nuke.Common; +using Nuke.Common.IO; +using NukeBuildHelpers.Common; +using NukeBuildHelpers.Enums; +using Semver; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace NukeBuildHelpers.Models.RunContext; + +public class RunContext +{ + public required AbsolutePath OutputDirectory { get; init; } +} diff --git a/NukeBuildHelpers/Pipelines/AzurePipeline.cs b/NukeBuildHelpers/Pipelines/AzurePipeline.cs index 1ab5f746..a9a0424c 100644 --- a/NukeBuildHelpers/Pipelines/AzurePipeline.cs +++ b/NukeBuildHelpers/Pipelines/AzurePipeline.cs @@ -35,6 +35,7 @@ public PipelineInfo GetPipelineInfo() { TriggerType triggerType = TriggerType.Commit; var branch = Environment.GetEnvironmentVariable("BUILD_SOURCEBRANCH"); + long prNumber = 0; if (string.IsNullOrEmpty(branch)) { branch = NukeBuild.Repository.Branch; @@ -43,6 +44,7 @@ public PipelineInfo GetPipelineInfo() { if (branch.StartsWith("refs/pull", StringComparison.InvariantCultureIgnoreCase)) { + prNumber = long.Parse(branch.Split('/')[2]); triggerType = TriggerType.PullRequest; branch = Environment.GetEnvironmentVariable("SYSTEM_PULLREQUEST_TARGETBRANCH")!; } @@ -69,72 +71,114 @@ public PipelineInfo GetPipelineInfo() { Branch = branch, TriggerType = triggerType, + PullRequestNumber = prNumber }; } - public void Prepare(PreSetupOutput preSetupOutput, List appTestEntries, Dictionary Tests)> appEntryConfigs, List<(AppEntry AppEntry, string Env, SemVersion Version)> toRelease) + public void Prepare(PreSetupOutput preSetupOutput, AppConfig appConfig, Dictionary toEntry) { var outputTestMatrix = new Dictionary(); var outputBuildMatrix = new Dictionary(); var outputPublishMatrix = new Dictionary(); - foreach (var appTestEntry in appTestEntries) + + foreach (var appEntryConfig in appConfig.AppEntryConfigs.Values) { - var appEntry = appEntryConfigs.First(i => i.Value.Tests.Any(j => j.Id == appTestEntry.Id)).Value.Entry; - var hasRelease = toRelease.Any(i => i.AppEntry.Id == appEntry.Id); - if (hasRelease || appTestEntry.RunType == TestRunType.Always) + if (!toEntry.TryGetValue(appEntryConfig.Entry.Id, out var entry)) + { + continue; + } + if ((preSetupOutput.TriggerType == TriggerType.PullRequest && appEntryConfig.Entry.RunBuildOn.HasFlag(RunType.PullRequest)) || + (preSetupOutput.TriggerType == TriggerType.Commit && appEntryConfig.Entry.RunBuildOn.HasFlag(RunType.Commit)) || + (preSetupOutput.TriggerType == TriggerType.Tag && appEntryConfig.Entry.RunBuildOn.HasFlag(RunType.Bump))) { - PreSetupOutputAppTestEntryMatrix preSetupOutputMatrix = new() + outputBuildMatrix.Add(appEntryConfig.Entry.Id, new() { - Id = appTestEntry.Id, - Name = appTestEntry.Name, + Id = appEntryConfig.Entry.Id, + Name = appEntryConfig.Entry.Name, Environment = preSetupOutput.Environment, - RunsOn = GetRunsOn(appTestEntry.RunsOn), - BuildScript = GetBuildScript(appTestEntry.RunsOn), - IdsToRun = $"{appEntry.Id};{appTestEntry.Id}" - }; - outputTestMatrix.Add(appTestEntry.Id, preSetupOutputMatrix); + RunsOn = GetRunsOn(appEntryConfig.Entry.BuildRunsOn), + BuildScript = GetBuildScript(appEntryConfig.Entry.BuildRunsOn), + IdsToRun = appEntryConfig.Entry.Id, + Version = entry.Version.ToString() + }); + } + if ((preSetupOutput.TriggerType == TriggerType.PullRequest && appEntryConfig.Entry.RunPublishOn.HasFlag(RunType.PullRequest)) || + (preSetupOutput.TriggerType == TriggerType.Commit && appEntryConfig.Entry.RunPublishOn.HasFlag(RunType.Commit)) || + (preSetupOutput.TriggerType == TriggerType.Tag && appEntryConfig.Entry.RunPublishOn.HasFlag(RunType.Bump))) + { + outputPublishMatrix.Add(appEntryConfig.Entry.Id, new() + { + Id = appEntryConfig.Entry.Id, + Name = appEntryConfig.Entry.Name, + Environment = preSetupOutput.Environment, + RunsOn = GetRunsOn(appEntryConfig.Entry.PublishRunsOn), + BuildScript = GetBuildScript(appEntryConfig.Entry.PublishRunsOn), + IdsToRun = appEntryConfig.Entry.Id, + Version = entry.Version.ToString() + }); } } - if (outputTestMatrix.Count == 0 && appTestEntries.Count != 0) + if (outputBuildMatrix.Count == 0) { - PreSetupOutputAppTestEntryMatrix preSetupOutputMatrix = new() + outputBuildMatrix.Add("skip", new() { Id = "skip", Name = "Skip", Environment = preSetupOutput.Environment, RunsOn = GetRunsOn(RunsOnType.Ubuntu2204), BuildScript = "", - IdsToRun = "" - }; - outputTestMatrix.Add("skip", preSetupOutputMatrix); + IdsToRun = "", + Version = "" + }); } - foreach (var (Entry, Tests) in appEntryConfigs.Values) + if (outputPublishMatrix.Count == 0) { - var release = toRelease.FirstOrDefault(i => i.AppEntry.Id == Entry.Id); - if (release.AppEntry != null) + outputPublishMatrix.Add("skip", new() { - outputBuildMatrix.Add(Entry.Id, new() - { - Id = Entry.Id, - Name = Entry.Name, - Environment = preSetupOutput.Environment, - RunsOn = GetRunsOn(Entry.BuildRunsOn), - BuildScript = GetBuildScript(Entry.BuildRunsOn), - IdsToRun = Entry.Id, - Version = release.Version.ToString() + "+build." + preSetupOutput.BuildId - }); - outputPublishMatrix.Add(Entry.Id, new() + Id = "skip", + Name = "Skip", + Environment = preSetupOutput.Environment, + RunsOn = GetRunsOn(RunsOnType.Ubuntu2204), + BuildScript = "", + IdsToRun = "", + Version = "" + }); + } + + foreach (var appTestEntry in appConfig.AppTestEntries.Values) + { + var appEntry = appConfig.AppEntries.Values.FirstOrDefault(i => appTestEntry.AppEntryTargets.Contains(i.GetType())); + if (appEntry == null) + { + continue; + } + if (appTestEntry.RunTestOn == RunTestType.All || + ((outputBuildMatrix.ContainsKey(appEntry.Id) || outputPublishMatrix.ContainsKey(appEntry.Id)) && appTestEntry.RunTestOn.HasFlag(RunTestType.Target))) + { + outputTestMatrix.Add(appTestEntry.Id, new() { - Id = Entry.Id, - Name = Entry.Name, + Id = appTestEntry.Id, + Name = appTestEntry.Name, Environment = preSetupOutput.Environment, - RunsOn = GetRunsOn(Entry.PublishRunsOn), - BuildScript = GetBuildScript(Entry.PublishRunsOn), - IdsToRun = Entry.Id, - Version = release.Version.ToString() + "+build." + preSetupOutput.BuildId + RunsOn = GetRunsOn(appTestEntry.RunsOn), + BuildScript = GetBuildScript(appTestEntry.RunsOn), + IdsToRun = $"{appEntry.Id};{appTestEntry.Id}" }); } } + if (outputTestMatrix.Count == 0) + { + outputTestMatrix.Add("skip", new() + { + Id = "skip", + Name = "Skip", + Environment = preSetupOutput.Environment, + RunsOn = GetRunsOn(RunsOnType.Ubuntu2204), + BuildScript = "", + IdsToRun = "" + }); + } + File.WriteAllText(Nuke.Common.NukeBuild.TemporaryDirectory / "pre_setup_output_test_matrix.json", JsonSerializer.Serialize(outputTestMatrix, JsonExtension.SnakeCaseNamingOption)); File.WriteAllText(Nuke.Common.NukeBuild.TemporaryDirectory / "pre_setup_output_build_matrix.json", JsonSerializer.Serialize(outputBuildMatrix, JsonExtension.SnakeCaseNamingOption)); File.WriteAllText(Nuke.Common.NukeBuild.TemporaryDirectory / "pre_setup_output_publish_matrix.json", JsonSerializer.Serialize(outputPublishMatrix, JsonExtension.SnakeCaseNamingOption)); @@ -145,9 +189,7 @@ public void Prepare(PreSetupOutput preSetupOutput, List appTestEnt public void BuildWorkflow() { - BaseNukeBuildHelpers.GetOrFail(BaseNukeBuildHelpers.GetAppEntryConfigs, out var appEntryConfigs); - BaseNukeBuildHelpers.GetOrFail(BaseNukeBuildHelpers.GetInstances, out var appEntries); - BaseNukeBuildHelpers.GetOrFail(BaseNukeBuildHelpers.GetInstances, out var appTestEntries); + BaseNukeBuildHelpers.GetOrFail(BaseNukeBuildHelpers.GetAppConfig, out var appConfig); List workflowBuilders = [.. BaseNukeBuildHelpers.GetInstances().OrderByDescending(i => i.Priority)]; @@ -193,6 +235,7 @@ public void BuildWorkflow() var nukePreSetupStep = AddJobStepNukeRun(preSetupJob, RunsOnType.Ubuntu2204, "PipelinePreSetup", "azure"); AddStepEnvVar(nukePreSetupStep, "GITHUB_TOKEN", "$(GITHUB_TOKEN)"); AddJobOutputFromFile(preSetupJob, "NUKE_PRE_SETUP_HAS_RELEASE", "./.nuke/temp/pre_setup_has_release.txt"); + AddJobOutputFromFile(preSetupJob, "NUKE_PRE_SETUP_HAS_ENTRIES", "./.nuke/temp/pre_setup_has_entries.txt"); AddJobOutputFromFile(preSetupJob, "NUKE_PRE_SETUP_OUTPUT", "./.nuke/temp/pre_setup_output.json"); AddJobOutputFromFile(preSetupJob, "NUKE_PRE_SETUP_OUTPUT_TEST_MATRIX", "./.nuke/temp/pre_setup_output_test_matrix.json"); AddJobOutputFromFile(preSetupJob, "NUKE_PRE_SETUP_OUTPUT_BUILD_MATRIX", "./.nuke/temp/pre_setup_output_build_matrix.json"); @@ -203,32 +246,29 @@ public void BuildWorkflow() // ██████████████████████████████████████ // ████████████████ Test ████████████████ // ██████████████████████████████████████ - if (appTestEntries.Count > 0) - { - var testJob = AddJob(workflow, "test", "Test", "$(runs_on)", needs: [.. needs], condition: "succeeded()"); - AddJobEnvVarFromNeeds(testJob, "NUKE_PRE_SETUP_OUTPUT", "pre_setup"); - AddJobMatrixIncludeFromPreSetup(testJob, "NUKE_PRE_SETUP_OUTPUT_TEST_MATRIX"); - AddJobStepCheckout(testJob, condition: "ne(variables['id'], 'skip')"); - AddJobStepsFromBuilder(testJob, workflowBuilders, (wb, step) => wb.WorkflowBuilderPreTestRun(step)); - var nukeTestStep = AddJobStepNukeRun(testJob, "$(build_script)", "PipelineTest", "$(ids_to_run)", condition: "ne(variables['id'], 'skip')"); - AddJobStepsFromBuilder(testJob, workflowBuilders, (wb, step) => wb.WorkflowBuilderPostTestRun(step)); - AddStepEnvVarFromSecretMap(nukeTestStep, appTestEntrySecretMap); - - needs.Add("test"); - } + var testJob = AddJob(workflow, "test", "Test", "$(runs_on)", needs: [.. needs], condition: "succeeded()"); + AddJobEnvVarFromNeeds(testJob, "NUKE_PRE_SETUP_OUTPUT", "pre_setup"); + AddJobMatrixIncludeFromPreSetup(testJob, "NUKE_PRE_SETUP_OUTPUT_TEST_MATRIX"); + AddJobStepCheckout(testJob, condition: "ne(variables['id'], 'skip')"); + AddJobStepsFromBuilder(testJob, workflowBuilders, (wb, step) => wb.WorkflowBuilderPreTestRun(step)); + var nukeTestStep = AddJobStepNukeRun(testJob, "$(build_script)", "PipelineTest", "$(ids_to_run)", condition: "ne(variables['id'], 'skip')"); + AddJobStepsFromBuilder(testJob, workflowBuilders, (wb, step) => wb.WorkflowBuilderPostTestRun(step)); + AddStepEnvVarFromSecretMap(nukeTestStep, appTestEntrySecretMap); + + needs.Add("test"); // ██████████████████████████████████████ // ███████████████ Build ████████████████ // ██████████████████████████████████████ - var buildJob = AddJob(workflow, "build", "Build", "$(runs_on)", needs: [.. needs], condition: "and(succeeded(), eq(dependencies.pre_setup.outputs['NUKE_PRE_SETUP_HAS_RELEASE.NUKE_PRE_SETUP_HAS_RELEASE'], 'true'))"); + var buildJob = AddJob(workflow, "build", "Build", "$(runs_on)", needs: [.. needs], condition: "and(succeeded(), eq(dependencies.pre_setup.outputs['NUKE_PRE_SETUP_HAS_ENTRIES.NUKE_PRE_SETUP_HAS_ENTRIES'], 'true'))"); AddJobMatrixIncludeFromPreSetup(buildJob, "NUKE_PRE_SETUP_OUTPUT_BUILD_MATRIX"); AddJobEnvVarFromNeeds(buildJob, "NUKE_PRE_SETUP_OUTPUT", "pre_setup"); - AddJobStepCheckout(buildJob); + AddJobStepCheckout(buildJob, condition: "ne(variables['id'], 'skip')"); AddJobStepsFromBuilder(buildJob, workflowBuilders, (wb, step) => wb.WorkflowBuilderPreBuildRun(step)); - var nukeBuildStep = AddJobStepNukeRun(buildJob, "$(build_script)", "PipelineBuild", "$(ids_to_run)"); + var nukeBuildStep = AddJobStepNukeRun(buildJob, "$(build_script)", "PipelineBuild", "$(ids_to_run)", condition: "ne(variables['id'], 'skip')"); AddStepEnvVarFromSecretMap(nukeBuildStep, appEntrySecretMap); AddJobStepsFromBuilder(buildJob, workflowBuilders, (wb, step) => wb.WorkflowBuilderPostBuildRun(step)); - var uploadBuildStep = AddJobStep(buildJob, displayName: "Upload artifacts", task: "PublishPipelineArtifact@1"); + var uploadBuildStep = AddJobStep(buildJob, displayName: "Upload artifacts", task: "PublishPipelineArtifact@1", condition: "ne(variables['id'], 'skip')"); AddJobStepInputs(uploadBuildStep, "artifact", "$(id)"); AddJobStepInputs(uploadBuildStep, "targetPath", "./.nuke/output"); AddJobStepInputs(uploadBuildStep, "continueOnError", "true"); @@ -238,16 +278,16 @@ public void BuildWorkflow() // ██████████████████████████████████████ // ██████████████ Publish ███████████████ // ██████████████████████████████████████ - var publishJob = AddJob(workflow, "publish", "Publish", "$(runs_on)", needs: [.. needs], condition: "and(succeeded(), eq(dependencies.pre_setup.outputs['NUKE_PRE_SETUP_HAS_RELEASE.NUKE_PRE_SETUP_HAS_RELEASE'], 'true'))"); + var publishJob = AddJob(workflow, "publish", "Publish", "$(runs_on)", needs: [.. needs], condition: "and(succeeded(), eq(dependencies.pre_setup.outputs['NUKE_PRE_SETUP_HAS_ENTRIES.NUKE_PRE_SETUP_HAS_ENTRIES'], 'true'))"); AddJobEnvVarFromNeeds(publishJob, "NUKE_PRE_SETUP_OUTPUT", "pre_setup"); AddJobMatrixIncludeFromPreSetup(publishJob, "NUKE_PRE_SETUP_OUTPUT_PUBLISH_MATRIX"); - AddJobStepCheckout(publishJob); - var downloadPublishStep = AddJobStep(publishJob, displayName: "Download artifacts", task: "DownloadPipelineArtifact@2"); + AddJobStepCheckout(publishJob, condition: "ne(variables['id'], 'skip')"); + var downloadPublishStep = AddJobStep(publishJob, displayName: "Download artifacts", task: "DownloadPipelineArtifact@2", condition: "ne(variables['id'], 'skip')"); AddJobStepInputs(downloadPublishStep, "artifact", "$(id)"); AddJobStepInputs(downloadPublishStep, "path", "./.nuke/output"); AddJobStepInputs(downloadPublishStep, "continueOnError", "true"); AddJobStepsFromBuilder(publishJob, workflowBuilders, (wb, step) => wb.WorkflowBuilderPrePublishRun(step)); - var nukePublishStep = AddJobStepNukeRun(publishJob, "$(build_script)", "PipelinePublish", "$(ids_to_run)"); + var nukePublishStep = AddJobStepNukeRun(publishJob, "$(build_script)", "PipelinePublish", "$(ids_to_run)", condition: "ne(variables['id'], 'skip')"); AddStepEnvVarFromSecretMap(nukePublishStep, appEntrySecretMap); AddJobStepsFromBuilder(publishJob, workflowBuilders, (wb, step) => wb.WorkflowBuilderPostPublishRun(step)); diff --git a/NukeBuildHelpers/Pipelines/GithubPipeline.cs b/NukeBuildHelpers/Pipelines/GithubPipeline.cs index b9be97ea..3d00b8d5 100644 --- a/NukeBuildHelpers/Pipelines/GithubPipeline.cs +++ b/NukeBuildHelpers/Pipelines/GithubPipeline.cs @@ -34,6 +34,7 @@ public PipelineInfo GetPipelineInfo() { TriggerType triggerType = TriggerType.Commit; var branch = Environment.GetEnvironmentVariable("GITHUB_REF"); + long prNumber = 0; if (string.IsNullOrEmpty(branch)) { branch = NukeBuild.Repository.Branch; @@ -42,6 +43,7 @@ public PipelineInfo GetPipelineInfo() { if (branch.StartsWith("refs/pull", StringComparison.InvariantCultureIgnoreCase)) { + prNumber = long.Parse(branch.Split('/')[2]); triggerType = TriggerType.PullRequest; branch = Environment.GetEnvironmentVariable("GITHUB_BASE_REF")!; } @@ -68,19 +70,89 @@ public PipelineInfo GetPipelineInfo() { Branch = branch, TriggerType = triggerType, + PullRequestNumber = prNumber, }; } - public void Prepare(PreSetupOutput preSetupOutput, List appTestEntries, Dictionary Tests)> appEntryConfigs, List<(AppEntry AppEntry, string Env, SemVersion Version)> toRelease) + public void Prepare(PreSetupOutput preSetupOutput, AppConfig appConfig, Dictionary toEntry) { var outputTestMatrix = new List(); var outputBuildMatrix = new List(); var outputPublishMatrix = new List(); - foreach (var appTestEntry in appTestEntries) + + foreach (var appEntryConfig in appConfig.AppEntryConfigs.Values) + { + if (!toEntry.TryGetValue(appEntryConfig.Entry.Id, out var entry)) + { + continue; + } + if ((preSetupOutput.TriggerType == TriggerType.PullRequest && appEntryConfig.Entry.RunBuildOn.HasFlag(RunType.PullRequest)) || + (preSetupOutput.TriggerType == TriggerType.Commit && appEntryConfig.Entry.RunBuildOn.HasFlag(RunType.Commit)) || + (preSetupOutput.TriggerType == TriggerType.Tag && appEntryConfig.Entry.RunBuildOn.HasFlag(RunType.Bump))) + { + outputBuildMatrix.Add(new() + { + Id = appEntryConfig.Entry.Id, + Name = appEntryConfig.Entry.Name, + Environment = preSetupOutput.Environment, + RunsOn = GetRunsOn(appEntryConfig.Entry.BuildRunsOn), + BuildScript = GetBuildScript(appEntryConfig.Entry.BuildRunsOn), + IdsToRun = appEntryConfig.Entry.Id, + Version = entry.Version.ToString() + }); + } + if ((preSetupOutput.TriggerType == TriggerType.PullRequest && appEntryConfig.Entry.RunPublishOn.HasFlag(RunType.PullRequest)) || + (preSetupOutput.TriggerType == TriggerType.Commit && appEntryConfig.Entry.RunPublishOn.HasFlag(RunType.Commit)) || + (preSetupOutput.TriggerType == TriggerType.Tag && appEntryConfig.Entry.RunPublishOn.HasFlag(RunType.Bump))) + { + outputPublishMatrix.Add(new() + { + Id = appEntryConfig.Entry.Id, + Name = appEntryConfig.Entry.Name, + Environment = preSetupOutput.Environment, + RunsOn = GetRunsOn(appEntryConfig.Entry.PublishRunsOn), + BuildScript = GetBuildScript(appEntryConfig.Entry.PublishRunsOn), + IdsToRun = appEntryConfig.Entry.Id, + Version = entry.Version.ToString() + }); + } + } + if (outputBuildMatrix.Count == 0) + { + outputBuildMatrix.Add(new() + { + Id = "skip", + Name = "Skip", + Environment = preSetupOutput.Environment, + RunsOn = GetRunsOn(RunsOnType.Ubuntu2204), + BuildScript = "", + IdsToRun = "", + Version = "" + }); + } + if (outputPublishMatrix.Count == 0) + { + outputPublishMatrix.Add(new() + { + Id = "skip", + Name = "Skip", + Environment = preSetupOutput.Environment, + RunsOn = GetRunsOn(RunsOnType.Ubuntu2204), + BuildScript = "", + IdsToRun = "", + Version = "" + }); + } + + foreach (var appTestEntry in appConfig.AppTestEntries.Values) { - var appEntry = appEntryConfigs.First(i => i.Value.Tests.Any(j => j.Id == appTestEntry.Id)).Value.Entry; - var hasRelease = toRelease.Any(i => i.AppEntry.Id == appEntry.Id); - if (hasRelease || appTestEntry.RunType == TestRunType.Always) + var appEntry = appConfig.AppEntries.Values.FirstOrDefault(i => appTestEntry.AppEntryTargets.Contains(i.GetType())); + if (appEntry == null) + { + continue; + } + if (appTestEntry.RunTestOn == RunTestType.All || + ((outputBuildMatrix.Any(i => i.Id == appEntry.Id) || outputPublishMatrix.Any(i => i.Id == appEntry.Id)) && appTestEntry.RunTestOn.HasFlag(RunTestType.Target))) { PreSetupOutputAppTestEntryMatrix preSetupOutputMatrix = new() { @@ -94,9 +166,9 @@ public void Prepare(PreSetupOutput preSetupOutput, List appTestEnt outputTestMatrix.Add(preSetupOutputMatrix); } } - if (outputTestMatrix.Count == 0 && appTestEntries.Count != 0) + if (outputTestMatrix.Count == 0) { - PreSetupOutputAppTestEntryMatrix preSetupOutputMatrix = new() + outputTestMatrix.Add(new() { Id = "skip", Name = "Skip", @@ -104,36 +176,9 @@ public void Prepare(PreSetupOutput preSetupOutput, List appTestEnt RunsOn = GetRunsOn(RunsOnType.Ubuntu2204), BuildScript = "", IdsToRun = "" - }; - outputTestMatrix.Add(preSetupOutputMatrix); - } - foreach (var (Entry, Tests) in appEntryConfigs.Values) - { - var release = toRelease.FirstOrDefault(i => i.AppEntry.Id == Entry.Id); - if (release.AppEntry != null) - { - outputBuildMatrix.Add(new() - { - Id = Entry.Id, - Name = Entry.Name, - Environment = preSetupOutput.Environment, - RunsOn = GetRunsOn(Entry.BuildRunsOn), - BuildScript = GetBuildScript(Entry.BuildRunsOn), - IdsToRun = Entry.Id, - Version = release.Version.ToString() + "+build." + preSetupOutput.BuildId - }); - outputPublishMatrix.Add(new() - { - Id = Entry.Id, - Name = Entry.Name, - Environment = preSetupOutput.Environment, - RunsOn = GetRunsOn(Entry.PublishRunsOn), - BuildScript = GetBuildScript(Entry.PublishRunsOn), - IdsToRun = Entry.Id, - Version = release.Version.ToString() + "+build." + preSetupOutput.BuildId - }); - } + }); } + File.WriteAllText(Nuke.Common.NukeBuild.TemporaryDirectory / "pre_setup_output_test_matrix.json", JsonSerializer.Serialize(outputTestMatrix, JsonExtension.SnakeCaseNamingOption)); File.WriteAllText(Nuke.Common.NukeBuild.TemporaryDirectory / "pre_setup_output_build_matrix.json", JsonSerializer.Serialize(outputBuildMatrix, JsonExtension.SnakeCaseNamingOption)); File.WriteAllText(Nuke.Common.NukeBuild.TemporaryDirectory / "pre_setup_output_publish_matrix.json", JsonSerializer.Serialize(outputPublishMatrix, JsonExtension.SnakeCaseNamingOption)); @@ -144,9 +189,7 @@ public void Prepare(PreSetupOutput preSetupOutput, List appTestEnt public void BuildWorkflow() { - BaseNukeBuildHelpers.GetOrFail(BaseNukeBuildHelpers.GetAppEntryConfigs, out var appEntryConfigs); - BaseNukeBuildHelpers.GetOrFail(BaseNukeBuildHelpers.GetInstances, out var appEntries); - BaseNukeBuildHelpers.GetOrFail(BaseNukeBuildHelpers.GetInstances, out var appTestEntries); + BaseNukeBuildHelpers.GetOrFail(BaseNukeBuildHelpers.GetAppConfig, out var appConfig); List workflowBuilders = [.. BaseNukeBuildHelpers.GetInstances().OrderByDescending(i => i.Priority)]; @@ -185,6 +228,7 @@ public void BuildWorkflow() AddJobStepCheckout(preSetupJob, fetchDepth: 0); AddJobStepNukeRun(preSetupJob, RunsOnType.Ubuntu2204, "PipelinePreSetup", "github"); AddJobOutputFromFile(preSetupJob, "NUKE_PRE_SETUP_HAS_RELEASE", "./.nuke/temp/pre_setup_has_release.txt"); + AddJobOutputFromFile(preSetupJob, "NUKE_PRE_SETUP_HAS_ENTRIES", "./.nuke/temp/pre_setup_has_entries.txt"); AddJobOutputFromFile(preSetupJob, "NUKE_PRE_SETUP_OUTPUT", "./.nuke/temp/pre_setup_output.json"); AddJobOutputFromFile(preSetupJob, "NUKE_PRE_SETUP_OUTPUT_TEST_MATRIX", "./.nuke/temp/pre_setup_output_test_matrix.json"); AddJobOutputFromFile(preSetupJob, "NUKE_PRE_SETUP_OUTPUT_BUILD_MATRIX", "./.nuke/temp/pre_setup_output_build_matrix.json"); @@ -195,32 +239,29 @@ public void BuildWorkflow() // ██████████████████████████████████████ // ████████████████ Test ████████████████ // ██████████████████████████████████████ - if (appTestEntries.Count > 0) - { - var testJob = AddJob(workflow, "test", "Test - ${{ matrix.name }}", "${{ matrix.runs_on }}", needs: [.. needs]); - AddJobOrStepEnvVarFromNeeds(testJob, "NUKE_PRE_SETUP_OUTPUT", "pre_setup"); - AddJobMatrixIncludeFromPreSetup(testJob, "NUKE_PRE_SETUP_OUTPUT_TEST_MATRIX"); - AddJobStepCheckout(testJob, _if: "${{ matrix.id != 'skip' }}"); - AddJobStepsFromBuilder(testJob, workflowBuilders, (wb, step) => wb.WorkflowBuilderPreTestRun(step)); - var nukeTestStep = AddJobStepNukeRun(testJob, "${{ matrix.build_script }}", "PipelineTest", "${{ matrix.ids_to_run }}", "${{ matrix.id != 'skip' }}"); - AddJobStepsFromBuilder(testJob, workflowBuilders, (wb, step) => wb.WorkflowBuilderPostTestRun(step)); - AddJobOrStepEnvVarFromSecretMap(nukeTestStep, appTestEntrySecretMap); - - needs.Add("test"); - } + var testJob = AddJob(workflow, "test", "Test - ${{ matrix.name }}", "${{ matrix.runs_on }}", needs: [.. needs]); + AddJobOrStepEnvVarFromNeeds(testJob, "NUKE_PRE_SETUP_OUTPUT", "pre_setup"); + AddJobMatrixIncludeFromPreSetup(testJob, "NUKE_PRE_SETUP_OUTPUT_TEST_MATRIX"); + AddJobStepCheckout(testJob, _if: "${{ matrix.id != 'skip' }}"); + AddJobStepsFromBuilder(testJob, workflowBuilders, (wb, step) => wb.WorkflowBuilderPreTestRun(step)); + var nukeTestStep = AddJobStepNukeRun(testJob, "${{ matrix.build_script }}", "PipelineTest", "${{ matrix.ids_to_run }}", _if: "${{ matrix.id != 'skip' }}"); + AddJobStepsFromBuilder(testJob, workflowBuilders, (wb, step) => wb.WorkflowBuilderPostTestRun(step)); + AddJobOrStepEnvVarFromSecretMap(nukeTestStep, appTestEntrySecretMap); + + needs.Add("test"); // ██████████████████████████████████████ // ███████████████ Build ████████████████ // ██████████████████████████████████████ - var buildJob = AddJob(workflow, "build", "Build - ${{ matrix.name }}", "${{ matrix.runs_on }}", needs: [.. needs], _if: "${{ needs.pre_setup.outputs.NUKE_PRE_SETUP_HAS_RELEASE == 'true' }}"); + var buildJob = AddJob(workflow, "build", "Build - ${{ matrix.name }}", "${{ matrix.runs_on }}", needs: [.. needs], _if: "${{ needs.pre_setup.outputs.NUKE_PRE_SETUP_HAS_ENTRIES == 'true' }}"); AddJobOrStepEnvVarFromNeeds(buildJob, "NUKE_PRE_SETUP_OUTPUT", "pre_setup"); AddJobMatrixIncludeFromPreSetup(buildJob, "NUKE_PRE_SETUP_OUTPUT_BUILD_MATRIX"); - AddJobStepCheckout(buildJob); + AddJobStepCheckout(buildJob, _if: "${{ matrix.id != 'skip' }}"); AddJobStepsFromBuilder(buildJob, workflowBuilders, (wb, step) => wb.WorkflowBuilderPreBuildRun(step)); - var nukeBuild = AddJobStepNukeRun(buildJob, "${{ matrix.build_script }}", "PipelineBuild", "${{ matrix.ids_to_run }}"); + var nukeBuild = AddJobStepNukeRun(buildJob, "${{ matrix.build_script }}", "PipelineBuild", "${{ matrix.ids_to_run }}", _if: "${{ matrix.id != 'skip' }}"); AddJobOrStepEnvVarFromSecretMap(nukeBuild, appEntrySecretMap); AddJobStepsFromBuilder(buildJob, workflowBuilders, (wb, step) => wb.WorkflowBuilderPostBuildRun(step)); - var uploadBuildStep = AddJobStep(buildJob, name: "Upload artifacts", uses: "actions/upload-artifact@v4"); + var uploadBuildStep = AddJobStep(buildJob, name: "Upload artifacts", uses: "actions/upload-artifact@v4", _if: "${{ matrix.id != 'skip' }}"); AddJobStepWith(uploadBuildStep, "name", "${{ matrix.id }}"); AddJobStepWith(uploadBuildStep, "path", "./.nuke/output/*"); AddJobStepWith(uploadBuildStep, "if-no-files-found", "error"); @@ -231,16 +272,16 @@ public void BuildWorkflow() // ██████████████████████████████████████ // ██████████████ Publish ███████████████ // ██████████████████████████████████████ - var publishJob = AddJob(workflow, "publish", "Publish - ${{ matrix.name }}", "${{ matrix.runs_on }}", needs: [.. needs], _if: "${{ needs.pre_setup.outputs.NUKE_PRE_SETUP_HAS_RELEASE == 'true' }}"); + var publishJob = AddJob(workflow, "publish", "Publish - ${{ matrix.name }}", "${{ matrix.runs_on }}", needs: [.. needs], _if: "${{ needs.pre_setup.outputs.NUKE_PRE_SETUP_HAS_ENTRIES == 'true' }}"); AddJobOrStepEnvVarFromNeeds(publishJob, "NUKE_PRE_SETUP_OUTPUT", "pre_setup"); AddJobMatrixIncludeFromPreSetup(publishJob, "NUKE_PRE_SETUP_OUTPUT_PUBLISH_MATRIX"); - AddJobStepCheckout(publishJob); - var downloadBuildStep = AddJobStep(publishJob, name: "Download artifacts", uses: "actions/download-artifact@v4"); + AddJobStepCheckout(publishJob, _if: "${{ matrix.id != 'skip' }}"); + var downloadBuildStep = AddJobStep(publishJob, name: "Download artifacts", uses: "actions/download-artifact@v4", _if: "${{ matrix.id != 'skip' }}"); AddJobStepWith(downloadBuildStep, "path", "./.nuke/output"); AddJobStepWith(downloadBuildStep, "pattern", "${{ matrix.id }}"); AddJobStepWith(downloadBuildStep, "merge-multiple", "true"); AddJobStepsFromBuilder(publishJob, workflowBuilders, (wb, step) => wb.WorkflowBuilderPrePublishRun(step)); - var nukePublishTask = AddJobStepNukeRun(publishJob, "${{ matrix.build_script }}", "PipelinePublish", "${{ matrix.ids_to_run }}"); + var nukePublishTask = AddJobStepNukeRun(publishJob, "${{ matrix.build_script }}", "PipelinePublish", "${{ matrix.ids_to_run }}", _if: "${{ matrix.id != 'skip' }}"); AddJobOrStepEnvVarFromSecretMap(nukePublishTask, appEntrySecretMap); AddJobStepsFromBuilder(publishJob, workflowBuilders, (wb, step) => wb.WorkflowBuilderPostPublishRun(step)); diff --git a/build/NugetBuildHelpers.cs b/build/NugetBuildHelpers.cs index 69a8b718..effcb2d5 100644 --- a/build/NugetBuildHelpers.cs +++ b/build/NugetBuildHelpers.cs @@ -6,6 +6,7 @@ using NukeBuildHelpers; using NukeBuildHelpers.Attributes; using NukeBuildHelpers.Enums; +using NukeBuildHelpers.Models.RunContext; using Serilog; using System; using System.Collections.Generic; @@ -22,16 +23,25 @@ public class NugetBuildHelpers : AppEntry public override RunsOnType PublishRunsOn => RunsOnType.Ubuntu2204; + public override RunType RunBuildOn => RunType.All; + + public override RunType RunPublishOn => RunType.All; + [SecretHelper("NUGET_AUTH_TOKEN")] - readonly string NuGetAuthToken; + readonly string? NuGetAuthToken; [SecretHelper("GITHUB_TOKEN")] - readonly string GithubToken; + readonly string? GithubToken; public override bool RunParallel => false; - public override void Build() + public override void Build(AppRunContext appRunContext) { + AppVersion? appVersion = null; + if (appRunContext is AppPipelineRunContext appPipelineRunContext) + { + appVersion = appPipelineRunContext.AppVersion; + } OutputDirectory.DeleteDirectory(); DotNetTasks.DotNetClean(_ => _ .SetProject(NukeBuild.Solution.NukeBuildHelpers)); @@ -45,20 +55,23 @@ public override void Build() .SetNoBuild(true) .SetIncludeSymbols(true) .SetSymbolPackageFormat("snupkg") - .SetVersion(NewVersion?.Version?.ToString() ?? "0.0.0") - .SetPackageReleaseNotes(NewVersion?.ReleaseNotes) + .SetVersion(appVersion?.Version?.ToString() ?? "0.0.0") + .SetPackageReleaseNotes(appVersion?.ReleaseNotes) .SetOutputDirectory(OutputDirectory)); } - public override void Publish() + public override void Publish(AppRunContext appRunContext) { - DotNetTasks.DotNetNuGetPush(_ => _ - .SetSource("https://nuget.pkg.github.com/kiryuumaru/index.json") - .SetApiKey(GithubToken) - .SetTargetPath(OutputDirectory / "**")); - DotNetTasks.DotNetNuGetPush(_ => _ - .SetSource("https://api.nuget.org/v3/index.json") - .SetApiKey(NuGetAuthToken) - .SetTargetPath(OutputDirectory / "**")); + if (appRunContext.RunType == RunType.Bump) + { + DotNetTasks.DotNetNuGetPush(_ => _ + .SetSource("https://nuget.pkg.github.com/kiryuumaru/index.json") + .SetApiKey(GithubToken) + .SetTargetPath(OutputDirectory / "**")); + DotNetTasks.DotNetNuGetPush(_ => _ + .SetSource("https://api.nuget.org/v3/index.json") + .SetApiKey(NuGetAuthToken) + .SetTargetPath(OutputDirectory / "**")); + } } } diff --git a/build/NugetBuildHelpers2.cs b/build/NugetBuildHelpers2.cs index c7c82762..7c55dbd6 100644 --- a/build/NugetBuildHelpers2.cs +++ b/build/NugetBuildHelpers2.cs @@ -3,6 +3,7 @@ using Nuke.Common.Tools.DotNet; using NukeBuildHelpers; using NukeBuildHelpers.Enums; +using NukeBuildHelpers.Models.RunContext; using Serilog; using System; using System.Collections.Generic; @@ -18,12 +19,21 @@ public class NugetBuildHelpers2 : AppEntry public override RunsOnType PublishRunsOn => RunsOnType.WindowsLatest; + public override RunType RunBuildOn => RunType.None; + + public override RunType RunPublishOn => RunType.None; + public override bool MainRelease => false; public override bool RunParallel => false; - public override void Build() + public override void Build(AppRunContext appRunContext) { + AppVersion? appVersion = null; + if (appRunContext is AppPipelineRunContext appPipelineRunContext) + { + appVersion = appPipelineRunContext.AppVersion; + } OutputDirectory.DeleteDirectory(); DotNetTasks.DotNetClean(_ => _ .SetProject(NukeBuild.Solution.NukeBuildHelpers)); @@ -37,16 +47,19 @@ public override void Build() .SetNoBuild(true) .SetIncludeSymbols(true) .SetSymbolPackageFormat("snupkg") - .SetVersion(NewVersion?.Version.ToString() ?? "0.0.0") - .SetPackageReleaseNotes("* Initial prerelease") + .SetVersion(appVersion?.Version?.ToString() ?? "0.0.0") + .SetPackageReleaseNotes(appVersion?.ReleaseNotes) .SetOutputDirectory(OutputDirectory)); } - public override void Publish() + public override void Publish(AppRunContext appRunContext) { - foreach (var ss in OutputDirectory.GetFiles()) + if (appRunContext.RunType == RunType.Bump) { - Log.Information("Publish: {name}", ss.Name); + foreach (var ss in OutputDirectory.GetFiles()) + { + Log.Information("Publish: {name}", ss.Name); + } } } } diff --git a/build/NugetBuildHelpers3.cs b/build/NugetBuildHelpers3.cs index 7acb8243..676e572b 100644 --- a/build/NugetBuildHelpers3.cs +++ b/build/NugetBuildHelpers3.cs @@ -3,6 +3,7 @@ using Nuke.Common.Tools.DotNet; using NukeBuildHelpers; using NukeBuildHelpers.Enums; +using NukeBuildHelpers.Models.RunContext; using Serilog; using System; using System.Collections.Generic; @@ -18,12 +19,21 @@ public class NugetBuildHelpers3 : AppEntry public override RunsOnType PublishRunsOn => RunsOnType.UbuntuLatest; + public override RunType RunBuildOn => RunType.Commit; + + public override RunType RunPublishOn => RunType.Commit; + public override bool MainRelease => false; public override bool RunParallel => false; - public override void Build() + public override void Build(AppRunContext appRunContext) { + AppVersion? appVersion = null; + if (appRunContext is AppPipelineRunContext appPipelineRunContext) + { + appVersion = appPipelineRunContext.AppVersion; + } OutputDirectory.DeleteDirectory(); DotNetTasks.DotNetClean(_ => _ .SetProject(NukeBuild.Solution.NukeBuildHelpers)); @@ -37,16 +47,19 @@ public override void Build() .SetNoBuild(true) .SetIncludeSymbols(true) .SetSymbolPackageFormat("snupkg") - .SetVersion(NewVersion?.Version.ToString() ?? "0.0.0") - .SetPackageReleaseNotes("* Initial prerelease") + .SetVersion(appVersion?.Version?.ToString() ?? "0.0.0") + .SetPackageReleaseNotes(appVersion?.ReleaseNotes) .SetOutputDirectory(OutputDirectory)); } - public override void Publish() + public override void Publish(AppRunContext appRunContext) { - foreach (var ss in OutputDirectory.GetFiles()) + if (appRunContext.RunType == RunType.Bump) { - Log.Information("Publish: {name}", ss.Name); + foreach (var ss in OutputDirectory.GetFiles()) + { + Log.Information("Publish: {name}", ss.Name); + } } } } diff --git a/build/NugetBuildHelpers4.cs b/build/NugetBuildHelpers4.cs index 62b93174..0c161657 100644 --- a/build/NugetBuildHelpers4.cs +++ b/build/NugetBuildHelpers4.cs @@ -3,6 +3,7 @@ using Nuke.Common.Tools.DotNet; using NukeBuildHelpers; using NukeBuildHelpers.Enums; +using NukeBuildHelpers.Models.RunContext; using Serilog; using System; using System.Collections.Generic; @@ -18,12 +19,21 @@ public class NugetBuildHelpers4 : AppEntry public override RunsOnType PublishRunsOn => RunsOnType.UbuntuLatest; + public override RunType RunBuildOn => RunType.PullRequest; + + public override RunType RunPublishOn => RunType.PullRequest; + public override bool MainRelease => false; public override bool RunParallel => false; - public override void Build() + public override void Build(AppRunContext appRunContext) { + AppVersion? appVersion = null; + if (appRunContext is AppPipelineRunContext appPipelineRunContext) + { + appVersion = appPipelineRunContext.AppVersion; + } OutputDirectory.DeleteDirectory(); DotNetTasks.DotNetClean(_ => _ .SetProject(NukeBuild.Solution.NukeBuildHelpers)); @@ -37,16 +47,19 @@ public override void Build() .SetNoBuild(true) .SetIncludeSymbols(true) .SetSymbolPackageFormat("snupkg") - .SetVersion(NewVersion?.Version.ToString() ?? "0.0.0") - .SetPackageReleaseNotes("* Initial prerelease") + .SetVersion(appVersion?.Version?.ToString() ?? "0.0.0") + .SetPackageReleaseNotes(appVersion?.ReleaseNotes) .SetOutputDirectory(OutputDirectory)); } - public override void Publish() + public override void Publish(AppRunContext appRunContext) { - foreach (var ss in OutputDirectory.GetFiles()) + if (appRunContext.RunType == RunType.Bump) { - Log.Information("Publish: {name}", ss.Name); + foreach (var ss in OutputDirectory.GetFiles()) + { + Log.Information("Publish: {name}", ss.Name); + } } } } diff --git a/build/NugetBuildHelpersTestEntry.cs b/build/NugetBuildHelpersTestEntry.cs index 181b84c9..c7f4f3fd 100644 --- a/build/NugetBuildHelpersTestEntry.cs +++ b/build/NugetBuildHelpersTestEntry.cs @@ -5,6 +5,7 @@ using NukeBuildHelpers.Attributes; using NukeBuildHelpers.Enums; using NukeBuildHelpers.Models; +using NukeBuildHelpers.Models.RunContext; using Serilog; using System; using System.Collections.Generic; @@ -22,7 +23,7 @@ public class NugetBuildHelpersTest : AppTestEntry public override Type[] AppEntryTargets => [typeof(NugetBuildHelpers)]; - public override void Run() + public override void Run(AppTestRunContext appTestRunContext) { DotNetTasks.DotNetClean(_ => _ .SetProject(NukeBuild.Solution.NukeBuildHelpers_UnitTest)); diff --git a/build/NugetBuildHelpersTestEntry2.cs b/build/NugetBuildHelpersTestEntry2.cs index 437527cd..8b96f20e 100644 --- a/build/NugetBuildHelpersTestEntry2.cs +++ b/build/NugetBuildHelpersTestEntry2.cs @@ -4,6 +4,7 @@ using NukeBuildHelpers; using NukeBuildHelpers.Enums; using NukeBuildHelpers.Models; +using NukeBuildHelpers.Models.RunContext; using System; using System.Collections.Generic; using System.Linq; @@ -16,13 +17,13 @@ public class NugetBuildHelpersTest2 : AppTestEntry { public override RunsOnType RunsOn => RunsOnType.Windows2022; - public override TestRunType RunType => TestRunType.OnAppEntryVersionBump; + public override RunTestType RunTestOn => RunTestType.Local; public override bool RunParallel => false; public override Type[] AppEntryTargets => [typeof(NugetBuildHelpers2)]; - public override void Run() + public override void Run(AppTestRunContext appTestRunContext) { DotNetTasks.DotNetClean(_ => _ .SetProject(NukeBuild.Solution.NukeBuildHelpers_UnitTest)); diff --git a/build/NugetBuildHelpersTestEntry3.cs b/build/NugetBuildHelpersTestEntry3.cs index fd59bd50..7841caa3 100644 --- a/build/NugetBuildHelpersTestEntry3.cs +++ b/build/NugetBuildHelpersTestEntry3.cs @@ -4,6 +4,7 @@ using NukeBuildHelpers; using NukeBuildHelpers.Enums; using NukeBuildHelpers.Models; +using NukeBuildHelpers.Models.RunContext; using System; using System.Collections.Generic; using System.Linq; @@ -16,13 +17,13 @@ public class NugetBuildHelpersTest3 : AppTestEntry { public override RunsOnType RunsOn => RunsOnType.Ubuntu2204; - public override TestRunType RunType => TestRunType.OnAppEntryVersionBump; + public override RunTestType RunTestOn => RunTestType.All; public override bool RunParallel => false; public override Type[] AppEntryTargets => [typeof(NugetBuildHelpers2)]; - public override void Run() + public override void Run(AppTestRunContext appTestRunContext) { DotNetTasks.DotNetClean(_ => _ .SetProject(NukeBuild.Solution.NukeBuildHelpers_UnitTest)); diff --git a/build/NugetBuildHelpersTestEntry4.cs b/build/NugetBuildHelpersTestEntry4.cs index 188595df..04c5aeff 100644 --- a/build/NugetBuildHelpersTestEntry4.cs +++ b/build/NugetBuildHelpersTestEntry4.cs @@ -4,6 +4,7 @@ using NukeBuildHelpers; using NukeBuildHelpers.Enums; using NukeBuildHelpers.Models; +using NukeBuildHelpers.Models.RunContext; using System; using System.Collections.Generic; using System.Linq; @@ -16,13 +17,13 @@ public class NugetBuildHelpersTest4 : AppTestEntry { public override RunsOnType RunsOn => RunsOnType.Ubuntu2204; - public override TestRunType RunType => TestRunType.OnAppEntryVersionBump; + public override RunTestType RunTestOn => RunTestType.Target; public override bool RunParallel => false; public override Type[] AppEntryTargets => [typeof(NugetBuildHelpers3)]; - public override void Run() + public override void Run(AppTestRunContext appTestRunContext) { DotNetTasks.DotNetClean(_ => _ .SetProject(NukeBuild.Solution.NukeBuildHelpers_UnitTest)); diff --git a/build/_build.csproj b/build/_build.csproj index 4624261c..d8389634 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -1,26 +1,27 @@  - - Exe - net8.0 - - CS0649;CS0169;CA1050;CA1822;CA2211;IDE1006 - .. - .. - 1 - false - + + Exe + net8.0 + + CS0649;CS0169;CA1050;CA1822;CA2211;IDE1006 + .. + .. + 1 + false + enable + - - - + + + - - - + + + - - - + + +