From cb8887cbd66644d4e0a7419ae1d8df49e5bada3a Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Sat, 15 Nov 2025 16:15:43 +1000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Conditionally=20Create=20Release=20?= =?UTF-8?q?(#8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SharpIDE.sln | 3 ++ iac/Deploy/Steps/CreateGithubRelease.cs | 6 ++- iac/should-release.cs | 51 +++++++++++++++++-- .../Features/SlnPicker/SlnPicker.cs | 11 ++++ .../Features/SlnPicker/SlnPicker.tscn | 3 +- src/SharpIDE.Godot/version.txt | 1 + 6 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 src/SharpIDE.Godot/version.txt diff --git a/SharpIDE.sln b/SharpIDE.sln index f683165..2d911b0 100644 --- a/SharpIDE.sln +++ b/SharpIDE.sln @@ -37,6 +37,9 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpIDE.Godot", "src\SharpIDE.Godot\SharpIDE.Godot.csproj", "{D306410D-3A28-4F1B-A09B-CA10041A7C53}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "iac", "iac", "{E239E6C6-8915-4F03-85B7-22AEAF281D14}" + ProjectSection(SolutionItems) = preProject + iac\should-release.cs = iac\should-release.cs + EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Deploy", "iac\Deploy\Deploy.csproj", "{52CD8910-88A4-4978-B107-C7B6C7FC3557}" EndProject diff --git a/iac/Deploy/Steps/CreateGithubRelease.cs b/iac/Deploy/Steps/CreateGithubRelease.cs index 2085652..7133495 100644 --- a/iac/Deploy/Steps/CreateGithubRelease.cs +++ b/iac/Deploy/Steps/CreateGithubRelease.cs @@ -18,7 +18,11 @@ public class CreateGithubRelease(IPipelineContext pipelineContext) : IStep var credentials = new Credentials(token); github.Credentials = credentials; - var version = NuGetVersion.Parse("0.1.1"); + var versionFile = await PipelineFileHelper.GitRootDirectory.GetFile("./src/SharpIDE.Godot/version.txt"); + if (versionFile.Exists is false) throw new FileNotFoundException(versionFile.FullName); + var versionText = await File.ReadAllTextAsync(versionFile.FullName, cancellationToken); + + var version = NuGetVersion.Parse(versionText); var versionString = version.ToNormalizedString(); var releaseTag = $"v{versionString}"; diff --git a/iac/should-release.cs b/iac/should-release.cs index 25c97a1..088b873 100644 --- a/iac/should-release.cs +++ b/iac/should-release.cs @@ -1,5 +1,50 @@ +#:package Octokit +#:package NuGet.Versioning +using Octokit; +using NuGet.Versioning; +var versionFile = new FileInfo(Path.Combine(GetGitRootPath(), "src", "SharpIDE.Godot", "version.txt")); +if (versionFile.Exists is false) throw new FileNotFoundException(versionFile.FullName); +var versionText = await File.ReadAllTextAsync(versionFile.FullName); -// var test = await github.Repository.Release.Get(owner, repo, newRelease.TagName); -Console.WriteLine("false"); -return 0; \ No newline at end of file +var version = NuGetVersion.Parse(versionText); +var versionString = version.ToNormalizedString(); +var releaseTag = $"v{versionString}"; + +var github = new GitHubClient(new ProductHeaderValue("SharpIDE-CI")); +var owner = "MattParkerDev"; +var repo = "SharpIDE"; +var release = await GetReleaseOrNull(); + +var resultString = release is null ? "true" : "false"; +Console.WriteLine(resultString); +return 0; + +async Task GetReleaseOrNull() +{ + try + { + var release = await github.Repository.Release.Get(owner, repo, releaseTag); + return release; + } + catch (NotFoundException) + { + return null; + } +} + +static string GetGitRootPath() +{ + var currentDirectory = Directory.GetCurrentDirectory(); + var gitRoot = currentDirectory; + while (!Directory.Exists(Path.Combine(gitRoot, ".git"))) + { + gitRoot = Path.GetDirectoryName(gitRoot); // parent directory + if (string.IsNullOrWhiteSpace(gitRoot)) + { + throw new Exception("Could not find git root"); + } + } + + return gitRoot; +} diff --git a/src/SharpIDE.Godot/Features/SlnPicker/SlnPicker.cs b/src/SharpIDE.Godot/Features/SlnPicker/SlnPicker.cs index fbd8600..9966335 100644 --- a/src/SharpIDE.Godot/Features/SlnPicker/SlnPicker.cs +++ b/src/SharpIDE.Godot/Features/SlnPicker/SlnPicker.cs @@ -1,4 +1,6 @@ using Godot; +using NuGet.Versioning; +using FileAccess = Godot.FileAccess; namespace SharpIDE.Godot.Features.SlnPicker; @@ -8,6 +10,8 @@ public partial class SlnPicker : Control private FileDialog _fileDialog = null!; private Button _openSlnButton = null!; private VBoxContainer _previousSlnsVBoxContainer = null!; + private Label _versionLabel = null!; + private static NuGetVersion? _version; private PackedScene _previousSlnEntryScene = ResourceLoader.Load("res://Features/SlnPicker/PreviousSlnEntry.tscn"); @@ -21,12 +25,19 @@ public partial class SlnPicker : Control public override void _Ready() { _previousSlnsVBoxContainer = GetNode("%PreviousSlnsVBoxContainer"); + _versionLabel = GetNode