Skip to content

Commit 4c91e99

Browse files
author
András Kurai
committed
create github release with ci
1 parent d16dbbc commit 4c91e99

File tree

5 files changed

+88
-13
lines changed

5 files changed

+88
-13
lines changed

.github/workflows/publish.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ jobs:
1717
with:
1818
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
1919
root: "UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator"
20+
21+
- name: Create GitHub Release
22+
shell: pwsh
23+
run: ./build.ps1 CreateGithubRelease --is-ci

.nuke/build.schema.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"enum": [
7878
"BuildDocs",
7979
"Compile",
80+
"CreateGithubRelease",
8081
"CreateMetadata",
8182
"GenerateUnitySolution",
8283
"Restore",
@@ -85,10 +86,6 @@
8586
]
8687
}
8788
},
88-
"Solution": {
89-
"type": "string",
90-
"description": "Path to a solution file that is automatically loaded"
91-
},
9289
"Target": {
9390
"type": "array",
9491
"description": "List of targets to be invoked. Default is '{default_target}'",
@@ -97,6 +94,7 @@
9794
"enum": [
9895
"BuildDocs",
9996
"Compile",
97+
"CreateGithubRelease",
10098
"CreateMetadata",
10199
"GenerateUnitySolution",
102100
"Restore",

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
## 0.1.0
2-
- Add initial project
1+
# 0.1.1
2+
- Add documentation website
3+
- Reference website in `package.json`
4+
5+
# 0.1.0
6+
- Add initial project

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace Sample
5555

5656
## Installation
5757

58-
Either use the `.unitypackage` provided in the releases or use OpenUPM
58+
Use [OpenUPM](https://openupm.com/) to install the package.
5959

6060
```
6161
openupm add com.autsoft.unityresourcegenerator

UnityResourceGenerator.Build/Build.cs

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
using Nuke.Common;
22
using Nuke.Common.IO;
3-
using Nuke.Common.ProjectModel;
43
using Nuke.Common.Tooling;
54
using Nuke.Common.Tools.MSBuild;
5+
using Nuke.Common.Utilities.Collections;
66
using System;
77
using System.IO;
8+
using System.Linq;
9+
using System.Text;
10+
using System.Text.Json;
811
using System.Text.RegularExpressions;
912
using System.Threading.Tasks;
1013
using static Nuke.Common.Tools.DocFX.DocFXTasks;
14+
using static Nuke.Common.Tools.Git.GitTasks;
1115
using static Nuke.Common.Tools.MSBuild.MSBuildTasks;
1216
using static Nuke.Common.Tools.Unity.UnityTasks;
1317
using static UnityHelper;
@@ -18,21 +22,24 @@ class Build : NukeBuild
1822

1923
public static int Main() => Execute<Build>(x => x.Compile);
2024

25+
[PathExecutable] readonly Tool Gh = default!;
26+
2127
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
2228
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
2329

24-
[Solution] readonly Solution Solution = default!;
25-
2630
[Parameter("Password for Unity license")] string? UnityPassword;
2731
[Parameter("Email for Unity license")] string? UnityEmail;
2832
[Parameter("Serial for Unity license")] string? UnitySerial;
2933

3034
[Parameter("Are we running in CI")] bool IsCi = false;
3135

32-
AbsolutePath UnityProjectPath => Solution.Directory / "UnityResourceGenerator";
33-
AbsolutePath UnitySolution => UnityProjectPath / "UnityResourceGenerator.sln";
36+
string CurrentVersion { get; set; } = default!;
37+
bool IsNewestVersion { get; set; }
3438

35-
string UnityVersion =>
39+
static AbsolutePath UnityProjectPath => RootDirectory / "UnityResourceGenerator";
40+
static AbsolutePath UnitySolution => UnityProjectPath / "UnityResourceGenerator.sln";
41+
42+
static string UnityVersion =>
3643
Regex.Match
3744
(
3845
File.ReadAllLines(Path.Combine(UnityProjectPath, "ProjectSettings", "ProjectVersion.txt"))[0],
@@ -116,4 +123,66 @@ async Task GenerateSolution()
116123
Target ServeDocs => _ => _
117124
.DependsOn(BuildDocs)
118125
.Executes(() => DocFX($"{DocFxJsonPath} --serve"));
126+
127+
Target CreateGithubRelease => _ => _
128+
.OnlyWhenDynamic(() => IsNewestVersion)
129+
.OnlyWhenDynamic(() => IsCi)
130+
.Executes(() =>
131+
{
132+
var version = CurrentVersion;
133+
134+
var notes = File.ReadAllLines(RootDirectory / "CHANGELOG.md")
135+
.Skip(1)
136+
.TakeUntil(string.IsNullOrWhiteSpace)
137+
.Aggregate(new StringBuilder(), (sb, l) => sb.AppendLine(l))
138+
.ToString();
139+
140+
Gh($"release create {version} -t {version} -n \"{notes}\"");
141+
});
142+
143+
144+
protected override void OnBuildInitialized()
145+
{
146+
bool GetIsNewestVersion()
147+
{
148+
var currentVersion = new Version(CurrentVersion);
149+
150+
GitLogger = (_, s) => Logger.Info(s);
151+
152+
Git("fetch --tags");
153+
154+
var maxPublishedVersion = Git("tag")
155+
.Select(o => new Version(o.Text))
156+
.OrderBy(v => v)
157+
.LastOrDefault();
158+
159+
return currentVersion.CompareTo(maxPublishedVersion) > 0;
160+
}
161+
162+
string GetCurrentVersion()
163+
{
164+
var packagePath = UnityProjectPath / "Assets" / "AutSoft.UnityResourceGenerator" / "package.json";
165+
166+
if (!File.Exists(packagePath)) throw new InvalidOperationException($"package.json does not exist at path: {packagePath}");
167+
168+
var jsonContent = File.ReadAllText(packagePath);
169+
var package = JsonSerializer.Deserialize<PackageJson>(jsonContent, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
170+
171+
if (package?.Version is null) throw new InvalidOperationException($"Cloud not deserialize package.json:{Environment.NewLine}{jsonContent}");
172+
173+
return package.Version;
174+
}
175+
176+
CurrentVersion = GetCurrentVersion();
177+
IsNewestVersion = GetIsNewestVersion();
178+
179+
base.OnBuildInitialized();
180+
}
181+
182+
sealed class PackageJson
183+
{
184+
public PackageJson(string version) => Version = version;
185+
186+
public string Version { get; }
187+
}
119188
}

0 commit comments

Comments
 (0)