|
| 1 | +using System.Collections.Generic; |
| 2 | +using System.Linq; |
| 3 | +using Nuke.Common.CI.GitHubActions; |
| 4 | +using Rocket.Surgery.Nuke; |
| 5 | +using Rocket.Surgery.Nuke.ContinuousIntegration; |
| 6 | +using Rocket.Surgery.Nuke.DotNetCore; |
| 7 | +using Rocket.Surgery.Nuke.GithubActions; |
| 8 | + |
| 9 | +[AzurePipelinesSteps( |
| 10 | + AutoGenerate = false, |
| 11 | + InvokeTargets = new[] { nameof(Default) }, |
| 12 | + NonEntryTargets = new[] |
| 13 | + { |
| 14 | + nameof(ICIEnvironment.CIEnvironment), |
| 15 | + nameof(ITriggerCodeCoverageReports.Trigger_Code_Coverage_Reports), |
| 16 | + nameof(ITriggerCodeCoverageReports.Generate_Code_Coverage_Report_Cobertura), |
| 17 | + nameof(IGenerateCodeCoverageBadges.Generate_Code_Coverage_Badges), |
| 18 | + nameof(IGenerateCodeCoverageReport.Generate_Code_Coverage_Report), |
| 19 | + nameof(IGenerateCodeCoverageSummary.Generate_Code_Coverage_Summary), |
| 20 | + nameof(Default) |
| 21 | + }, |
| 22 | + ExcludedTargets = new[] |
| 23 | + { nameof(ICanClean.Clean), nameof(ICanRestoreWithDotNetCore.Restore), nameof(ICanRestoreWithDotNetCore.DotnetToolRestore) }, |
| 24 | + Parameters = new[] |
| 25 | + { |
| 26 | + nameof(IHaveCodeCoverage.CoverageDirectory), nameof(IHaveOutputArtifacts.ArtifactsDirectory), nameof(Verbosity), |
| 27 | + nameof(IHaveConfiguration.Configuration) |
| 28 | + } |
| 29 | +)] |
| 30 | +[GitHubActionsSteps("ci", GitHubActionsImage.MacOsLatest, GitHubActionsImage.WindowsLatest, GitHubActionsImage.UbuntuLatest, |
| 31 | + AutoGenerate = false, |
| 32 | + On = new[] { GitHubActionsTrigger.Push }, |
| 33 | + OnPushTags = new[] { "v*" }, |
| 34 | + OnPushBranches = new[] { "master", "next" }, |
| 35 | + OnPullRequestBranches = new[] { "master", "next" }, |
| 36 | + InvokedTargets = new[] { nameof(Default) }, |
| 37 | + NonEntryTargets = new[] |
| 38 | + { |
| 39 | + nameof(ICIEnvironment.CIEnvironment), |
| 40 | + nameof(ITriggerCodeCoverageReports.Trigger_Code_Coverage_Reports), |
| 41 | + nameof(ITriggerCodeCoverageReports.Generate_Code_Coverage_Report_Cobertura), |
| 42 | + nameof(IGenerateCodeCoverageBadges.Generate_Code_Coverage_Badges), |
| 43 | + nameof(IGenerateCodeCoverageReport.Generate_Code_Coverage_Report), |
| 44 | + nameof(IGenerateCodeCoverageSummary.Generate_Code_Coverage_Summary), |
| 45 | + nameof(Default) |
| 46 | + }, |
| 47 | + ExcludedTargets = new[] { nameof(ICanClean.Clean), nameof(ICanRestoreWithDotNetCore.DotnetToolRestore) }, |
| 48 | + Enhancements = new[] { nameof(Middleware) } |
| 49 | +)] |
| 50 | +[PrintBuildVersion, PrintCIEnvironment, UploadLogs] |
| 51 | +public partial class Solution |
| 52 | +{ |
| 53 | + public static RocketSurgeonGitHubActionsConfiguration Middleware(RocketSurgeonGitHubActionsConfiguration configuration) |
| 54 | + { |
| 55 | + var buildJob = configuration.Jobs.First(z => z.Name == "Build"); |
| 56 | + var checkoutStep = buildJob.Steps.OfType<CheckoutStep>().Single(); |
| 57 | + // For fetch all |
| 58 | + checkoutStep.FetchDepth = 0; |
| 59 | + buildJob.Steps.InsertRange(buildJob.Steps.IndexOf(checkoutStep) + 1, new BaseGitHubActionsStep[] { |
| 60 | + new RunStep("Fetch all history for all tags and branches") { |
| 61 | + Run = "git fetch --prune" |
| 62 | + }, |
| 63 | + new SetupDotNetStep("Use .NET Core 2.1 SDK") { |
| 64 | + DotNetVersion = "2.1.x" |
| 65 | + }, |
| 66 | + new SetupDotNetStep("Use .NET Core 3.1 SDK") { |
| 67 | + DotNetVersion = "3.1.x" |
| 68 | + }, |
| 69 | + new RunStep("🪓 **DOTNET HACK** 🪓") { |
| 70 | + Shell = GithubActionShell.Pwsh, |
| 71 | + Run = @"$version = Split-Path (Split-Path $ENV:DOTNET_ROOT -Parent) -Leaf; |
| 72 | + $root = Split-Path (Split-Path $ENV:DOTNET_ROOT -Parent) -Parent; |
| 73 | + $directories = Get-ChildItem $root | Where-Object { $_.Name -ne $version }; |
| 74 | + foreach ($dir in $directories) { |
| 75 | + $from = $dir.FullName; |
| 76 | + $to = ""$root/$version""; |
| 77 | + Write-Host Copying from $from to $to; |
| 78 | + Copy-Item ""$from\*"" $to -Recurse -Force; |
| 79 | + } |
| 80 | + " |
| 81 | + }, |
| 82 | + }); |
| 83 | + |
| 84 | + buildJob.Steps.Add(new UsingStep("Publish Coverage") |
| 85 | + { |
| 86 | + Uses = "codecov/codecov-action@v1", |
| 87 | + With = new Dictionary<string, string> |
| 88 | + { |
| 89 | + ["name"] = "actions-${{ matrix.os }}", |
| 90 | + ["fail_ci_if_error"] = "true", |
| 91 | + } |
| 92 | + }); |
| 93 | + |
| 94 | + buildJob.Steps.Add(new UploadArtifactStep("Publish logs") |
| 95 | + { |
| 96 | + Name = "logs", |
| 97 | + Path = "artifacts/logs/", |
| 98 | + If = "always()" |
| 99 | + }); |
| 100 | + |
| 101 | + buildJob.Steps.Add(new UploadArtifactStep("Publish coverage data") |
| 102 | + { |
| 103 | + Name = "coverage", |
| 104 | + Path = "coverage/", |
| 105 | + If = "always()" |
| 106 | + }); |
| 107 | + |
| 108 | + buildJob.Steps.Add(new UploadArtifactStep("Publish test data") |
| 109 | + { |
| 110 | + Name = "test data", |
| 111 | + Path = "artifacts/test/", |
| 112 | + If = "always()" |
| 113 | + }); |
| 114 | + |
| 115 | + buildJob.Steps.Add(new UploadArtifactStep("Publish NuGet Packages") |
| 116 | + { |
| 117 | + Name = "nuget", |
| 118 | + Path = "artifacts/nuget/", |
| 119 | + If = "always()" |
| 120 | + }); |
| 121 | + |
| 122 | + |
| 123 | + /* |
| 124 | +
|
| 125 | + - publish: "${{ parameters.Artifacts }}/logs/" |
| 126 | + displayName: Publish Logs |
| 127 | + artifact: "Logs${{ parameters.Postfix }}" |
| 128 | + condition: always() |
| 129 | +
|
| 130 | + - publish: ${{ parameters.Coverage }} |
| 131 | + displayName: Publish Coverage |
| 132 | + artifact: "Coverage${{ parameters.Postfix }}" |
| 133 | + condition: always() |
| 134 | +
|
| 135 | + - publish: "${{ parameters.Artifacts }}/nuget/" |
| 136 | + displayName: Publish NuGet Artifacts |
| 137 | + artifact: "NuGet${{ parameters.Postfix }}" |
| 138 | + condition: always() |
| 139 | + */ |
| 140 | + return configuration; |
| 141 | + } |
| 142 | +} |
0 commit comments