diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1921310..294c81f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,28 +6,33 @@ jobs: strategy: matrix: configuration: [Debug, Release] - platform: [x64] + runs-on: windows-latest steps: - uses: actions/checkout@v3 with: submodules: true + - uses: actions/setup-dotnet@v3 with: dotnet-version: '6.x' + - name: Restore dependencies run: dotnet restore + - name: Build run: dotnet build --no-restore + - name: Publish - run: dotnet publish -p:PublishSingleFile=true -r win-${{ matrix.platform }} -c ${{ matrix.configuration }} --self-contained false .\Bloxstrap\Bloxstrap.csproj + run: dotnet publish -p:PublishSingleFile=true -p:CommitHash=${{ github.sha }} -p:CommitRef=${{ github.ref_type }}/${{ github.ref_name }} -r win-x64 -c ${{ matrix.configuration }} --self-contained false .\Bloxstrap\Bloxstrap.csproj + - name: Upload Artifact uses: actions/upload-artifact@v3 with: - name: Bloxstrap (${{ matrix.configuration }}, ${{ matrix.platform }}) + name: Bloxstrap (${{ matrix.configuration }}, x64) path: | - .\Bloxstrap\bin\${{ matrix.configuration }}\net6.0-windows\win-${{ matrix.platform }}\publish\* + .\Bloxstrap\bin\${{ matrix.configuration }}\net6.0-windows\win-x64\publish\* release: needs: build @@ -40,9 +45,11 @@ jobs: with: name: Bloxstrap (Release, x64) path: x64 + - name: Rename binaries run: | mv x64/Bloxstrap.exe Bloxstrap-${{ github.ref_name }}-x64.exe + - name: Release uses: softprops/action-gh-release@v1 with: diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index d2c1cd0..1b5a504 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -15,6 +15,7 @@ using Microsoft.Win32; using Bloxstrap.Extensions; using Bloxstrap.Models; +using Bloxstrap.Models.Attributes; using Bloxstrap.UI.BootstrapperDialogs; using Bloxstrap.UI.Menu.Views; using Bloxstrap.Utility; @@ -44,6 +45,7 @@ namespace Bloxstrap public static bool IsMenuLaunch { get; private set; } = false; public static string[] LaunchArgs { get; private set; } = null!; + public static BuildMetadataAttribute BuildMetadata => Assembly.GetExecutingAssembly().GetCustomAttribute()!; public static string Version = Assembly.GetExecutingAssembly().GetName().Version!.ToString()[..^2]; // singletons @@ -118,6 +120,11 @@ namespace Bloxstrap Logger.WriteLine($"[App::OnStartup] Starting {ProjectName} v{Version}"); + if (String.IsNullOrEmpty(BuildMetadata.CommitHash)) + Logger.WriteLine($"[App::OnStartup] Compiled {BuildMetadata.Timestamp.ToFriendlyString()} from {BuildMetadata.Machine}"); + else + Logger.WriteLine($"[App::OnStartup] Compiled {BuildMetadata.Timestamp.ToFriendlyString()} from commit {BuildMetadata.CommitHash} ({BuildMetadata.CommitRef})"); + // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); diff --git a/Bloxstrap/Bloxstrap.csproj b/Bloxstrap/Bloxstrap.csproj index 24f4203..c4cccd6 100644 --- a/Bloxstrap/Bloxstrap.csproj +++ b/Bloxstrap/Bloxstrap.csproj @@ -39,4 +39,13 @@ + + + <_Parameter1>$([System.DateTime]::UtcNow.ToString("s"))Z + <_Parameter2>$(COMPUTERNAME)\$(USERNAME) + <_Parameter3>$(CommitHash) + <_Parameter4>$(CommitRef) + + + diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index 5c17080..2676e9c 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -576,25 +576,34 @@ namespace Bloxstrap return; } - string currentVersion = $"{App.ProjectName} v{App.Version}"; - App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] Checking for {App.ProjectName} updates..."); var releaseInfo = await Utilities.GetJson($"https://api.github.com/repos/{App.ProjectRepository}/releases/latest"); - if (releaseInfo?.Assets is null || currentVersion == releaseInfo.Name) + if (releaseInfo is null || releaseInfo.Assets is null) { App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] No updates found"); return; } + int numCurrentVersion = Utilities.VersionToNumber(App.Version); + int numLatestVersion = Utilities.VersionToNumber(releaseInfo.TagName); + + // check if we aren't using a deployed build, so we can update to one if a new version comes out + if (numCurrentVersion == numLatestVersion && App.BuildMetadata.CommitRef.StartsWith("tag") || numCurrentVersion > numLatestVersion) + { + App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] No updates found"); + return; + } + + SetStatus($"Getting the latest {App.ProjectName}..."); // 64-bit is always the first option GithubReleaseAsset asset = releaseInfo.Assets[0]; string downloadLocation = Path.Combine(Directories.LocalAppData, "Temp", asset.Name); - App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] Downloading {releaseInfo.Name}..."); + App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] Downloading {releaseInfo.TagName}..."); if (!File.Exists(downloadLocation)) { @@ -604,7 +613,7 @@ namespace Bloxstrap await response.Content.CopyToAsync(fileStream); } - App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] Starting {releaseInfo.Name}..."); + App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] Starting {releaseInfo.TagName}..."); ProcessStartInfo startInfo = new() { diff --git a/Bloxstrap/Extensions/DateTimeEx.cs b/Bloxstrap/Extensions/DateTimeEx.cs new file mode 100644 index 0000000..f30d011 --- /dev/null +++ b/Bloxstrap/Extensions/DateTimeEx.cs @@ -0,0 +1,12 @@ +using System; + +namespace Bloxstrap.Extensions +{ + static class DateTimeEx + { + public static string ToFriendlyString(this DateTime dateTime) + { + return dateTime.ToString("dddd, d MMMM yyyy 'at' h:mm:ss tt", App.CultureFormat); + } + } +} diff --git a/Bloxstrap/Logger.cs b/Bloxstrap/Logger.cs index ad4bc93..883dac2 100644 --- a/Bloxstrap/Logger.cs +++ b/Bloxstrap/Logger.cs @@ -39,9 +39,9 @@ namespace Bloxstrap public void WriteLine(string message) { - string timestamp = DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'"); + string timestamp = DateTime.UtcNow.ToString("s") + "Z"; string outcon = $"{timestamp} {message}"; - string outlog = outcon.Replace(Directories.UserProfile, ""); + string outlog = outcon.Replace(Directories.UserProfile, "%UserProfile%"); Debug.WriteLine(outcon); WriteToLog(outlog); diff --git a/Bloxstrap/Models/Attributes/CompileTimeInfoAttribute.cs b/Bloxstrap/Models/Attributes/CompileTimeInfoAttribute.cs new file mode 100644 index 0000000..32423f3 --- /dev/null +++ b/Bloxstrap/Models/Attributes/CompileTimeInfoAttribute.cs @@ -0,0 +1,21 @@ +using System; + +namespace Bloxstrap.Models.Attributes +{ + [AttributeUsage(AttributeTargets.Assembly)] + public class BuildMetadataAttribute : Attribute + { + public DateTime Timestamp { get; set; } + public string Machine { get; set; } + public string CommitHash { get; set; } + public string CommitRef { get; set; } + + public BuildMetadataAttribute(string timestamp, string machine, string commitHash, string commitRef) + { + Timestamp = DateTime.Parse(timestamp).ToLocalTime(); + Machine = machine; + CommitHash = commitHash; + CommitRef = commitRef; + } + } +} diff --git a/Bloxstrap/UI/Menu/ViewModels/AboutViewModel.cs b/Bloxstrap/UI/Menu/ViewModels/AboutViewModel.cs index 89566dc..cea0d43 100644 --- a/Bloxstrap/UI/Menu/ViewModels/AboutViewModel.cs +++ b/Bloxstrap/UI/Menu/ViewModels/AboutViewModel.cs @@ -1,7 +1,21 @@ -namespace Bloxstrap.UI.Menu.ViewModels +using System; +using System.Windows; + +using Bloxstrap.Extensions; +using Bloxstrap.Models.Attributes; + +namespace Bloxstrap.UI.Menu.ViewModels { public class AboutViewModel { public string Version => $"Version {App.Version}"; + + public BuildMetadataAttribute BuildMetadata => App.BuildMetadata; + + public string BuildTimestamp => BuildMetadata.Timestamp.ToFriendlyString(); + public string BuildCommitHashUrl => $"https://github.com/{App.ProjectRepository}/commit/{BuildMetadata.CommitHash}"; + + public Visibility BuildInformationVisibility => BuildMetadata.CommitRef.StartsWith("tag") ? Visibility.Collapsed : Visibility.Visible; + public Visibility BuildCommitVisibility => String.IsNullOrEmpty(BuildMetadata.CommitHash) ? Visibility.Collapsed : Visibility.Visible; } } diff --git a/Bloxstrap/UI/Menu/ViewModels/InstallationViewModel.cs b/Bloxstrap/UI/Menu/ViewModels/InstallationViewModel.cs index e3ca027..cfd75b5 100644 --- a/Bloxstrap/UI/Menu/ViewModels/InstallationViewModel.cs +++ b/Bloxstrap/UI/Menu/ViewModels/InstallationViewModel.cs @@ -12,6 +12,7 @@ using System.Windows.Input; using CommunityToolkit.Mvvm.Input; using Bloxstrap.Enums; +using Bloxstrap.Extensions; using Bloxstrap.Models; namespace Bloxstrap.UI.Menu.ViewModels @@ -50,7 +51,7 @@ namespace Bloxstrap.UI.Menu.ViewModels { Version = info.Version, VersionGuid = info.VersionGuid, - Timestamp = info.Timestamp?.ToString("dddd, d MMMM yyyy 'at' h:mm:ss tt", App.CultureFormat)! + Timestamp = info.Timestamp?.ToFriendlyString()! }; OnPropertyChanged(nameof(ChannelDeployInfo)); diff --git a/Bloxstrap/UI/Menu/Views/Pages/AboutPage.xaml b/Bloxstrap/UI/Menu/Views/Pages/AboutPage.xaml index 2a6f0bc..e2a3d09 100644 --- a/Bloxstrap/UI/Menu/Views/Pages/AboutPage.xaml +++ b/Bloxstrap/UI/Menu/Views/Pages/AboutPage.xaml @@ -41,6 +41,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Bloxstrap/Updater.cs b/Bloxstrap/Updater.cs index d229f1c..e9d53a4 100644 --- a/Bloxstrap/Updater.cs +++ b/Bloxstrap/Updater.cs @@ -19,11 +19,9 @@ namespace Bloxstrap // 2.0.0 downloads updates to /Updates so lol bool isAutoUpgrade = Environment.ProcessPath.StartsWith(Path.Combine(Directories.Base, "Updates")) || Environment.ProcessPath.StartsWith(Path.Combine(Directories.LocalAppData, "Temp")); - // if downloaded version doesn't match, replace installed version with downloaded version FileVersionInfo currentVersionInfo = FileVersionInfo.GetVersionInfo(Environment.ProcessPath); - FileVersionInfo installedVersionInfo = FileVersionInfo.GetVersionInfo(Directories.Application); - if (installedVersionInfo.ProductVersion == currentVersionInfo.ProductVersion) + if (Utility.MD5Hash.FromFile(Environment.ProcessPath) == Utility.MD5Hash.FromFile(Directories.Application)) return; MessageBoxResult result; diff --git a/Bloxstrap/Utilities.cs b/Bloxstrap/Utilities.cs index 53571d9..4371146 100644 --- a/Bloxstrap/Utilities.cs +++ b/Bloxstrap/Utilities.cs @@ -39,5 +39,12 @@ namespace Bloxstrap return default; } } + + public static int VersionToNumber(string version) + { + // yes this is kinda stupid lol + version = version.Replace("v", "").Replace(".", ""); + return Int32.Parse(version); + } } }