From 5694fa53c08045bdbd45d42ec27b5d1fe161def2 Mon Sep 17 00:00:00 2001 From: CoolLoong <1542536763@qq.com> Date: Thu, 14 Dec 2023 17:54:36 +0800 Subject: [PATCH] build: add workflow (#8) * build: add workflow * feat: support install bdslib and cache * fix: try * fix: try * fix: try * fix: try * fix: try * fix: try * fix: try * build: only master and dev * build: only master and dev --- .github/workflows/build.yml | 72 +++++++++++++++++++++++++++++++++++++ bdsversion | 2 ++ xmake.lua | 55 ++++++++++++++++++++++++++-- 3 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 bdsversion diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..9caf07e2a --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,72 @@ +on: + push: + branches: + - master + - dev + paths: + - .github/workflows/build.yml + - scripts/localbdslibrary.lua + - src/** + - xmake.lua + pull_request: + branches: + - master + - dev + paths: + - .github/workflows/build.yml + - scripts/localbdslibrary.lua + - src/** + - xmake.lua + workflow_dispatch: + +jobs: + build: + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + + - name: Read bdsversion file + id: read-bdsversion + run: | + $content = Get-Content -Path .\bdsversion -Raw + $type = ($content | Select-String -Pattern 'type=(.*)' | ForEach-Object { $_.Matches.Groups[1].Value }).Trim() + $version = ($content | Select-String -Pattern 'version=(.*)' | ForEach-Object { $_.Matches.Groups[1].Value }).Trim() + echo "::set-output name=version_type::$type" + echo "::set-output name=version_number::$version" + printf '%s\n' "$type" + printf '%s\n' "$version" + + - uses: xmake-io/github-action-setup-xmake@v1 + + - uses: actions/cache@v3 + with: + path: | + ~/AppData/Local/.xmake + .xmake + build/bds/lib + key: | + xmake-dataextractor-windows-x64-${{ github.sha }} + xmake-dataextractor-windows-x64-${{ github.sha }} + bdslib-${{ steps.read-bdsversion.outputs.version_type }}-${{ steps.read-bdsversion.outputs.version_number }} + restore-keys: | + xmake-dataextractor-windows-x64- + xmake-dataextractor-windows-x64- + + - run: | + xmake repo -u + + - run: | + xmake bds-lib -b --${{ steps.read-bdsversion.outputs.version_type }}=${{ steps.read-bdsversion.outputs.version_number }} + + - run: | + xmake f -a x64 -m release -p windows -v -y --ccache=n + + - run: | + xmake -w -y + + - uses: actions/upload-artifact@v3 + with: + name: DataExtractor-Windows-X64-${{ github.sha }} + path: | + build/windows/x64/release/DataExtractor.dll + build/windows/x64/release/DataExtractor.pdb \ No newline at end of file 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..417e10bb2 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,54 @@ 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 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) + if not os.exists(lib_path) then + os.mkdir(lib_path) + end + os.vexec("%s -l -o %s --pdb %s", tools_path, lib_path , path.join(unzip_path, "bedrock_server.pdb")) end end) @@ -103,6 +151,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