From a461901fe11d8df93fd17930db56e42a90c90330 Mon Sep 17 00:00:00 2001 From: CoolLoong <1542536763@qq.com> Date: Thu, 14 Dec 2023 16:58:45 +0800 Subject: [PATCH] feat: support install bdslib and cache --- .github/workflows/build.yml | 20 ++++++++++++-- bdsversion | 2 ++ xmake.lua | 53 +++++++++++++++++++++++++++++++++++-- 3 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 bdsversion diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 300ad33ad..d8aa09269 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,21 +23,37 @@ jobs: runs-on: windows-latest steps: - uses: actions/checkout@v4 + + - name: Read bdsversion file + id: read-version + run: | + VERSION_TYPE=$(grep -oP 'type=\K[^,]+' bdsversion) + VERSION_NUMBER=$(grep -oP 'version=\K[^,]+' bdsversion) + echo "version_type=${VERSION_TYPE}" >> $GITHUB_ENV + echo "version_number=${VERSION_NUMBER}" >> $GITHUB_ENV - uses: xmake-io/github-action-setup-xmake@v1 - + - uses: actions/cache@v3 with: path: | ~/AppData/Local/.xmake .xmake - key: xmake-dataextractor-windows-x64-${{ github.sha }} + build/bds/lib + key: | + xmake-dataextractor-windows-x64-${{ github.sha }} + xmake-dataextractor-windows-x64-${{ github.sha }} + bdslib-${{ env.version_type }}-${{ env.version_number }} restore-keys: | xmake-dataextractor-windows-x64- + xmake-dataextractor-windows-x64- - run: | xmake repo -u + - run: | + xmake bds-lib -b --${{ env.version_type }}=${{ env.version_number }} + - run: | xmake f -a x64 -m release -p windows -v -y --ccache=n diff --git a/bdsversion b/bdsversion new file mode 100644 index 000000000..a392c8efe --- /dev/null +++ b/bdsversion @@ -0,0 +1,2 @@ +type=release +version=1.20.50.03 \ No newline at end of file diff --git a/xmake.lua b/xmake.lua index 3a9adaa14..cb573b0c2 100644 --- a/xmake.lua +++ b/xmake.lua @@ -63,7 +63,7 @@ target("DataExtractor") task("bds-lib") on_run(function () import("core.base.option") - local actions = {"remote", "local", "clean", "tool"} + local actions = {"remote", "local", "clean", "tool", "bdsversion"} -- error if multiple actions are specified or no action is specified local action = nil for _, a in ipairs(actions) do @@ -93,6 +93,52 @@ task("bds-lib") local tool_dir = path.join(config.buildir(), "tools") os.rm(tool_dir) print("[localbdslibrary] Toolchain has been cleared.") + elseif action == "bdsversion" then + import("utils.archive") + import("core.project.config") + import("net.http") + + local pe_editor_version = "v3.3.0" + local lib_path = path.join(config.buildir(), "bds", "lib") + local bedrock_server_api = path.join(lib_path, "bedrock_server_api.lib") + local bedrock_server_var = path.join(lib_path, "bedrock_server_var.lib") + if os.isfile(bedrock_server_api) and os.isfile(bedrock_server_var) then + print("[localbdslibrary] Local bds library found, skipping generation") + return + end + + local release_ver = "1.20.50.03" + local tools_path = path.join(config.buildir(), "tools", "PeEditor-" .. pe_editor_version .. ".exe") + if not os.isfile(tools_path) then + -- not found, download it + print("[localbdslibrary] Downloading PeEditor.exe...") + http.download("https://github.com/LiteLDev/PeEditor/releases/download/" .. pe_editor_version .. "/PeEditor.exe", tools_path) + if not os.isfile(tools_path) then + raise("[localbdslibrary] Failed to download PeEditor.exe") + end + print("[localbdslibrary] PeEditor.exe downloaded successfully") + end + local lib_path = path.join(config.buildir(), "bds" , "lib") + local url = nil + local bds_path = nil + if option.get("release") then + url = "https://minecraft.azureedge.net/bin-win/bedrock-server-".. option.get("release") ..".zip" + bds_path = path.join(config.buildir(), "bds" , "instance" , "bedrock-server-".. option.get("release") ..".zip") + elseif option.get("preview") then + url = "https://minecraft.azureedge.net/bin-win-preview/bedrock-server-".. option.get("preview") ..".zip" + bds_path = path.join(config.buildir(), "bds" , "instance" , "bedrock-server-".. option.get("preview") ..".zip") + else + raise("[localbdslibrary] Failed to set bedrock version") + end + print("[localbdslibrary] Downloading bedrock_server...") + http.download(url, bds_path) + if not os.isfile(bds_path) then + raise("[localbdslibrary] Failed to download bedrock_server") + end + print("[localbdslibrary] bedrock_server downloaded successfully") + local unzip_path = path.join(config.buildir(), "bds" , "instance") + archive.extract(bds_path, unzip_path) + os.vexec("%s -l -o %s --pdb %s", tools_path, lib_path , path.join(unzip_path, "bedrock_server.pdb")) end end) @@ -103,6 +149,9 @@ task("bds-lib") {'r', "remote", "k", nil, "Use remote BDS library"}, {'l', "local", "k", nil, "Use local BDS library"}, {'c', "clean", "k", nil, "Clean local BDS library"}, - {'t', "tool", "k", nil, "Remove toolchain"} + {'t', "tool", "k", nil, "Remove toolchain"}, + {'b', "bdsversion", "k", nil, "From specified bdsversion to install BDS library"}, + {nil, "release", "kv", "1.20.50.03", "choose release version"}, + {nil, "preview", "kv", "1.20.60.22", "choose preview version"} } } \ No newline at end of file