Skip to content

Commit e080e30

Browse files
Merge branch 'master' into foreman
2 parents 1b6ea52 + 92e62ca commit e080e30

4 files changed

Lines changed: 70 additions & 22 deletions

File tree

scripts/test.luau

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ runProcess({
1717
process.env.TEST_UNIVERSE_ID,
1818
"--load.project",
1919
"tests/test.project.json",
20+
"--lua.globals",
21+
"HELLO_GLOBAL=hello,WORLD_GLOBAL=world!",
2022
"--binaryOutput",
2123
"build/testOutput.txt",
2224
"--verbose",

src/commands/run.luau

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,30 @@ USAGE:
77
rocale-cli run [options]
88
99
REQUIRED:
10-
-u, --universeId <id> Target universe ID to spawn an Open Cloud instance of
11-
-p, --placeId <id> Target place ID to spawn an Open Cloud instance of
12-
--apiKey <key> Roblox API key (or set ROBLOX_API_KEY env var)
10+
-u, --universeId <id> Target universe ID to spawn an Open Cloud instance of
11+
-p, --placeId <id> Target place ID to spawn an Open Cloud instance of
12+
--apiKey <key> Roblox API key (or set ROBLOX_API_KEY env var)
1313
1414
LOAD OPTIONS:
15-
--load.project <file> Rojo project.json/rbxp to build and load (requires rojo or robloxdev-cli)
16-
--load.place <file> Load an rbxl
17-
--load.version <num> Load existing place version without building/uploading
18-
(set to 0 to rerun last uploaded version)
15+
--load.project <file> Rojo project.json/rbxp to build and load (requires rojo or robloxdev-cli)
16+
--load.place <file> Load an rbxl
17+
--load.version <num> Load existing place version without building/uploading
18+
(set to 0 to rerun last uploaded version)
1919
2020
BUILD OPTIONS:
21-
--output <file> Output file path for the built place file
22-
(default: output.rbxl)
23-
--script <file> Luau script to load and set as entrypoint
21+
--output <file> Output file path for the built place file
22+
(default: output.rbxl)
23+
--script <file> Luau script to load and set as entrypoint
2424
2525
EXECUTION OPTIONS:
26-
--timeout <seconds> Timeout for polling task completion (default: 300)
27-
--pollInterval <seconds> Interval between polling attempts (default: 2)
28-
--binaryOutput <file> Path to save binary output from the task
26+
--lua.globals <key=value,...> Comma-separated list of Lua globals to inject
27+
--timeout <seconds> Timeout for polling task completion (default: 300)
28+
--pollInterval <seconds> Interval between polling attempts (default: 2)
29+
--binaryOutput <file> Path to save binary output from the task
2930
3031
FLAGS:
31-
-v, --verbose Enable verbose logging
32-
--help Show this help message
32+
-v, --verbose Enable verbose logging
33+
--help Show this help message
3334
]])
3435
end
3536

@@ -55,6 +56,7 @@ return function(...)
5556
args:add("load.version", "option")
5657
args:add("load.place", "option")
5758
args:add("apiKey", "option")
59+
args:add("lua.globals", "option", { default = nil })
5860
args:add("timeout", "option", { default = "300" })
5961
args:add("pollInterval", "option", { default = "2" })
6062
args:add("binaryOutput", "option", { default = nil })
@@ -76,6 +78,21 @@ return function(...)
7678
or args:get("apiKey")
7779
or log.fatal("Missing API Key: Set ROBLOX_API_KEY environment variable or provide it as an argument")
7880

