Conditionally Create Release (#8)

This commit is contained in:
Matt Parker
2025-11-15 16:15:43 +10:00
committed by GitHub
parent c2928fbd2d
commit cb8887cbd6
6 changed files with 70 additions and 5 deletions

View File

@@ -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

View File

@@ -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}";

View File

@@ -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;
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<Release?> 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;
}

View File

@@ -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<PackedScene>("res://Features/SlnPicker/PreviousSlnEntry.tscn");
@@ -21,12 +25,19 @@ public partial class SlnPicker : Control
public override void _Ready()
{
_previousSlnsVBoxContainer = GetNode<VBoxContainer>("%PreviousSlnsVBoxContainer");
_versionLabel = GetNode<Label>("%VersionLabel");
_fileDialog = GetNode<FileDialog>("%FileDialog");
_openSlnButton = GetNode<Button>("%OpenSlnButton");
_openSlnButton.Pressed += () => _fileDialog.PopupCentered();
var windowParent = GetParentOrNull<Window>();
_fileDialog.FileSelected += path => _tcs.SetResult(path);
windowParent?.CloseRequested += () => _tcs.SetResult(null);
if (_version is null)
{
var version = FileAccess.GetFileAsString("res://version.txt").Trim();
_version = NuGetVersion.Parse(version);
}
_versionLabel.Text = $"v{_version.ToNormalizedString()}";
if (Singletons.AppState.IdeSettings.AutoOpenLastSolution && GetParent() is not Window)
{
var lastSln = Singletons.AppState.RecentSlns.LastOrDefault();

View File

@@ -65,7 +65,8 @@ alignment = 1
layout_mode = 2
text = "SharpIDE"
[node name="Label2" type="Label" parent="VSplitContainer/Panel2/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer"]
[node name="VersionLabel" type="Label" parent="VSplitContainer/Panel2/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_colors/font_color = Color(0.5689727, 0.56897277, 0.5689727, 1)
text = "v0.1.2"

View File

@@ -0,0 +1 @@
0.1.2