Skip to content

Commit

Permalink
Merge pull request #33 from justinhhorner/v3_support
Browse files Browse the repository at this point in the history
Add support for Godot 3 downloads
  • Loading branch information
jolexxa authored Oct 16, 2023
2 parents d586f60 + 1a849c2 commit 493d81c
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 50 deletions.
86 changes: 84 additions & 2 deletions .github/workflows/install_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,90 @@ on:
pull_request:

jobs:
install_tests:
name: 🔋 Integration Tests with ${{ matrix.os }}
install_tests_3x:
name: 🔋 Godot 3.x Integration Tests with ${{ matrix.os }}
runs-on: ${{ matrix.os }}
# Only run the workflow if it's not a PR or if it's a PR from a fork.
# This prevents duplicate workflows from running on PR's that originate
# from the repository itself.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_NOLOGO: true
strategy:
# Don't cancel other runners if one fails.
fail-fast: false
matrix:
# Also try windows-2019?
os: [ macos-latest, ubuntu-latest, windows-2019 ]
defaults:
run:
# Use bash shells on all platforms.
shell: bash
steps:
- name: 🧾 Checkout
uses: actions/checkout@v3

- name: 💽 Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
# Use the .NET SDK from global.json in the root of the repository.
global-json-file: global.json

- name: 📦 Restore Dependencies
run: dotnet restore

- name: 🦺 Build Projects
run: dotnet build

- name: 🛣 Add Current Installation To Path
# Gets the last line of the output from the installation and adds it to the path.
working-directory: GodotEnv
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 3.5.3
- name: 🤖 Check Godot Location
working-directory: GodotEnv
run: |
# Get path to the symlink that always points to the active version of
# Godot.
GODOT_SYMLINK="$(dotnet run -- godot env path)"
# Make sure we can use Godot.
$GODOT_SYMLINK --version
echo "✅ Godot location is in path!"
- name: 🌴 Set GODOT System Environment Variable
working-directory: GodotEnv
run: |
dotnet run -- godot env setup
- name: 🧪 Verify GODOT System Environment Variable
working-directory: GodotEnv
run: |
# Make sure we can retrieve environment variable on all systems.
VERIFY_GODOT=$(dotnet run -- godot env get)
echo "GODOT=$VERIFY_GODOT"
if [ -z "$VERIFY_GODOT" ]; then
echo "❌ GODOT environment variable is empty!"
exit 1
fi
- name: 🗑 Uninstall
working-directory: GodotEnv
run: |
echo "Before uninstall:"
dotnet run -- godot list
echo "Uninstalling..."
dotnet run -- godot uninstall 3.5.3
echo "After uninstall:"
dotnet run -- godot list
install_tests_4x:
name: 🔋 Godot 4.x Integration Tests with ${{ matrix.os }}
runs-on: ${{ matrix.os }}
# Only run the workflow if it's not a PR or if it's a PR from a fork.
# This prevents duplicate workflows from running on PR's that originate
Expand Down
2 changes: 1 addition & 1 deletion GodotEnv.Tests/src/common/utilities/LogTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void OutputsCorrectStyleChanges() {
[/style][style fg="green"]F

[/style]
"""
""".ReplaceLineEndings()
);
}

Expand Down
60 changes: 38 additions & 22 deletions GodotEnv.Tests/src/features/godot/models/GodotEnvironmentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,77 +8,93 @@ namespace Chickensoft.GodotEnv.Tests.features.godot.models;
using Xunit;

