|
6 | 6 | fetchPackage, |
7 | 7 | runWithLiveLogs, |
8 | 8 | } from "@pipelab/plugin-core"; |
9 | | -import { dirname, join, delimiter } from "node:path"; |
10 | | -import { writeFile, cp, mkdir } from "node:fs/promises"; |
| 9 | +import { dirname, join, delimiter, resolve, relative } from "node:path"; |
| 10 | +import { writeFile, cp, access } from "node:fs/promises"; |
11 | 11 |
|
12 | 12 | export const ID = "poki-upload"; |
13 | 13 | export const POKI_CLI_VERSION = "0.1.19"; |
@@ -53,55 +53,96 @@ export const uploadToPoki = createAction({ |
53 | 53 | export const uploadToPokiRunner = createActionRunner<typeof uploadToPoki>( |
54 | 54 | async ({ log, inputs, paths, abortSignal, cwd, context }) => { |
55 | 55 | const { node, thirdparty, pnpm, userData } = paths; |
| 56 | + |
| 57 | + const absoluteInputFolder = resolve(inputs["input-folder"] as string); |
| 58 | + |
| 59 | + log("Starting Poki upload action..."); |
| 60 | + log(`- Game ID: ${inputs.project}`); |
| 61 | + log(`- Version name: ${inputs.name}`); |
| 62 | + log(`- Version notes: ${inputs.notes}`); |
| 63 | + log(`- Input folder: ${absoluteInputFolder}`); |
| 64 | + |
| 65 | + log(`Fetching @poki/cli version ${POKI_CLI_VERSION}...`); |
56 | 66 | const { packageDir: pokiDir } = await fetchPackage("@poki/cli", POKI_CLI_VERSION, { |
57 | 67 | context, |
58 | 68 | installDeps: true, |
59 | 69 | }); |
60 | 70 | const poki = join(pokiDir, "bin", "index.js"); |
| 71 | + log(`Successfully resolved @poki/cli. Executable: ${poki}`); |
61 | 72 |
|
62 | | - const dist = join(cwd, "dist"); |
| 73 | + const tempUploadFolder = await context.createTempFolder("poki-upload-"); |
| 74 | + log(`Created temporary upload root directory: ${tempUploadFolder}`); |
63 | 75 |
|
64 | | - await mkdir(dist, { recursive: true }); |
65 | | - await cp(inputs["input-folder"] as string, dist, { |
| 76 | + const tempDistFolder = join(tempUploadFolder, "dist"); |
| 77 | + log(`Copying build files from "${absoluteInputFolder}" to "${tempDistFolder}"...`); |
| 78 | + await cp(absoluteInputFolder, tempDistFolder, { |
66 | 79 | recursive: true, |
67 | 80 | }); |
68 | 81 |
|
69 | | - const pokiJsonPath = join(cwd, "poki.json"); |
| 82 | + const pokiJsonPath = join(tempUploadFolder, "poki.json"); |
70 | 83 |
|
71 | | - console.log("pokiJsonPath", pokiJsonPath); |
| 84 | + log(`Writing temporary poki.json configuration at: ${pokiJsonPath}`); |
| 85 | + const pokiConfig = { |
| 86 | + game_id: inputs.project, |
| 87 | + build_dir: "dist", |
| 88 | + }; |
| 89 | + log(`poki.json configuration content:\n${JSON.stringify(pokiConfig, null, 2)}`); |
72 | 90 |
|
73 | 91 | // create file at the same place the folder to upload |
74 | 92 | await writeFile( |
75 | 93 | pokiJsonPath, |
76 | | - JSON.stringify( |
77 | | - { |
78 | | - game_id: inputs.project, |
79 | | - build_dir: "dist", |
80 | | - }, |
81 | | - undefined, |
82 | | - 2, |
83 | | - ), |
| 94 | + JSON.stringify(pokiConfig, undefined, 2), |
84 | 95 | "utf-8", |
85 | 96 | ); |
86 | 97 |
|
87 | | - log("process.env.MSW_BRIDGE_PORT", process.env.MSW_BRIDGE_PORT); |
88 | | - log("process.env.NODE_OPTIONS", process.env.NODE_OPTIONS); |
89 | | - |
90 | 98 | // Direct Poki CLI to read/write credentials inside Pipelab's thirdparty folder |
91 | 99 | const sandboxConfigDir = thirdparty; |
92 | 100 |
|
| 101 | + log("Checking for sandboxed authentication credentials..."); |
| 102 | + const possibleAuthPaths = [ |
| 103 | + join(sandboxConfigDir, "poki", "auth.json"), |
| 104 | + join(sandboxConfigDir, "Poki", "auth.json"), |
| 105 | + ]; |
| 106 | + let authFileFound = false; |
| 107 | + let foundPath = ""; |
| 108 | + for (const p of possibleAuthPaths) { |
| 109 | + try { |
| 110 | + await access(p); |
| 111 | + authFileFound = true; |
| 112 | + foundPath = p; |
| 113 | + break; |
| 114 | + } catch {} |
| 115 | + } |
| 116 | + |
| 117 | + if (authFileFound) { |
| 118 | + log(`[Poki] Authentication file found at: ${foundPath}`); |
| 119 | + } else { |
| 120 | + log("[Poki] [WARNING] No authentication file (auth.json) found in the sandboxed config directory."); |
| 121 | + log("[Poki] [WARNING] Poki CLI might try to open a browser for interactive login, which could hang/fail in headless environments."); |
| 122 | + log(`[Poki] Expected location: ${join(sandboxConfigDir, "poki", "auth.json")} or ${join(sandboxConfigDir, "Poki", "auth.json")}`); |
| 123 | + } |
| 124 | + |
| 125 | + log("Configuring environment variables:"); |
| 126 | + log(` - XDG_CONFIG_HOME: ${sandboxConfigDir}`); |
| 127 | + log(` - LOCALAPPDATA: ${sandboxConfigDir}`); |
| 128 | + log(` - PATH: ${dirname(node)}${delimiter}${process.env.PATH}`); |
| 129 | + log(` - MSW_BRIDGE_PORT: ${process.env.MSW_BRIDGE_PORT || "not set"}`); |
| 130 | + log(` - NODE_OPTIONS: ${process.env.NODE_OPTIONS || "not set"}`); |
| 131 | + |
93 | 132 | const env: Record<string, string> = { |
94 | 133 | ...process.env, |
95 | 134 | XDG_CONFIG_HOME: sandboxConfigDir, |
96 | 135 | LOCALAPPDATA: sandboxConfigDir, |
97 | 136 | PATH: `${dirname(node)}${delimiter}${process.env.PATH}`, |
98 | 137 | }; |
99 | 138 |
|
| 139 | + log(`Running Poki CLI upload command: node ${poki} upload --name "${inputs.name}" --notes "${inputs.notes}"`); |
| 140 | + |
100 | 141 | await runWithLiveLogs( |
101 | 142 | node, |
102 | 143 | [poki, "upload", "--name", inputs.name as string, "--notes", inputs.notes as string], |
103 | 144 | { |
104 | | - cwd, |
| 145 | + cwd: tempUploadFolder, |
105 | 146 | env, |
106 | 147 | cancelSignal: abortSignal, |
107 | 148 | }, |
|
0 commit comments