Skip to content

Commit d02d3d3

Browse files
committed
(build) added release project
1 parent 3a7fbab commit d02d3d3

File tree

13 files changed

+204
-4
lines changed

13 files changed

+204
-4
lines changed

build/.run/Publish Release.run.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="Publish Release" type="DotNetProject" factoryName=".NET Project" folderName="Release">
3+
<option name="EXE_PATH" value="$PROJECT_DIR$/../run/release.exe" />
4+
<option name="PROGRAM_PARAMETERS" value="--target=PublishRelease" />
5+
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/.." />
6+
<option name="PASS_PARENT_ENVS" value="1" />
7+
<option name="USE_EXTERNAL_CONSOLE" value="0" />
8+
<option name="USE_MONO" value="0" />
9+
<option name="RUNTIME_ARGUMENTS" value="" />
10+
<option name="PROJECT_PATH" value="$PROJECT_DIR$/release/release.csproj" />
11+
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
12+
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
13+
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
14+
<option name="PROJECT_KIND" value="DotNetCore" />
15+
<option name="PROJECT_TFM" value="net5.0" />
16+
<method v="2">
17+
<option name="Build" />
18+
</method>
19+
</configuration>
20+
</component>

build/CI.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "publish", "publish\publish.
2020
EndProject
2121
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "docs", "docs\docs.csproj", "{C85F4443-5A37-4230-BC0C-C4436149AAEB}"
2222
EndProject
23+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "release", "release\release.csproj", "{8DAB65D8-57E8-4185-96FC-8A7C7373FC23}"
24+
EndProject
2325
Global
2426
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2527
Debug|Any CPU = Debug|Any CPU
@@ -54,5 +56,9 @@ Global
5456
{C85F4443-5A37-4230-BC0C-C4436149AAEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
5557
{C85F4443-5A37-4230-BC0C-C4436149AAEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
5658
{C85F4443-5A37-4230-BC0C-C4436149AAEB}.Release|Any CPU.Build.0 = Release|Any CPU
59+
{8DAB65D8-57E8-4185-96FC-8A7C7373FC23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
60+
{8DAB65D8-57E8-4185-96FC-8A7C7373FC23}.Debug|Any CPU.Build.0 = Debug|Any CPU
61+
{8DAB65D8-57E8-4185-96FC-8A7C7373FC23}.Release|Any CPU.ActiveCfg = Release|Any CPU
62+
{8DAB65D8-57E8-4185-96FC-8A7C7373FC23}.Release|Any CPU.Build.0 = Release|Any CPU
5763
EndGlobalSection
5864
EndGlobal

build/common/Lifetime/BuildTaskLifetime.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ public override void Setup(ICakeContext context, ITaskSetupContext info)
1111
var message = $"Task: {info.Task.Name}";
1212
context.StartGroup(message);
1313
}
14-
public override void Teardown(ICakeContext context, ITaskTeardownContext info)
15-
{
16-
context.EndGroup();
17-
}
14+
public override void Teardown(ICakeContext context, ITaskTeardownContext info) => context.EndGroup();
1815
}
1916
}

