Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed May 13, 2024
1 parent afd9692 commit 6bffad8
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 56 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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
101 changes: 49 additions & 52 deletions Build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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<string>();
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<ITeamCityWriter>();
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())
];
}
8 changes: 4 additions & 4 deletions Build/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -114,7 +114,7 @@ public static bool Succeed(this int? exitCode, string shortName)
return false;
}

public static async Task<bool> Succeed(this Task<int?> exitCodeTask, string shortName) =>
public static async Task<bool> Succeed(Task<int?> exitCodeTask, string shortName) =>
Succeed(await exitCodeTask, shortName);

private static bool CheckBuildResult(IBuildResult result)
Expand All @@ -136,15 +136,15 @@ select testResult.ToString())
return false;
}

public static void Succeed(this IBuildResult result)
public static void Succeed(IBuildResult result)
{
if (!CheckBuildResult(result))
{
Exit();
}
}

public static async Task<bool> Succeed(this Task<IBuildResult> resultTask)
public static async Task<bool> Succeed(Task<IBuildResult> resultTask)
{
if (CheckBuildResult(await resultTask))
{
Expand Down

0 comments on commit 6bffad8

Please sign in to comment.