81+
local luaGlobals = {}
82+
if args:get("lua.globals") then
83+
local globals = args:get("lua.globals")
84+
assert(globals, "Expected globals to be a comma-separated list of key=value pairs")
85+
86+
for _, pair in ipairs(string.split(globals, ",")) do
87+
local key, value = pair:match("([^=]+)=([^=]+)")
88+
if key and value then
89+
luaGlobals[key] = value
90+
else
91+
log.fatal("Expected format for globals is key=value")
92+
end
93+
end
94+
end
95+
7996
local placeInfo: ocaleSdk.PlaceInfo = {
8097
universeId = tonumber(args:get("universeId")) or log.fatal("Missing a universe ID"),
8198
placeId = tonumber(args:get("placeId")) or log.fatal("Missing a place ID"),
@@ -140,12 +157,22 @@ return function(...)
140157
end
141158
assert(entryScript)
142159

143-
local enableBinaryOutput = false
160+
local binaryOutputPath = nil
144161
if args:get("binaryOutput") then
145-
enableBinaryOutput = true
162+
binaryOutputPath = args:get("binaryOutput")
146163
end
164+
assert(binaryOutputPath, "Binary output path should be a valid file path")
165+
local enableBinaryOutput = binaryOutputPath ~= nil
147166

148-
local task = ocaleSdk.createTask(apiKey, placeInfo, entryScript, tonumber(args:get("timeout")), nil, enableBinaryOutput)
167+
local task = ocaleSdk.createTask(
168+
apiKey,
169+
placeInfo,
170+
entryScript,
171+
tonumber(args:get("timeout")),
172+
nil,
173+
enableBinaryOutput,
174+
luaGlobals
175+
)
149176
local completedTask = ocaleSdk.pollTaskCompletion(
150177
apiKey,
151178
task.path,
@@ -158,8 +185,8 @@ return function(...)
158185

159186
if enableBinaryOutput and completedTask.binaryOutputUri then
160187
local binaryOutput = ocaleSdk.getBinaryOutput(completedTask.binaryOutputUri)
161-
fs.writestringtofile(args:get("binaryOutput"), binaryOutput)
162-
log.info(`{richterm.green("✓", log.noColor())} Binary output saved to '{args:get("binaryOutput")}'`)
188+
fs.writestringtofile(binaryOutputPath, binaryOutput)
189+
log.info(`{richterm.green("✓", log.noColor())} Binary output saved to '{binaryOutputPath}'`)
163190
end
164191

165192
if completedTask.state == "FAILED" then

src/core/ocaleSdk.luau

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,43 @@ export type TaskResponse = {
8686
binaryInput: string?,
8787
binaryOutputUri: string?,
8888
}
89+
8990
function OcaleSDK.createTask(
9091
apiKey: string,
9192
placeInfo: PlaceInfo,
9293
scriptPath: string,
9394
timeout: number?,
9495
binaryInputPath: string?,
95-
enableBinaryOutput: boolean?
96+
enableBinaryOutput: boolean?,
97+
luaGlobals: { [string]: string }?
9698
): TaskResponse
9799
log.info(`{richterm.blue("→", log.noColor())} Creating the OCALE task...`)
98100
local url = getCreateTaskPath(placeInfo)
101+
local entryScript = fs.readfiletostring(scriptPath)
102+
103+
-- inject globals at the top of the entry script
104+
if luaGlobals then
105+
local keys: { string } = {}
106+
local values: { string } = {}
107+
for key, value in pairs(luaGlobals) do
108+
table.insert(keys, `_G[{string.format("%q", key)}]`)
109+
table.insert(values, string.format("%q", value))
110+
end
111+
local assignGlobals = table.concat(keys, ",") .. "=" .. table.concat(values, ",") .. " "
112+
entryScript = assignGlobals .. entryScript
113+
end
114+
99115
local req: net.Metadata = {
100116
method = "POST",
101117
headers = { ["x-api-key"] = apiKey, ["content-type"] = "application/json" },
102118
body = json.serialize({
103-
script = fs.readfiletostring(scriptPath),
119+
script = entryScript,
104120
binaryInput = binaryInputPath,
105121
enableBinaryOutput = enableBinaryOutput,
106122
timeout = `{timeout}s`,
107123
}),
108124
}
125+
109126
log.debug(`Request URL: {url}`)
110127
local response = net.request(url, req)
111128
log.fatalif(not response.ok, `{response.status} - {response.body}`)

tests/project/init.luau

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
assert(_G.HELLO_GLOBAL == "hello", "_G.HELLO_GLOBAL should be set to 'hello'")
2+
assert(_G.WORLD_GLOBAL == "world!", "_G.WORLD_GLOBAL should be set to 'world!'")
13
return true

0 commit comments

Comments
 (0)