Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
*.cs eol=lf
*.json eol=lf
*.txt eol=lf
# Shell scripts must always be LF; CRLF breaks them on Linux/macOS checkouts
*.sh eol=lf

# Add any other file extensions that should use LF endings

# Explicitly declare binary files to prevent line ending conversion
*.exe binary
*.dll binary
*.icns binary
*.ico binary
*.png binary
95 changes: 95 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Build and package

on:
push:
branches: [ "master" ]
# matches both release tags (5.14.0) and pre-release tags (5.14.0-beta.1)
tags: [ "[0-9]+.[0-9]+.[0-9]+*" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:
inputs:
version:
description: "Optional version override, eg 5.14.0. Leave empty to use the version derived from git tags."
required: false
type: string

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# MinVer derives the version from tags, so the full history and tags are needed here too; without
# them every build would report 0.0.0-alpha.0
fetch-depth: 0

- name: Install .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x

- name: Restore
run: dotnet restore

- name: Test
run: dotnet test Tests/Tests.csproj -c Release --no-restore

# build.sh cross-publishes every runtime, so a single host is enough. macOS is used because packaging the
# macOS bundles correctly needs ditto and codesign.
package:
needs: test
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# MinVer needs the full history and tags to derive the version
fetch-depth: 0

- name: Install .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x

# The version comes from the git tag via MinVer, so no version file is read or written.
- name: Build
shell: bash
env:
VERSION_OVERRIDE: ${{ inputs.version }}
run: ./build.sh ${VERSION_OVERRIDE:+"$VERSION_OVERRIDE"}

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: object-editor
path: |
artifacts/*.zip
artifacts/*.tar.gz
if-no-files-found: error
retention-days: 14

release:
if: github.ref_type == 'tag'
needs: package
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true

- name: Create draft release
uses: softprops/action-gh-release@v2
with:
files: artifacts/*
draft: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
100 changes: 0 additions & 100 deletions .github/workflows/dotnet-desktop.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Common/Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.11" />
<PackageReference Include="NuGet.Versioning" Version="7.9.0" />
<PackageReference Include="NuGet.Versioning" Version="8.0.0" />
</ItemGroup>

</Project>
46 changes: 38 additions & 8 deletions Common/PlatformSpecific.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,46 @@ public static bool RunningAsAdmin()
}

public static string EditorPlatformZipName(OSPlatform platform) =>
platform == OSPlatform.Windows ? "win-x64.zip" :
platform == OSPlatform.OSX ? "osx-x64.tar" :
platform == OSPlatform.Linux ? "linux-x64.tar" :
throw new PlatformNotSupportedException();
EditorPlatformZipName(platform, RuntimeInformation.ProcessArchitecture);

// mac: object-editor-5.3.5-osx-x64.zip / object-editor-5.3.5-osx-arm64.zip
// linux: object-editor-5.3.5-linux-x64.tar.gz
// win: object-editor-5.3.5-win-x64.zip
public static string EditorPlatformZipName(OSPlatform platform, Architecture architecture)
{
var rid = RuntimeIdentifierFor(platform, architecture);

return platform == OSPlatform.Windows ? $"{rid}.zip"
: platform == OSPlatform.OSX ? $"{rid}.zip"
: platform == OSPlatform.Linux ? $"{rid}.tar.gz"
: throw new PlatformNotSupportedException();
}

public static string EditorPlatformBinaryName(OSPlatform platform) =>
platform == OSPlatform.Windows ? $"{VersionHelpers.ObjectEditorName}.exe" :
platform == OSPlatform.OSX ? VersionHelpers.ObjectEditorName :
platform == OSPlatform.Linux ? VersionHelpers.ObjectEditorName :
throw new PlatformNotSupportedException();
platform == OSPlatform.Windows ? $"{VersionHelpers.ObjectEditorName}.exe"
: platform == OSPlatform.OSX || platform == OSPlatform.Linux ? VersionHelpers.ObjectEditorName
: throw new PlatformNotSupportedException();

public static string EditorPlatformUpdaterName(OSPlatform platform) =>
platform == OSPlatform.Windows ? $"{VersionHelpers.ObjectEditorUpdaterName}.exe"
: platform == OSPlatform.OSX || platform == OSPlatform.Linux ? VersionHelpers.ObjectEditorUpdaterName
: throw new PlatformNotSupportedException();

// the runtime identifier used by build.sh, eg win-x64, osx-arm64, linux-x64
public static string RuntimeIdentifierFor(OSPlatform platform, Architecture architecture)
{
var arch = architecture switch
{
Architecture.X64 => "x64",
Architecture.Arm64 => "arm64",
_ => throw new PlatformNotSupportedException($"Architecture {architecture} is not supported."),
};

return platform == OSPlatform.Windows ? $"win-{arch}"
: platform == OSPlatform.OSX ? $"osx-{arch}"
: platform == OSPlatform.Linux ? $"linux-{arch}"
: throw new PlatformNotSupportedException();
}

public static OSPlatform GetPlatform =>
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? OSPlatform.Windows :
Expand Down
55 changes: 24 additions & 31 deletions Common/VersionHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using System.Diagnostics;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;

namespace Common;

Expand All @@ -19,15 +19,15 @@ public static class VersionHelpers
public static Process? OpenDownloadPage()
=> Process.Start(new ProcessStartInfo(GithubLatestReleaseDownloadPage) { UseShellExecute = true });

// win: object-editor-5.3.5-win-x64.zip
// osx: object-editor-5.3.5-osx-x64.tar
// linux: object-editor-5.3.5-linux-x64.tar
// win: object-editor-5.3.5-win-x64.zip
// osx: object-editor-5.3.5-osx-arm64.zip (or -osx-x64.zip)
// linux: object-editor-5.3.5-linux-x64.tar.gz

static string DownloadFilename(SemanticVersion latestVersion, OSPlatform platform)
=> $"object-editor-{latestVersion}-{PlatformSpecific.EditorPlatformZipName(platform)}";
static string DownloadFilename(SemanticVersion latestVersion, OSPlatform platform, Architecture architecture)
=> $"object-editor-{latestVersion}-{PlatformSpecific.EditorPlatformZipName(platform, architecture)}";

public static string UrlForDownload(SemanticVersion latestVersion, OSPlatform platform)
=> $"{GithubLatestReleaseDownloadPage}/download/{latestVersion}/{DownloadFilename(latestVersion, platform)}";
public static string UrlForDownload(SemanticVersion latestVersion, OSPlatform platform, Architecture? architecture = null)
=> $"{GithubLatestReleaseDownloadPage}/download/{latestVersion}/{DownloadFilename(latestVersion, platform, architecture ?? RuntimeInformation.ProcessArchitecture)}";

public static void StartAutoUpdater(ILogger logger, SemanticVersion currentVersion, SemanticVersion latestVersion)
{
Expand All @@ -48,17 +48,17 @@ public static void StartAutoUpdater(ILogger logger, SemanticVersion currentVersi
}
}

// The updater binary has no .exe suffix on Unix-like platforms.
var editorExe = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? $"{ObjectEditorUpdaterName}.exe"
: ObjectEditorUpdaterName;
if (!File.Exists(editorExe))
var editorExe = PlatformSpecific.EditorPlatformUpdaterName(PlatformSpecific.GetPlatform);
// resolve relative to the editor's own folder: inside a macOS .app bundle the working directory
// is unrelated to where the binaries live
var editorExePath = Path.Combine(Path.GetDirectoryName(Environment.ProcessPath) ?? ".", editorExe);
if (!File.Exists(editorExePath))
{
logger.LogError("Cannot find the auto-updater executable: {EditorExe}. You'll need to manually download the update.", editorExe);
logger.LogError("Cannot find the auto-updater executable: {EditorExePath}. You'll need to manually download the update.", editorExePath);
return;
}

var startInfo = new ProcessStartInfo(editorExe,
var startInfo = new ProcessStartInfo(editorExePath,
[
"--pid",
$"{Environment.ProcessId}",
Expand Down Expand Up @@ -103,24 +103,17 @@ public static SemanticVersion GetCurrentAppVersion()
return CachedSemanticVersion;
}

foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
// version.txt is an embedded resource in the Definitions assembly
using var stream = assembly.GetManifestResourceStream("Definitions.version.txt") ?? assembly.GetManifestResourceStream("version.txt");
if (stream == null)
{
continue;
}
// The version is baked into every assembly at build time by MinVer (from the git tag), so the running
// binary can never disagree with what it reports. SourceLink appends the commit hash as build metadata,
// which is not part of the version.
// Read from the assembly that defines this type rather than the entry assembly: it is always this
// product's assembly, even when the app is hosted by another process (eg a test runner or designer).
var informationalVersion = typeof(VersionHelpers).Assembly
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
.InformationalVersion;

using var ms = new MemoryStream();
stream.CopyTo(ms);
CachedSemanticVersion = GetVersionFromText(Encoding.ASCII.GetString(ms.ToArray()));
return CachedSemanticVersion;
}

CachedSemanticVersion = UnknownVersion;
CachedSemanticVersion = GetVersionFromText(informationalVersion?.Split('+')[0]);
return CachedSemanticVersion;

}

// A single, process-wide HttpClient avoids socket exhaustion that comes from
Expand Down
2 changes: 1 addition & 1 deletion Dat/Dat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SixLabors.ImageSharp" Version="4.1.1" />
<PackageReference Include="SixLabors.ImageSharp" Version="4.1.3" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 2 additions & 3 deletions Definitions/Definitions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="version.txt" />
<EmbeddedResource Include="Assets\palette.png">
<LogicalName>Core.palette.png</LogicalName>
</EmbeddedResource>
Expand All @@ -62,8 +61,8 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.11" />
<PackageReference Include="SixLabors.ImageSharp" Version="4.1.1" />
<PackageReference Include="System.IO.Hashing" Version="10.0.11" />
<PackageReference Include="SixLabors.ImageSharp" Version="4.1.3" />
<PackageReference Include="System.IO.Hashing" Version="11.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion Definitions/version.txt

This file was deleted.

Loading
Loading