public class GodotEnvironmentTest {
private readonly SemanticVersion version;
private readonly Mock<IComputer> computer;
private readonly Mock<IFileClient> fileClient;

public GodotEnvironmentTest() {
computer = new Mock<IComputer>();
fileClient = new Mock<IFileClient>();
version = new SemanticVersion("4", "1", "2", string.Empty);
}
private readonly Mock<IComputer> computer = new();
private readonly Mock<IFileClient> fileClient = new();
private readonly SemanticVersion version4 = new("4", "1", "2");
private readonly SemanticVersion version3 = new("3", "5", "3");

[Fact]
public void GetsExpectedMacDownloadUrl() {
var platform = new MacOS(fileClient.Object, computer.Object);
var downloadUrl = platform.GetDownloadUrl(version, false, false);

downloadUrl.ShouldBe($"{GodotEnvironment.GODOT_URL_PREFIX}4.1.2-stable/Godot_v4.1.2-stable_macos.universal.zip");
var downloadUrl = platform.GetDownloadUrl(version4, false, false);
downloadUrl.ShouldBe(GetExpectedDownloadUrl(version4, "stable_macos.universal"));

downloadUrl = platform.GetDownloadUrl(version3, false, false);
downloadUrl.ShouldBe(GetExpectedDownloadUrl(version3, "stable_osx.universal"));
}

[Fact]
public void GetsExpectedMacMonoDownloadUrl() {
var platform = new MacOS(fileClient.Object, computer.Object);
var downloadUrl = platform.GetDownloadUrl(version, true, false);

downloadUrl.ShouldBe($"{GodotEnvironment.GODOT_URL_PREFIX}4.1.2-stable/Godot_v4.1.2-stable_mono_macos.universal.zip");
var downloadUrl = platform.GetDownloadUrl(version4, true, false);
downloadUrl.ShouldBe(GetExpectedDownloadUrl(version4, "stable_mono_macos.universal"));

downloadUrl = platform.GetDownloadUrl(version3, true, false);
downloadUrl.ShouldBe(GetExpectedDownloadUrl(version3, "stable_mono_osx.universal"));
}

[Fact]
public void GetsExpectedWindowsDownloadUrl() {
var platform = new Windows(fileClient.Object, computer.Object);
var downloadUrl = platform.GetDownloadUrl(version, false, false);

var downloadUrl = platform.GetDownloadUrl(version4, false, false);
downloadUrl.ShouldBe($"{GodotEnvironment.GODOT_URL_PREFIX}4.1.2-stable/Godot_v4.1.2-stable_win64.exe.zip");

downloadUrl = platform.GetDownloadUrl(version3, false, false);
downloadUrl.ShouldBe($"{GodotEnvironment.GODOT_URL_PREFIX}{version3.VersionString}-stable/Godot_v{version3.VersionString}-stable_win64.exe.zip");
}

[Fact]
public void GetsExpectedWindowsMonoDownloadUrl() {
var platform = new Windows(fileClient.Object, computer.Object);
var downloadUrl = platform.GetDownloadUrl(version, true, false);

downloadUrl.ShouldBe($"{GodotEnvironment.GODOT_URL_PREFIX}4.1.2-stable/Godot_v4.1.2-stable_mono_win64.zip");
var downloadUrl = platform.GetDownloadUrl(version4, true, false);
downloadUrl.ShouldBe(GetExpectedDownloadUrl(version4, "stable_mono_win64"));

downloadUrl = platform.GetDownloadUrl(version3, true, false);
downloadUrl.ShouldBe(GetExpectedDownloadUrl(version3, "stable_mono_win64"));
}

[Fact]
public void GetsExpectedLinuxDownloadUrl() {
var platform = new Linux(fileClient.Object, computer.Object);
var downloadUrl = platform.GetDownloadUrl(version, false, false);

downloadUrl.ShouldBe($"{GodotEnvironment.GODOT_URL_PREFIX}4.1.2-stable/Godot_v4.1.2-stable_linux.x86_64.zip");
var downloadUrl = platform.GetDownloadUrl(version4, false, false);
downloadUrl.ShouldBe(GetExpectedDownloadUrl(version4, "stable_linux.x86_64"));

downloadUrl = platform.GetDownloadUrl(version3, false, false);
downloadUrl.ShouldBe(GetExpectedDownloadUrl(version3, "stable_x11.64"));
}

[Fact]
public void GetsExpectedLinuxMonoDownloadUrl() {
var platform = new Linux(fileClient.Object, computer.Object);
var downloadUrl = platform.GetDownloadUrl(version, true, false);

downloadUrl.ShouldBe($"{GodotEnvironment.GODOT_URL_PREFIX}4.1.2-stable/Godot_v4.1.2-stable_mono_linux_x86_64.zip");
var downloadUrl = platform.GetDownloadUrl(version4, true, false);
downloadUrl.ShouldBe(GetExpectedDownloadUrl(version4, "stable_mono_linux_x86_64"));

downloadUrl = platform.GetDownloadUrl(version3, true, false);
downloadUrl.ShouldBe(GetExpectedDownloadUrl(version3, "stable_mono_x11_64"));
}

[Fact]
public void GetsExpectedTemplatesDownloadUrl() {
var platform = new MacOS(fileClient.Object, computer.Object);
var downloadUrl = platform.GetDownloadUrl(version, false, true);
var downloadUrl = platform.GetDownloadUrl(version4, false, true);

downloadUrl.ShouldBe($"{GodotEnvironment.GODOT_URL_PREFIX}4.1.2-stable/Godot_v4.1.2-stable_export_templates.tpz");
}

[Fact]
public void GetsExpectedTemplatesMonoDownloadUrl() {
var platform = new MacOS(fileClient.Object, computer.Object);
var downloadUrl = platform.GetDownloadUrl(version, true, true);
var downloadUrl = platform.GetDownloadUrl(version4, true, true);

downloadUrl.ShouldBe($"{GodotEnvironment.GODOT_URL_PREFIX}4.1.2-stable/Godot_v4.1.2-stable_mono_export_templates.tpz");
}

private static string GetExpectedDownloadUrl(SemanticVersion version, string platformSuffix) =>
$"{GodotEnvironment.GODOT_URL_PREFIX}{version.VersionString}-stable/Godot_v{version.VersionString}-{platformSuffix}.zip";
}
6 changes: 3 additions & 3 deletions GodotEnv/src/features/godot/domain/GodotRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public async Task UpdateGodotSymlink(
if (installation.IsDotnetVersion) {
// Update GodotSharp symlinks
var godotSharpPath = GetGodotSharpPath(
installation.Path, installation.Version
installation.Path, installation.Version, installation.IsDotnetVersion
);

log.Print("");
Expand Down Expand Up @@ -495,10 +495,10 @@ private string GetExecutionPath(
);

private string GetGodotSharpPath(
string installationPath, SemanticVersion version
string installationPath, SemanticVersion version, bool isDotnetVersion
) => FileClient.Combine(
installationPath,
Platform.GetRelativeGodotSharpPath(version)
Platform.GetRelativeGodotSharpPath(version, isDotnetVersion)
);

private GodotInstallation? ReadInstallation(
Expand Down
13 changes: 8 additions & 5 deletions GodotEnv/src/features/godot/models/GodotEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ public interface IGodotEnvironment {
/// </summary>
/// <param name="isDotnetVersion">True if using the .NET-enabled version of Godot,
/// false otherwise.</param>
/// <param name="version">Godot version.</param>
/// <returns>Godot filename suffix.</returns>
string GetInstallerNameSuffix(bool isDotnetVersion);
string GetInstallerNameSuffix(bool isDotnetVersion, SemanticVersion version);

/// <summary>
/// Computes the local path where the Godot export templates should be
Expand Down Expand Up @@ -108,8 +109,9 @@ string GetRelativeExtractedExecutablePath(
/// directory that is included with Godot.
/// </summary>
/// <param name="version">Godot version.</param>
/// <param name="isDotnetVersion">Dotnet version indicator.</param>
/// <returns>Path to the GodotSharp directory.</returns>
string GetRelativeGodotSharpPath(SemanticVersion version);
string GetRelativeGodotSharpPath(SemanticVersion version, bool isDotnetVersion);
}

public abstract class GodotEnvironment : IGodotEnvironment {
Expand Down Expand Up @@ -145,14 +147,15 @@ protected GodotEnvironment(IFileClient fileClient, IComputer computer) {
public IComputer Computer { get; }

public abstract string ExportTemplatesBasePath { get; }
public abstract string GetInstallerNameSuffix(bool isDotnetVersion);
public abstract string GetInstallerNameSuffix(bool isDotnetVersion, SemanticVersion version);
public abstract void Describe(ILog log);
public abstract Task<bool> IsExecutable(IShell shell, IFileInfo file);
public abstract string GetRelativeExtractedExecutablePath(
SemanticVersion version, bool isDotnetVersion
);
public abstract string GetRelativeGodotSharpPath(
SemanticVersion version
SemanticVersion version,
bool isDotnetVersion
);

// TODO: Implement
Expand Down Expand Up @@ -300,7 +303,7 @@ protected static string GetFilenameVersionString(SemanticVersion version) {
// Gets the filename of the Godot installation download for the platform.
private string GetInstallerFilename(
SemanticVersion version, bool isDotnetVersion
) => GetFilenameVersionString(version) + GetInstallerNameSuffix(isDotnetVersion) +
) => GetFilenameVersionString(version) + GetInstallerNameSuffix(isDotnetVersion, version) +
".zip";

// Gets the filename of the Godot export templates installation download for
Expand Down
41 changes: 31 additions & 10 deletions GodotEnv/src/features/godot/models/Linux.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,52 @@ public Linux(IFileClient fileClient, IComputer computer)
FileClient.UserDirectory, ".local/share/godot"
);

public override string GetInstallerNameSuffix(bool isDotnetVersion) =>
isDotnetVersion ? "_mono_linux_x86_64" : "_linux.x86_64";
public override string GetInstallerNameSuffix(bool isDotnetVersion, SemanticVersion version) {
var (platformName, architecture) = GetPlatformNameAndArchitecture(version);

return isDotnetVersion ? $"_mono_{platformName}_{architecture}" : $"_{platformName}.{architecture}";
}

public override void Describe(ILog log) => log.Info("🐧 Running on Linux");

public override string GetRelativeExtractedExecutablePath(
SemanticVersion version, bool isDotnetVersion
) {
var fsVersionString = GetFilenameVersionString(version);
var name = fsVersionString +
$"{(isDotnetVersion ? "_mono" : "")}_linux.x86_64";
var nameSuffix = GetInstallerNameSuffix(isDotnetVersion, version);
var (platformName, architecture) = GetPlatformNameAndArchitecture(version);

var pathSuffix = fsVersionString +
$"{(isDotnetVersion ? "_mono" : "")}_{platformName}.{architecture}";

if (isDotnetVersion) {
// Dotnet version extracts to a folder, whereas the non-dotnet version
// does not.
return FileClient.Combine(fsVersionString + "_mono_linux_x86_64", name);
return FileClient.Combine(fsVersionString + nameSuffix, pathSuffix);
}

return name;
return pathSuffix;
}

public override string GetRelativeGodotSharpPath(
SemanticVersion version
SemanticVersion version,
bool isDotnetVersion
) => FileClient.Combine(
GetFilenameVersionString(version) + "_mono_linux_x86_64",
"GodotSharp/"
);
GetFilenameVersionString(version) + GetInstallerNameSuffix(isDotnetVersion, version),
"GodotSharp/"
);

private static (string platformName, string architecture) GetPlatformNameAndArchitecture(
SemanticVersion version
) {
var architecture = "x86_64";
var platformName = "linux";

if (int.TryParse(version.Major, out var parsedVersion) && parsedVersion == 3) {
architecture = "64";
platformName = "x11";
}

return (platformName, architecture);
}
}
7 changes: 4 additions & 3 deletions GodotEnv/src/features/godot/models/MacOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public MacOS(IFileClient fileClient, IComputer computer)
)
);

public override string GetInstallerNameSuffix(bool isDotnetVersion) =>
$"{(isDotnetVersion ? "_mono" : "")}_macos.universal";
public override string GetInstallerNameSuffix(bool isDotnetVersion, SemanticVersion version) =>
$"{(isDotnetVersion ? "_mono" : "")}_{(int.Parse(version.Major) == 3 ? "osx" : "macos")}.universal";

public override void Describe(ILog log) => log.Info("🍏 Running on macOS");

Expand All @@ -24,6 +24,7 @@ public override string GetRelativeExtractedExecutablePath(
) => $"Godot{(isDotnetVersion ? "_mono" : "")}.app/Contents/MacOS/Godot";

public override string GetRelativeGodotSharpPath(
SemanticVersion version
SemanticVersion version,
bool isDotnetVersion
) => "Godot_mono.app/Contents/Resources/GodotSharp";
}
2 changes: 1 addition & 1 deletion GodotEnv/src/features/godot/models/SemanticVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Chickensoft.GodotEnv.Features.Godot.Models;
using System.Text.RegularExpressions;

public record SemanticVersion(
string Major, string Minor, string Patch, string Label
string Major, string Minor, string Patch, string Label = ""
) {
// Borrowed from https://semver.org/

Expand Down
5 changes: 3 additions & 2 deletions GodotEnv/src/features/godot/models/Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public Windows(IFileClient fileClient, IComputer computer)
FileClient.Combine(FileClient.UserDirectory, "\\AppData\\Roaming\\Godot")
);

public override string GetInstallerNameSuffix(bool isDotnetVersion) =>
public override string GetInstallerNameSuffix(bool isDotnetVersion, SemanticVersion version) =>
isDotnetVersion ? "_mono_win64" : "_win64.exe";

public override Task<bool> IsExecutable(IShell shell, IFileInfo file) =>
Expand Down Expand Up @@ -42,7 +42,8 @@ public override string GetRelativeExtractedExecutablePath(
}

public override string GetRelativeGodotSharpPath(
SemanticVersion version
SemanticVersion version,
bool isDotnetVersion
) => FileClient.Combine(
GetFilenameVersionString(version) + "_mono_win64", "GodotSharp"
);
Expand Down
Loading

0 comments on commit 493d81c

Please sign in to comment.