From 6bffad81aa2b0763ab473332bede365a88e3bf51 Mon Sep 17 00:00:00 2001 From: Nikolay Pianikov Date: Sat, 11 May 2024 20:12:53 +0300 Subject: [PATCH] Fix build --- .github/workflows/main.yml | 19 +++++++ Build/Program.cs | 101 ++++++++++++++++++------------------- Build/Tools.cs | 8 +-- 3 files changed, 72 insertions(+), 56 deletions(-) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..0513212 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,19 @@ +name: Pure.DI check + +on: [ push, pull_request ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Setup dotnet + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.0.x' + + - name: Build + run: dotnet run --project ./Build diff --git a/Build/Program.cs b/Build/Program.cs index 51a25e1..89d929a 100644 --- a/Build/Program.cs +++ b/Build/Program.cs @@ -6,15 +6,14 @@ // ReSharper disable ArrangeTypeModifiers -var cases = new[] -{ - new Case("3.8", "3.8.0"), - new Case("4.0", "4.0.1") -}; - const string solutionFile = "Immutype.sln"; const string configuration = "Release"; const string packageId = "Immutype"; +Settings[] buildSettings = +[ + new Settings("3.8", "3.8.0"), + new Settings("4.0", "4.0.1") +]; var currentDir = Environment.CurrentDirectory; if (!File.Exists(solutionFile)) @@ -23,69 +22,67 @@ return 1; } +var outputDir = Path.Combine("Immutype", "Bin", configuration); var defaultVersion = NuGetVersion.Parse(Property.Get("version", "1.0.0-dev", Tools.UnderTeamCity)); -var apiKey = Property.Get("apiKey", ""); - var nuGetVersion = Version.GetNext(new NuGetRestoreSettings(packageId).WithPackageType(NuGetPackageType.Tool), defaultVersion); - -var output = Path.Combine("Immutype", "Bin", configuration); var packages = new List(); -foreach (var @case in cases) +foreach (var settings in buildSettings) { - var props = new List<(string name, string value)>(@case.Props) - { - ("version", nuGetVersion.ToString()) - }; - - new DotNetClean() - .WithConfiguration(configuration) - .WithProps(props) - .Build() - .Succeed(); - - new DotNetTest() - .WithConfiguration(configuration) - .WithProps(props) - .Build() - .Succeed(); - - new DotNetPack() - .WithConfiguration(configuration) - .WithNoBuild(true) - .WithProps(props) - .Build() - .Succeed(); - - packages.Add(Path.Combine(output, $"roslyn{@case.AnalyzerRoslynVersion}", $"Immutype.{nuGetVersion}.nupkg")); + var props = settings.CreateBuildProps(nuGetVersion); + Assertion.Succeed( + new DotNetClean() + .WithConfiguration(configuration) + .WithProps(props) + .Build()); + + Assertion.Succeed( + new DotNetTest() + .WithConfiguration(configuration) + .WithProps(props) + .Build()); + + var packagePath = Path.GetFullPath(Path.Combine(outputDir, $"roslyn{settings.AnalyzerRoslynVersion}")); + Assertion.Succeed( + new DotNetPack() + .WithConfiguration(configuration) + .WithNoBuild(true) + .WithOutput(packagePath) + .WithProps(props) + .Build()); + + var package = Path.Combine(packagePath, $"Immutype.{nuGetVersion}.nupkg"); + packages.Add(package); } -var package = Path.Combine(output, $"Immutype.{nuGetVersion}.nupkg"); -Tools.MergeNuGetPackages(packages, package); +var mergedPackage = Path.GetFullPath(Path.Combine(outputDir, $"Immutype.{nuGetVersion}.nupkg")); +Tools.MergeNuGetPackages(packages, mergedPackage); Info("Publishing artifacts."); var teamCityWriter = GetService(); -teamCityWriter.PublishArtifact($"{package} => ."); +teamCityWriter.PublishArtifact($"{mergedPackage} => ."); +var apiKey = Property.Get("apiKey", ""); if (!string.IsNullOrWhiteSpace(apiKey) && nuGetVersion.Release != "dev") { - new DotNetNuGetPush() - .WithApiKey(apiKey) - .WithSources("https://api.nuget.org/v3/index.json") - .WithPackage(package) - .Run(). - Succeed($"Pushing {Path.GetFileName(package)}"); + Assertion.Succeed( + new DotNetNuGetPush() + .WithApiKey(apiKey) + .WithSources("https://api.nuget.org/v3/index.json") + .WithPackage(mergedPackage) + .Run(), + $"Pushing {Path.GetFileName(mergedPackage)}"); } WriteLine($"Package version: {nuGetVersion}", Color.Highlighted); return 0; -record Case(string AnalyzerRoslynVersion, string AnalyzerRoslynPackageVersion) +record Settings(string AnalyzerRoslynVersion, string AnalyzerRoslynPackageVersion) { - public IEnumerable<(string name, string value)> Props => - new[] - { - ("AnalyzerRoslynVersion", AnalyzerRoslynVersion), - ("AnalyzerRoslynPackageVersion", AnalyzerRoslynPackageVersion) - }; + public (string name, string value)[] CreateBuildProps(NuGetVersion nuGetVersion) => + [ + ("AnalyzerRoslynVersion", AnalyzerRoslynVersion), + ("AnalyzerRoslynPackageVersion", AnalyzerRoslynPackageVersion), + ("version", nuGetVersion.ToString()) + ]; } diff --git a/Build/Tools.cs b/Build/Tools.cs index 66ec324..bd46ed8 100644 --- a/Build/Tools.cs +++ b/Build/Tools.cs @@ -102,7 +102,7 @@ public static string Get(string name, string defaultProp, bool showWarning = fal static class Assertion { - public static bool Succeed(this int? exitCode, string shortName) + public static bool Succeed(int? exitCode, string shortName) { if (exitCode == 0) { @@ -114,7 +114,7 @@ public static bool Succeed(this int? exitCode, string shortName) return false; } - public static async Task Succeed(this Task exitCodeTask, string shortName) => + public static async Task Succeed(Task exitCodeTask, string shortName) => Succeed(await exitCodeTask, shortName); private static bool CheckBuildResult(IBuildResult result) @@ -136,7 +136,7 @@ select testResult.ToString()) return false; } - public static void Succeed(this IBuildResult result) + public static void Succeed(IBuildResult result) { if (!CheckBuildResult(result)) { @@ -144,7 +144,7 @@ public static void Succeed(this IBuildResult result) } } - public static async Task Succeed(this Task resultTask) + public static async Task Succeed(Task resultTask) { if (CheckBuildResult(await resultTask)) {