Skip to content

Commit cb8887c

Browse files
✨ Conditionally Create Release (#8)
1 parent c2928fb commit cb8887c

File tree

6 files changed

+70
-5
lines changed

6 files changed

+70
-5
lines changed

SharpIDE.sln

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ EndProject
3737
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpIDE.Godot", "src\SharpIDE.Godot\SharpIDE.Godot.csproj", "{D306410D-3A28-4F1B-A09B-CA10041A7C53}"
3838
EndProject
3939
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "iac", "iac", "{E239E6C6-8915-4F03-85B7-22AEAF281D14}"
40+
ProjectSection(SolutionItems) = preProject
41+
iac\should-release.cs = iac\should-release.cs
42+
EndProjectSection
4043
EndProject
4144
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Deploy", "iac\Deploy\Deploy.csproj", "{52CD8910-88A4-4978-B107-C7B6C7FC3557}"
4245
EndProject

iac/Deploy/Steps/CreateGithubRelease.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ public class CreateGithubRelease(IPipelineContext pipelineContext) : IStep
1818
var credentials = new Credentials(token);
1919
github.Credentials = credentials;
2020

21-
var version = NuGetVersion.Parse("0.1.1");
21+
var versionFile = await PipelineFileHelper.GitRootDirectory.GetFile("./src/SharpIDE.Godot/version.txt");
22+
if (versionFile.Exists is false) throw new FileNotFoundException(versionFile.FullName);
23+
var versionText = await File.ReadAllTextAsync(versionFile.FullName, cancellationToken);
24+
25+
var version = NuGetVersion.Parse(versionText);
2226
var versionString = version.ToNormalizedString();
2327
var releaseTag = $"v{versionString}";
2428

iac/should-release.cs

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,50 @@
1+
#:package Octokit
2+
#:package NuGet.Versioning
3+
using Octokit;
4+
using NuGet.Versioning;
15

6+
var versionFile = new FileInfo(Path.Combine(GetGitRootPath(), "src", "SharpIDE.Godot", "version.txt"));
7+
if (versionFile.Exists is false) throw new FileNotFoundException(versionFile.FullName);
8+
var versionText = await File.ReadAllTextAsync(versionFile.FullName);
29

3-
// var test = await github.Repository.Release.Get(owner, repo, newRelease.TagName);
4-
Console.WriteLine("false");
5-
return 0;
10+
var version = NuGetVersion.Parse(versionText);
11+
var versionString = version.ToNormalizedString();
12+
var releaseTag = $"v{versionString}";
13+
14+
var github = new GitHubClient(new ProductHeaderValue("SharpIDE-CI"));
15+
var owner = "MattParkerDev";
16+
var repo = "SharpIDE";
17+
var release = await GetReleaseOrNull();
18+
19+
var resultString = release is null ? "true" : "false";
20+
Console.WriteLine(resultString);
21+
return 0;
22+
23+
async Task<Release?> GetReleaseOrNull()
24+
{
25+
try
26+
{
27+
var release = await github.Repository.Release.Get(owner, repo, releaseTag);
28+
return release;
29+
}
30+
catch (NotFoundException)
31+
{
32+
return null;
33+
}
34+
}
35+
36+
static string GetGitRootPath()
37+
{
38+
var currentDirectory = Directory.GetCurrentDirectory();
39+
var gitRoot = currentDirectory;
40+
while (!Directory.Exists(Path.Combine(gitRoot, ".git")))
41+
{
42+
gitRoot = Path.GetDirectoryName(gitRoot); // parent directory
43+
if (string.IsNullOrWhiteSpace(gitRoot))
44+
{
45+
throw new Exception("Could not find git root");
46+
}
47+
}
48+
49+
return gitRoot;
50+
}

src/SharpIDE.Godot/Features/SlnPicker/SlnPicker.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using Godot;
2+
using NuGet.Versioning;
3+
using FileAccess = Godot.FileAccess;
24

35
namespace SharpIDE.Godot.Features.SlnPicker;
46

@@ -8,6 +10,8 @@ public partial class SlnPicker : Control
810
private FileDialog _fileDialog = null!;
911
private Button _openSlnButton = null!;
1012
private VBoxContainer _previousSlnsVBoxContainer = null!;
13+
private Label _versionLabel = null!;
14+
private static NuGetVersion? _version;
1115

1216
private PackedScene _previousSlnEntryScene = ResourceLoader.Load<PackedScene>("res://Features/SlnPicker/PreviousSlnEntry.tscn");
1317

@@ -21,12 +25,19 @@ public override void _ExitTree()
2125
public override void _Ready()
2226
{
2327
_previousSlnsVBoxContainer = GetNode<VBoxContainer>("%PreviousSlnsVBoxContainer");
28+
_versionLabel = GetNode<Label>("%VersionLabel");
2429
_fileDialog = GetNode<FileDialog>("%FileDialog");
2530
_openSlnButton = GetNode<Button>("%OpenSlnButton");
2631
_openSlnButton.Pressed += () => _fileDialog.PopupCentered();
2732
var windowParent = GetParentOrNull<Window>();
2833
_fileDialog.FileSelected += path => _tcs.SetResult(path);
2934
windowParent?.CloseRequested += () => _tcs.SetResult(null);
35+
if (_version is null)
36+
{
37+
var version = FileAccess.GetFileAsString("res://version.txt").Trim();
38+
_version = NuGetVersion.Parse(version);
39+
}
40+
_versionLabel.Text = $"v{_version.ToNormalizedString()}";
3041
if (Singletons.AppState.IdeSettings.AutoOpenLastSolution && GetParent() is not Window)
3142
{
3243
var lastSln = Singletons.AppState.RecentSlns.LastOrDefault();

src/SharpIDE.Godot/Features/SlnPicker/SlnPicker.tscn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ alignment = 1
6565
layout_mode = 2
6666
text = "SharpIDE"
6767

68-
[node name="Label2" type="Label" parent="VSplitContainer/Panel2/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer"]
68+
[node name="VersionLabel" type="Label" parent="VSplitContainer/Panel2/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer"]
69+
unique_name_in_owner = true
6970
layout_mode = 2
7071
theme_override_colors/font_color = Color(0.5689727, 0.56897277, 0.5689727, 1)
7172
text = "v0.1.2"

src/SharpIDE.Godot/version.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.2

0 commit comments

Comments
 (0)