openai/codex-action

Public

mirrored from https://github.com/openai/codex-actionAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
main

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/readServerInfo.ts

30lines · modecode

1import * as core from "@actions/core";
2import * as fs from "fs/promises";
3
4/**
5 * In theory, this is not called until `serverInfoFile` is non-empty, but we
6 * will poll in the rare case that it was a partial write.
7 */
8export async function readServerInfo(serverInfoFile: string): Promise<void> {
9 for (let attempt = 0; attempt < 100; attempt++) {
10 try {
11 const contents = await fs.readFile(serverInfoFile, { encoding: "utf8" });
12 const { port } = JSON.parse(contents);
13 if (typeof port !== "number") {
14 continue;
15 }
16
17 core.setOutput("port", port.toString());
18 return;
19 } catch (error) {
20 console.error(`Error reading server info: ${error}`);
21 await sleep(100);
22 }
23 }
24
25 throw Error(`Failed to read server info from ${serverInfoFile}`);
26}
27
28async function sleep(ms: number): Promise<void> {
29 return new Promise((resolve) => setTimeout(resolve, ms));
30}
31