Skip to content

Commit

Permalink
Merge pull request #62 from Shaderbug/use-label-no-dots-for-checksum-url
Browse files Browse the repository at this point in the history
Fix: Support labels with dots in the ChecksumClient
  • Loading branch information
definitelyokay committed May 2, 2024
2 parents 794641b + fedf73b commit ef43bea
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/install_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ jobs:
matrix:
# Also try windows-2019?
os: [macos-latest, ubuntu-latest, windows-2019]
version: ["4.1.1", "4.3.0-dev.6"]
defaults:
run:
# Use bash shells on all platforms.
Expand All @@ -128,7 +129,7 @@ jobs:
run: |
# Use tool to install Godot. Last line of output is the path to the
# symlink that always points to the active version of Godot.
dotnet run -- godot install 4.1.1
dotnet run -- godot install ${{ matrix.version }}
- name: 🤖 Check Godot Location
working-directory: GodotEnv
Expand Down Expand Up @@ -174,6 +175,6 @@ jobs:
echo "Before uninstall:"
dotnet run -- godot list
echo "Uninstalling..."
dotnet run -- godot uninstall 4.1.1
dotnet run -- godot uninstall ${{ matrix.version }}
echo "After uninstall:"
dotnet run -- godot list
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class GodotChecksumClientTest {
yield return [new SemanticVersion("1", "0", "0"), false, GetChecksumFileUrl("1.0-stable")];
yield return [new SemanticVersion("4", "0", "0", "alpha14"), false, GetChecksumFileUrl("4.0-alpha14")];
yield return [new SemanticVersion("4", "2", "2", "rc1"), false, GetChecksumFileUrl("4.2.2-rc1")];
// GodotSharp nuget packages use a dot in the label, and this has to be supported as well.
yield return [new SemanticVersion("4", "3", "0", "dev.6"), false, GetChecksumFileUrl("4.3-dev6")];
}

[Theory]
Expand Down
4 changes: 2 additions & 2 deletions GodotEnv/src/features/godot/domain/GodotChecksumClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ IGodotEnvironment platform
private IGodotEnvironment Platform { get; } = platform;

private static string GetChecksumFileUrl(GodotCompressedArchive archive) {
var suffix = archive.Version.Label == string.Empty ? "-stable" : string.Empty;
var releaseFilename = $"godot-{archive.Version.AsGodotVersionString}{suffix}.json";
var suffix = archive.Version.LabelNoDots == string.Empty ? "-stable" : string.Empty;
var releaseFilename = $"godot-{archive.Version.Format(true, true)}{suffix}.json";
return $"https://raw.githubusercontent.com/godotengine/godot-builds/main/releases/{releaseFilename}";
}

Expand Down
18 changes: 12 additions & 6 deletions GodotEnv/src/features/godot/models/SemanticVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,21 @@ public record SemanticVersion(
public string LabelNoDots => Label.Replace(".", "");

/// <summary>Reconstructed version string.</summary>
public string VersionString => $"{Major}.{Minor}.{Patch}" +
(Label != "" ? $"-{Label}" : "");
public string VersionString => Format(false, false);

/// <summary>
/// Version string as Godot uses them (if Patch is zero, it isn't included).
/// Formats a Semantic version in different forms as various Godot locations
/// use them.
/// </summary>
public string AsGodotVersionString => $"{Major}.{Minor}" +
(Patch != "0" ? $".{Patch}" : "") +
(Label != "" ? $"-{Label}" : "");
/// <param name="omitPatchIfZero">If true, a patch of 0 will be omitted.</param>
/// <param name="noDotsInLabel">If true, all dots will be removed from the label.</param>
/// <returns></returns>
public string Format(bool omitPatchIfZero, bool noDotsInLabel) {
var label = noDotsInLabel ? LabelNoDots : Label;
var patch = (omitPatchIfZero && Patch == "0") ? "" : $".{Patch}";

return $"{Major}.{Minor}{patch}" + (label != "" ? $"-{label}" : "");
}

public override string ToString() =>
$"Major({Major}).Minor({Minor}).Patch({Patch})-Label({Label})";
Expand Down

0 comments on commit ef43bea

Please sign in to comment.