build/common/Utilities/Constants.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ namespace Common.Utilities
22
{
33
public class Constants
44
{
5+
public const string RepoOwner = "gittools";
6+
public const string Repository = "GitVersion";
7+
58
public const string Version50 = "5.0";
69
public const string Version31 = "3.1";
710

build/release/BuildContext.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Cake.Core;
2+
using Common.Utilities;
3+
using Release.Utilities;
4+
5+
namespace Release
6+
{
7+
public class BuildContext : BuildContextBase
8+
{
9+
public Credentials? Credentials { get; set; }
10+
11+
public BuildContext(ICakeContext context) : base(context)
12+
{
13+
}
14+
}
15+
}

build/release/BuildLifetime.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Common.Utilities;
2+
using Release.Utilities;
3+
4+
namespace Release
5+
{
6+
public class BuildLifetime : BuildLifetimeBase<BuildContext>
7+
{
8+
public override void Setup(BuildContext context)
9+
{
10+
base.Setup(context);
11+
context.Credentials = Credentials.GetCredentials(context);
12+
13+
context.StartGroup("Build Setup");
14+
LogBuildInformation(context);
15+
context.EndGroup();
16+
}
17+
}
18+
}

build/release/Program.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Cake.Frosting;
2+
using Common.Utilities;
3+
using Release;
4+
5+
return new CakeHost()
6+
.UseContext<BuildContext>()
7+
.UseStartup<Startup>()
8+
.SetToolPath(Paths.ToolsDirectory)
9+
.Run(args);

build/release/Startup.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using Cake.Frosting;
3+
using Common.Lifetime;
4+
using Microsoft.Extensions.DependencyInjection;
5+
6+
namespace Release
7+
{
8+
public class Startup : IFrostingStartup
9+
{
10+
public void Configure(IServiceCollection services)
11+
{
12+
services.UseLifetime<BuildLifetime>();
13+
services.UseTaskLifetime<BuildTaskLifetime>();
14+
15+
services.UseTool(new Uri("dotnet:?package=GitVersion.Tool&version=5.6.11"));
16+
services.UseTool(new Uri("dotnet:?package=GitReleaseManager.Tool&version=0.12.0"));
17+
}
18+
}
19+
}

build/release/Tasks/Default.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Release.Tasks
2+
{
3+
public class Default : Common.Tasks.Default
4+
{
5+
}
6+
}

build/release/Tasks/PublishRelease.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System;
2+
using System.Linq;
3+
using Cake.Common.Diagnostics;
4+
using Cake.Common.IO;
5+
using Cake.Common.Tools.GitReleaseManager;
6+
using Cake.Common.Tools.GitReleaseManager.Create;
7+
using Cake.Frosting;
8+
using Common.Utilities;
9+
10+
namespace Release.Tasks
11+
{
12+
[TaskName(nameof(PublishRelease))]
13+
[TaskDescription("Publish release")]
14+
[IsDependentOn(typeof(PublishReleaseInternal))]
15+
16+
public class PublishRelease : FrostingTask<BuildContext>
17+
{
18+
}
19+
20+
[TaskName(nameof(PublishReleaseInternal))]
21+
[TaskDescription("Publish release")]
22+
public class PublishReleaseInternal : FrostingTask<BuildContext>
23+
{
24+
public override bool ShouldRun(BuildContext context)
25+
{
26+
var shouldRun = true;
27+
shouldRun &= context.ShouldRun(context.IsGitHubActionsBuild, $"{nameof(PublishRelease)} works only on GitHub Actions.");
28+
shouldRun &= context.ShouldRun(context.IsStableRelease, $"{nameof(PublishRelease)} works only for releases.");
29+
30+
return shouldRun;
31+
}
32+
33+
public override void Run(BuildContext context)
34+
{
35+
var token = context.Credentials?.GitHub?.Token;
36+
if (string.IsNullOrEmpty(token))
37+
{
38+
throw new InvalidOperationException("Could not resolve GitHub Token.");
39+
}
40+
41+
var tarGzFiles = context.GetFiles(Paths.Native + "/*.tar.gz").Select(x => x.ToString()).ToList();
42+
context.Information("zip count: " + tarGzFiles.Count);
43+
44+
var assets = string.Join(",", tarGzFiles);
45+
46+
var milestone = context.Version?.Milestone;
47+
48+
if (milestone is null) return;
49+
50+
context.GitReleaseManagerCreate(token, Constants.RepoOwner, Constants.Repository, new GitReleaseManagerCreateSettings
51+
{
52+
Milestone = milestone,
53+
Name = milestone,
54+
Prerelease = false,
55+
TargetCommitish = "main"
56+
});
57+
58+
context.GitReleaseManagerAddAssets(token, Constants.RepoOwner, Constants.Repository, milestone, assets);
59+
context.GitReleaseManagerClose(token, Constants.RepoOwner, Constants.Repository, milestone);
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)