diff --git a/.gitmodules b/.gitmodules index 46789ed1..52377d6d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -16,3 +16,6 @@ [submodule "plugin/Packages/Highlighter"] path = plugin/Packages/Highlighter url = https://github.com/boatbomber/highlighter.git +[submodule ".lune/opencloud-execute"] + path = .lune/opencloud-execute + url = https://github.com/Dekkonot/opencloud-luau-execute-lune.git diff --git a/.lune/.luaurc b/.lune/.luaurc new file mode 100644 index 00000000..e5fd924b --- /dev/null +++ b/.lune/.luaurc @@ -0,0 +1,5 @@ +{ + "aliases": { + "lune": "~/.lune/.typedefs/0.10.2/" + } +} diff --git a/.lune/opencloud-execute b/.lune/opencloud-execute new file mode 160000 index 00000000..8ae86dd3 --- /dev/null +++ b/.lune/opencloud-execute @@ -0,0 +1 @@ +Subproject commit 8ae86dd3ad35eb66b0a4edda7e8771a5986cd0c6 diff --git a/.lune/test-plugin.luau b/.lune/test-plugin.luau new file mode 100644 index 00000000..7b8a46f5 --- /dev/null +++ b/.lune/test-plugin.luau @@ -0,0 +1,103 @@ +local serde = require("@lune/serde") +local net = require("@lune/net") +local stdio = require("@lune/stdio") +local process = require("@lune/process") +local fs = require("@lune/fs") + +local luau_execute = require("./opencloud-execute") + +local TEST_SCRIPT = fs.readFile("plugin/run-tests.server.lua") + +local PATH_VERSION_MATCH = "assets/%d+/versions/(.+)" + +local UNIVERSE_ID = process.env["RBX_UNIVERSE_ID"] +local PLACE_ID = process.env["RBX_PLACE_ID"] +local API_KEY = process.env["RBX_API_KEY"] + +if not UNIVERSE_ID then + error("no universe ID specified. try providing one with the env var `RBX_UNIVERSE_ID`") +end +if not PLACE_ID then + error("no place ID specified. try providing one with the env var `RBX_PLACE_ID`") +end +if not API_KEY then + error("no API key specified. try providing one with the env var `RBX_API_KEY`") +end + +--stylua: ignore +local upload_result = process.exec("cargo", { + "run", "--", + "upload", "plugin/test-place.project.json", + "--api_key", API_KEY, + "--universe_id", UNIVERSE_ID, + "--asset_id", PLACE_ID +}, { + stdio = "none" +}) + +if not upload_result.ok then + print("Failed to upload plugin test place") + print("Not dumping stdout or stderr to avoid leaking secrets") + process.exit(1) +end + +-- This is /probably/ not necessary because Rojo generally does not have enough +-- activity that there will be multiple CI runs happening at once, but +-- it's better safe than sorry. +local version_response = net.request({ + method = "GET", + url = `https://apis.roblox.com/assets/v1/assets/{PLACE_ID}/versions`, + query = { + maxPageSize = 1, + }, + headers = { + ["User-Agent"] = `Rojo/PluginTesting 1.0.0; {_VERSION}`, + ["x-api-key"] = API_KEY, + }, +}) + +if not version_response.ok then + error( + `Failed to fetch version of Roblox place to run tests on because: {version_response.statusCode} - {version_response.statusMessage}\n{version_response.body}` + ) +end + +local place_version_raw = serde.decode("json", version_response.body).assetVersions[1].path +assert(typeof(place_version_raw) == "string", "the result from asset version endpoint was not as expected") + +local place_version = string.match(place_version_raw, PATH_VERSION_MATCH) + +local task = luau_execute.create_task_versioned(UNIVERSE_ID, PLACE_ID, place_version, TEST_SCRIPT) +print(`Running test script on {UNIVERSE_ID}/{PLACE_ID}@{place_version}`) +print(`Task ID: {luau_execute.task_id(task)}`) + +luau_execute.await_finish(task) +print("Output from task:\n") +local logs = luau_execute.get_structured_logs(task) +for _, log in logs do + if log.messageType == "OUTPUT" or log.messageType == "MESSAGE_TYPE_UNSPECIFIED" then + stdio.write(stdio.color("reset")) + elseif log.messageType == "INFO" then + stdio.write(stdio.color("cyan")) + elseif log.messageType == "WARNING" then + stdio.write(stdio.color("yellow")) + elseif log.messageType == "ERROR" then + stdio.write(stdio.color("red")) + end + stdio.write(log.message) + stdio.write(`{stdio.color("reset")}\n`) +end + +local status = luau_execute.check_status(task) +if status == "COMPLETE" then + process.exit(0) +else + print() + print("Task did not finish successfully") + local err = luau_execute.get_error(task) + if err then + print(`Error from task: {err.code}`) + print(err.message) + end + process.exit(1) +end diff --git a/rokit.toml b/rokit.toml index 6fbd8746..9903052e 100644 --- a/rokit.toml +++ b/rokit.toml @@ -3,3 +3,4 @@ rojo = "rojo-rbx/rojo@7.5.1" selene = "Kampfkarren/selene@0.29.0" stylua = "JohnnyMorganz/stylua@2.1.0" run-in-roblox = "rojo-rbx/run-in-roblox@0.3.0" +lune = "lune-org/lune@0.10.2"