Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
feat: support install bdslib and cache
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolLoong committed Dec 14, 2023
1 parent cec8ed1 commit a461901
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
20 changes: 18 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions bdsversion
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type=release
version=1.20.50.03
53 changes: 51 additions & 2 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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"}
}
}

0 comments on commit a461901

Please sign in to comment.