From 0955cfd8e43a93168856bfd13f3c264dbff7e657 Mon Sep 17 00:00:00 2001 From: Martin Fouilleul Date: Thu, 14 Mar 2024 10:33:25 +0100 Subject: [PATCH] * Package everything in build-all.yaml * Update tool to work with the new artifacts directory structure * Release artifacts can just be dropped and added to the path as a whole, no need for a first update step * Add --tarball option to orca update. This allows testing installs from CI artifacts without making a release --- .github/workflows/build-all.yaml | 65 ++++----- .github/workflows/create-release.yaml | 34 +---- scripts/dev.py | 20 ++- scripts/version.py | 16 --- src/tool/update.c | 194 +++++++++++++++++--------- 5 files changed, 184 insertions(+), 145 deletions(-) diff --git a/.github/workflows/build-all.yaml b/.github/workflows/build-all.yaml index 572ed37a..b0124ddc 100644 --- a/.github/workflows/build-all.yaml +++ b/.github/workflows/build-all.yaml @@ -2,9 +2,14 @@ name: build-all on: workflow_call: + inputs: + version: + type: string + required: false push: branches: - main + - webgpu-canvas jobs: build-dawn-mac: @@ -41,13 +46,17 @@ jobs: - name: Package shell: cmd run: | - orcadev.bat package-sdk orca-sdk-windows || exit 1 - tar --format=ustar -czf orca-sdk-windows.tar.gz orca-sdk-windows + if [${{ inputs.version }}]==[] ( + orcadev.bat install orca || exit 1 + ) else ( + orcadev.bat install --version ${{ inputs.version }} orca || exit 1 + ) + tar --format=ustar -czf orca-windows.tar.gz orca - uses: actions/upload-artifact@v4 with: - name: orca-sdk-windows - path: orca-sdk-windows.tar.gz + name: orca-windows + path: orca-windows.tar.gz build-macos-x64: needs: [build-dawn-mac] @@ -74,13 +83,17 @@ jobs: - name: Package run: | - ./orcadev package-sdk orca-sdk-mac-x64 - tar --format=ustar -czf orca-sdk-mac-x64.tar.gz orca-sdk-mac-x64 + if [ ${{ inputs.version }} != '' ] ; then + ./orcadev install --version ${{ inputs.version }} orca + else + ./orcadev install orca + fi + tar --format=ustar -czf orca-mac-x64.tar.gz orca - uses: actions/upload-artifact@v4 with: - name: orca-sdk-mac-x64 - path: orca-sdk-mac-x64.tar.gz + name: orca-mac-x64 + path: orca-mac-x64.tar.gz build-macos-arm64: needs: [build-dawn-mac] @@ -107,34 +120,14 @@ jobs: - name: Package run: | - ./orcadev package-sdk orca-sdk-mac-arm64 - tar --format=ustar -czf orca-sdk-mac-arm64.tar.gz orca-sdk-mac-arm64 + if [ ${{ inputs.version }} != '' ] ; then + ./orcadev install --version ${{ inputs.version }} orca + else + ./orcadev install orca + fi + tar --format=ustar -czf orca-mac-arm64.tar.gz orca - uses: actions/upload-artifact@v4 with: - name: orca-sdk-mac-arm64 - path: orca-sdk-mac-arm64.tar.gz - - mac-make-universal: - runs-on: macos-latest - needs: [build-macos-x64, build-macos-arm64] - steps: - - uses: actions/download-artifact@v4 - with: - path: artifacts - merge-multiple: true - - - name: Make universal binary - run: | - tar -xzf artifacts/orca-sdk-mac-x64.tar.gz - tar -xzf artifacts/orca-sdk-mac-arm64.tar.gz - lipo -create orca-sdk-mac-x64/bin/orca orca-sdk-mac-arm64/bin/orca -output orca - - - name: Tar - run: | - tar --format=ustar -czf orca-mac.tar.gz orca - - - uses: actions/upload-artifact@v4 - with: - name: orca-mac - path: orca-mac.tar.gz + name: orca-mac-arm64 + path: orca-mac-arm64.tar.gz diff --git a/.github/workflows/create-release.yaml b/.github/workflows/create-release.yaml index dd73081d..4258b93e 100644 --- a/.github/workflows/create-release.yaml +++ b/.github/workflows/create-release.yaml @@ -7,6 +7,8 @@ on: jobs: build-all: uses: ./.github/workflows/build-all.yaml + with: + version: ${{ github.ref_name }} release: runs-on: ubuntu-latest @@ -20,36 +22,12 @@ jobs: path: artifacts merge-multiple: true - - name: Untar - run: | - tar -xzf artifacts/orca-sdk-windows.tar.gz - tar -xzf artifacts/orca-sdk-mac-x64.tar.gz - tar -xzf artifacts/orca-sdk-mac-arm64.tar.gz - - - name: Package CLI Tool + - name: Copy run: | mkdir releases - cp orca-sdk-windows/bin/orca.exe releases - cp orca-mac.tar.gz releases - - - name: Package Windows SDK - run: | - find orca-sdk-windows -type f -exec sha1sum {} + | LC_ALL=C sort | sha1sum | cut -z -f 1 -d " " > sha1.sum - tar --format=ustar -czf releases/orca-sdk-windows.tar.gz orca-sdk-windows sha1.sum - - - name: Package Mac x64 Release - run: | - chmod +x orca-sdk-mac-x64/bin/orca - chmod +x orca-sdk-mac-x64/bin/orca_runtime - find orca-sdk-mac-x64 -type f -exec sha1sum {} + | LC_ALL=C sort | sha1sum | cut -z -f 1 -d " " > sha1.sum - tar --format=ustar -czf releases/orca-sdk-mac-x64.tar.gz orca-sdk-mac-x64 sha1.sum - - - name: Package Mac arm64 Release - run: | - chmod +x orca-sdk-mac-arm64/bin/orca - chmod +x orca-sdk-mac-arm64/bin/orca_runtime - find orca-sdk-mac-arm64 -type f -exec sha1sum {} + | LC_ALL=C sort | sha1sum | cut -z -f 1 -d " " > sha1.sum - tar --format=ustar -czf releases/orca-sdk-mac-arm64.tar.gz orca-sdk-mac-arm64 sha1.sum + cp artifacts/orca-windows.tar.gz releases + cp artifacts/orca-mac-x64.tar.gz releases + cp artifacts/orca-mac-arm64.tar.gz releases - uses: ncipollo/release-action@v1 with: diff --git a/scripts/dev.py b/scripts/dev.py index e31988aa..cd6ac456 100644 --- a/scripts/dev.py +++ b/scripts/dev.py @@ -16,7 +16,6 @@ from .log import * from .utils import pushd, removeall, yeetdir, yeetfile from .embed_text_files import * -from .version import orca_version ANGLE_VERSION = "2023-07-05" MAC_SDK_DIR = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" @@ -61,6 +60,7 @@ def attach_dev_commands(subparsers): package_cmd.set_defaults(func=dev_shellish(package_sdk)) install_cmd = subparsers.add_parser("install", help="Install a dev build of the Orca tools into the system Orca directory.") + install_cmd.add_argument("--version") install_cmd.add_argument("install_dir", nargs='?') install_cmd.set_defaults(func=dev_shellish(install)) @@ -1110,7 +1110,7 @@ def install(args): print() orca_dir = system_orca_dir() if args.install_dir == None else args.install_dir - version = orca_version() + version = f"dev-{orca_commit()}" if args.version == None else args.version dest = os.path.join(orca_dir, version) print(f"Installing dev build of Orca in {dest}") @@ -1341,6 +1341,22 @@ def get_source_root(): dir = newdir +def src_dir(): + # Fragile path adjustments! Yay! + return os.path.normpath(os.path.join(os.path.abspath(__file__), "../../src")) + + +def orca_commit(): + with pushd(src_dir()): + try: + res = subprocess.run(["git", "rev-parse", "--short", "HEAD"], check=True, capture_output=True, text=True) + commit = res.stdout.strip() + return commit + except subprocess.CalledProcessError: + log_warning("failed to look up current git hash") + return "unknown" + + def yeet(path): os.makedirs(path, exist_ok=True) shutil.rmtree(path) diff --git a/scripts/version.py b/scripts/version.py index e3e4dfec..6ab4c306 100644 --- a/scripts/version.py +++ b/scripts/version.py @@ -4,19 +4,3 @@ from .log import * from .utils import pushd - - -def src_dir(): - # Fragile path adjustments! Yay! - return os.path.normpath(os.path.join(os.path.abspath(__file__), "../../src")) - - -def orca_version(): - with pushd(src_dir()): - try: - res = subprocess.run(["git", "rev-parse", "--short", "HEAD"], check=True, capture_output=True, text=True) - version = res.stdout.strip() - return f"dev-{version}" - except subprocess.CalledProcessError: - log_warning("failed to look up current git hash for version number") - return "dev-unknown" diff --git a/src/tool/update.c b/src/tool/update.c index e5a52878..fe0b2cdd 100644 --- a/src/tool/update.c +++ b/src/tool/update.c @@ -15,12 +15,15 @@ #include "orca.h" #if OC_PLATFORM_WINDOWS - #define SDK_FILENAME OC_STR8("orca-sdk-windows") + #define RELEASE_FILENAME OC_STR8("orca-windows") + #define TOOL_NAME OC_STR8("orca.exe") #elif OC_PLATFORM_MACOS #if OC_ARCH_ARM64 - #define SDK_FILENAME OC_STR8("orca-sdk-mac-arm64") + #define RELEASE_FILENAME OC_STR8("orca-mac-arm64") + #define TOOL_NAME OC_STR8("orca") #else - #define SDK_FILENAME OC_STR8("orca-sdk-mac-x64") + #define RELEASE_FILENAME OC_STR8("orca-mac-x64") + #define TOOL_NAME OC_STR8("orca") #endif #else #error Unsupported platform @@ -41,8 +44,8 @@ int update(int argc, char** argv) Flag_Context c; flag_init_context(&c); - flag_help(&c, "Downloads and installs the latest version of Orca."); + char** tarball = flag_str(&c, NULL, "tarball", NULL, "update the Orca SDK from a tarball"); if(!flag_parse(&c, argc, argv)) { @@ -62,37 +65,9 @@ int update(int argc, char** argv) return 1; } - oc_str8 repo_url_base = OC_STR8("https://github.com/orca-app/orca"); - - //----------------------------------------------------------------------------- - // get the latest version number from github release url - //----------------------------------------------------------------------------- - oc_str8 latest_url = oc_path_append(&arena, repo_url_base, OC_STR8("/releases/latest")); - curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errbuf); - curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); - curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); // follow redirects - curl_easy_setopt(curl, CURLOPT_NOBODY, 1); - curl_easy_setopt(curl, CURLOPT_URL, latest_url.ptr); - CURLcode curl_code = curl_easy_perform(curl); - if(curl_code != CURLE_OK) - { - fprintf(stderr, "error: failed to fetch latest version: %s\n", curl_easy_strerror(curl_code)); - return 1; - } - - char* final_url_cstr = NULL; - curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &final_url_cstr); - oc_str8 final_url = oc_str8_push_cstring(&arena, final_url_cstr); - - oc_str8 version = oc_path_slice_filename(final_url); oc_str8 orca_dir = system_orca_dir(&arena); - oc_str8 version_dir = oc_path_append(&arena, orca_dir, version); - - if(oc_sys_exists(version_dir)) - { - printf("Already up to date with version %.*s\n", oc_str8_ip(version)); - return 0; - } + oc_str8 version = { 0 }; + oc_str8 version_dir = { 0 }; oc_str8 temp_dir = oc_path_append(&arena, orca_dir, OC_STR8("temporary")); if(oc_sys_exists(temp_dir)) @@ -101,55 +76,141 @@ int update(int argc, char** argv) } TRY(oc_sys_mkdirs(temp_dir)); - //----------------------------------------------------------------------------- - // update cli tool executable - //----------------------------------------------------------------------------- - oc_str8 current_tool_version = OC_STR8(TOSTRING(ORCA_TOOL_VERSION)); - if(oc_str8_cmp(current_tool_version, version) != 0) + if(!*tarball) { - return replace_yourself_and_update(curl, repo_url_base, orca_dir, current_tool_version, version); - } - - //----------------------------------------------------------------------------- - // download and extract latest version - //----------------------------------------------------------------------------- - { - printf("Downloading Orca SDK version %.*s...\n", oc_str8_ip(version)); - oc_str8 release_tarname = oc_str8_pushf(&arena, "%.*s.tar.gz", - oc_str8_ip(SDK_FILENAME)); - oc_str8 release_url = oc_str8_pushf(&arena, "/releases/latest/download/%.*s", - oc_str8_ip(release_tarname)); - release_url = oc_path_append(&arena, repo_url_base, release_url); - oc_str8 release_filepath = oc_path_append(&arena, temp_dir, release_tarname); - - curl_code = download_file(curl, release_url, release_filepath); + oc_str8 repo_url_base = OC_STR8("https://github.com/orca-app/orca"); + + //----------------------------------------------------------------------------- + // get the latest version number from github release url + //----------------------------------------------------------------------------- + oc_str8 latest_url = oc_path_append(&arena, repo_url_base, OC_STR8("/releases/latest")); + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errbuf); + curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); + curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); // follow redirects + curl_easy_setopt(curl, CURLOPT_NOBODY, 1); + curl_easy_setopt(curl, CURLOPT_URL, latest_url.ptr); + CURLcode curl_code = curl_easy_perform(curl); if(curl_code != CURLE_OK) { - fprintf(stderr, "error: failed to download file %s: %s\n", - release_url.ptr, curl_last_error(curl_code)); + fprintf(stderr, "error: failed to fetch latest version: %s\n", curl_easy_strerror(curl_code)); return 1; } + char* final_url_cstr = NULL; + curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &final_url_cstr); + oc_str8 final_url = oc_str8_push_cstring(&arena, final_url_cstr); + + version = oc_path_slice_filename(final_url); + version_dir = oc_path_append(&arena, orca_dir, version); + + if(oc_sys_exists(version_dir)) + { + printf("Already up to date with version %.*s\n", oc_str8_ip(version)); + goto end; + } + + /* + //----------------------------------------------------------------------------- + // update cli tool executable + //----------------------------------------------------------------------------- + oc_str8 current_tool_version = OC_STR8(TOSTRING(ORCA_TOOL_VERSION)); + if(oc_str8_cmp(current_tool_version, version) != 0) + { + return replace_yourself_and_update(curl, repo_url_base, orca_dir, current_tool_version, version); + } + */ + + //----------------------------------------------------------------------------- + // download and extract latest version + //----------------------------------------------------------------------------- + { + printf("Downloading Orca SDK version %.*s...\n", oc_str8_ip(version)); + + oc_str8 release_tarname = oc_str8_pushf(&arena, "%.*s.tar.gz", + oc_str8_ip(RELEASE_FILENAME)); + + oc_str8 release_url = oc_str8_pushf(&arena, "/releases/latest/download/%.*s", + oc_str8_ip(release_tarname)); + + release_url = oc_path_append(&arena, repo_url_base, release_url); + oc_str8 release_filepath = oc_path_append(&arena, temp_dir, release_tarname); + + curl_code = download_file(curl, release_url, release_filepath); + if(curl_code != CURLE_OK) + { + fprintf(stderr, "error: failed to download file %s: %s\n", + release_url.ptr, curl_last_error(curl_code)); + return 1; + } + + printf("Extracting Orca SDK...\n"); + if(!tarball_extract(release_filepath, temp_dir)) + { + fprintf(stderr, "error: failed to extract files from %s\n", release_filepath.ptr); + return 1; + } + } + } + else + { + oc_str8 tarballPath = OC_STR8(*tarball); + printf("Extracting Orca SDK...\n"); - if(!tarball_extract(release_filepath, temp_dir)) + if(!tarball_extract(tarballPath, temp_dir)) { - fprintf(stderr, "error: failed to extract files from %s\n", release_filepath.ptr); + fprintf(stderr, "error: failed to extract files from %s\n", *tarball); return 1; } - oc_str8 extracted_release = oc_path_append(&arena, temp_dir, SDK_FILENAME); - if(!oc_sys_move(extracted_release, version_dir)) + oc_str8 extracted_release = oc_path_append(&arena, temp_dir, OC_STR8("orca")); + oc_str8 versionPath = oc_path_append(&arena, extracted_release, OC_STR8("current_version")); + oc_file versionFile = oc_file_open(versionPath, OC_FILE_ACCESS_READ, OC_FILE_OPEN_NONE); + if(oc_file_is_nil(versionFile)) { - fprintf(stderr, "error: failed to move %s to %s\n", - extracted_release.ptr, version_dir.ptr); + fprintf(stderr, "error: failed to read version file %s\n", versionPath.ptr); return 1; } + + version.len = oc_file_size(versionFile), + version.ptr = oc_arena_push(&arena, version.len + 1); + oc_file_read(versionFile, version.len, version.ptr); + version.ptr[version.len] = '\0'; + + version_dir = oc_path_append(&arena, orca_dir, version); + if(oc_sys_exists(version_dir)) + { + printf("Already up to date with version %.*s\n", oc_str8_ip(version)); + return 0; + } } + //----------------------------------------------------------------------------- + // move files to the install dir + //----------------------------------------------------------------------------- + { + oc_str8 extracted_release = oc_path_append(&arena, temp_dir, OC_STR8("orca")); + oc_str8 release_sdk = oc_path_append(&arena, extracted_release, version); + + if(!oc_sys_move(release_sdk, version_dir)) + { + fprintf(stderr, "error: failed to move %s to %s\n", + release_sdk.ptr, version_dir.ptr); + return 1; + } + + oc_str8 release_tool = oc_path_append(&arena, extracted_release, TOOL_NAME); + if(!oc_sys_move(release_tool, version_dir)) + { + fprintf(stderr, "error: failed to move %s to %s\n", + release_tool.ptr, version_dir.ptr); + return 1; + } + } //----------------------------------------------------------------------------- // record checksum and update current_version file //----------------------------------------------------------------------------- { + /* oc_str8 checksum = { 0 }; oc_str8 checksum_path = oc_path_append(&arena, temp_dir, OC_STR8("sha1.sum")); oc_file checksum_file = oc_file_open(checksum_path, OC_FILE_ACCESS_READ, OC_FILE_OPEN_NONE); @@ -166,6 +227,7 @@ int update(int argc, char** argv) oc_file_close(checksum_file); if(checksum.len) + */ { oc_str8 all_versions = oc_path_append(&arena, orca_dir, OC_STR8("all_versions")); oc_file_open_flags open_flags = oc_sys_exists(all_versions) @@ -175,9 +237,12 @@ int update(int argc, char** argv) if(!oc_file_is_nil(file)) { oc_file_seek(file, 0, OC_FILE_SEEK_END); + /* oc_str8 version_and_checksum = oc_str8_pushf(&arena, "%.*s %.*s\n", oc_str8_ip(version), oc_str8_ip(checksum)); oc_file_write(file, version_and_checksum.len, version_and_checksum.ptr); + */ + oc_file_write(file, oc_str8_ip(version)); } else { @@ -192,6 +257,7 @@ int update(int argc, char** argv) fprintf(stderr, "error: failed to update current version file\n"); } +end: TRY(oc_sys_rmdir(temp_dir)); // NOTE(shaw): assuming that the cli tool will always just call update and @@ -263,6 +329,7 @@ static bool overwrite_current_version(oc_str8 new_version) return result; } +/* #if OC_PLATFORM_WINDOWS static int replace_yourself_and_update(CURL* curl, oc_str8 repo_url_base, oc_str8 orca_dir, oc_str8 old_version, oc_str8 new_version) @@ -386,3 +453,4 @@ static int replace_yourself_and_update(CURL* curl, oc_str8 repo_url_base, oc_str #else #error replace_yourself_and_update() not implemented on this platform #endif +*/