From ad3499d7a7511297fbb3ba1a24b72a88390f73db Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Thu, 3 Oct 2024 18:45:09 +0700 Subject: [PATCH] fix: updater universal --- .github/workflows/nightly-build.yml | 5 +++-- engine/commands/cortex_upd_cmd.cc | 25 ++++++++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/.github/workflows/nightly-build.yml b/.github/workflows/nightly-build.yml index 395b70786..8816ca6a7 100644 --- a/.github/workflows/nightly-build.yml +++ b/.github/workflows/nightly-build.yml @@ -96,8 +96,9 @@ jobs: run: | echo "{\"tag_name\": \"v${{ needs.get-update-version.outputs.new_version }}\"}" > version.json aws s3 cp version.json s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/latest/version.json - aws s3 cp s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/temp-latest/mac-amd64-cortex-nightly.tar.gz s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/latest/mac-amd64/cortex-nightly.tar.gz - aws s3 cp s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/temp-latest/mac-arm64-cortex-nightly.tar.gz s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/latest/mac-arm64/cortex-nightly.tar.gz + aws s3 cp s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/temp-latest/mac-universal-cortex-nightly.tar.gz s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/latest/mac-amd64/cortex-nightly.tar.gz + aws s3 cp s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/temp-latest/mac-universal-cortex-nightly.tar.gz s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/latest/mac-arm64/cortex-nightly.tar.gz + aws s3 cp s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/temp-latest/mac-universal-cortex-nightly.tar.gz s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/latest/mac-universal/cortex-nightly.tar.gz aws s3 cp s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/temp-latest/linux-amd64-cortex-nightly.tar.gz s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/latest/linux-amd64/cortex-nightly.tar.gz aws s3 cp s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/temp-latest/windows-amd64-cortex-nightly.tar.gz s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/latest/windows-amd64/cortex-nightly.tar.gz diff --git a/engine/commands/cortex_upd_cmd.cc b/engine/commands/cortex_upd_cmd.cc index 9947b1da0..51a9308af 100644 --- a/engine/commands/cortex_upd_cmd.cc +++ b/engine/commands/cortex_upd_cmd.cc @@ -27,6 +27,16 @@ std::chrono::seconds GetTimeSinceEpochMillisec() { using namespace std::chrono; return duration_cast(system_clock::now().time_since_epoch()); } + +std::unique_ptr GetSystemInfoWithUniversal() { + auto system_info = system_info_utils::GetSystemInfo(); + if (system_info->os == "mac") { + CTL_INF("Change arch from " << system_info->arch << " to universal"); + system_info->arch = "universal"; + } + return system_info; +} + } // namespace std::optional CheckNewUpdate( @@ -222,7 +232,7 @@ void CortexUpdCmd::Exec(const std::string& v) { } bool CortexUpdCmd::GetStable(const std::string& v) { - auto system_info = system_info_utils::GetSystemInfo(); + auto system_info = GetSystemInfoWithUniversal(); CTL_INF("OS: " << system_info->os << ", Arch: " << system_info->arch); // Download file @@ -276,7 +286,7 @@ bool CortexUpdCmd::GetStable(const std::string& v) { } bool CortexUpdCmd::GetBeta(const std::string& v) { - auto system_info = system_info_utils::GetSystemInfo(); + auto system_info = GetSystemInfoWithUniversal(); CTL_INF("OS: " << system_info->os << ", Arch: " << system_info->arch); // Download file @@ -407,11 +417,11 @@ bool CortexUpdCmd::HandleGithubRelease(const nlohmann::json& assets, } bool CortexUpdCmd::GetNightly(const std::string& v) { - auto system_info = system_info_utils::GetSystemInfo(); + auto system_info = GetSystemInfoWithUniversal(); CTL_INF("OS: " << system_info->os << ", Arch: " << system_info->arch); // Download file - std::string version = v.empty() ? "latest" : std::move(v); + std::string version = v.empty() ? "latest" : v; std::string os_arch{system_info->os + "-" + system_info->arch}; const char* paths[] = { "cortex", @@ -447,7 +457,7 @@ bool CortexUpdCmd::GetNightly(const std::string& v) { .localPath = localPath, }}}; - DownloadService().AddDownloadTask( + auto res = DownloadService().AddDownloadTask( download_task, [](const DownloadTask& finishedTask) { // try to unzip the downloaded file CTL_INF("Downloaded engine path: " @@ -462,6 +472,11 @@ bool CortexUpdCmd::GetNightly(const std::string& v) { CTL_INF("Finished!"); }); + if (res.has_error()) { + CLI_LOG("Download failed!"); + return false; + } + // Replace binary file auto executable_path = file_manager_utils::GetExecutableFolderContainerPath(); auto src =