openai/codex-action

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
pr21

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/readServerInfo.ts

30lines · modeblame

e9d0a695Michael Bolin10 months ago1import * 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> {
9for (let attempt = 0; attempt < 100; attempt++) {
10try {
11const contents = await fs.readFile(serverInfoFile, { encoding: "utf8" });
12const { port } = JSON.parse(contents);
13if (typeof port !== "number") {
14continue;
15}
16
17core.setOutput("port", port.toString());
18return;
19} catch (error) {
20console.error(`Error reading server info: ${error}`);
21await sleep(100);
22}
23}
24
25throw Error(`Failed to read server info from ${serverInfoFile}`);
26}
27
28async function sleep(ms: number): Promise<void> {
29return new Promise((resolve) => setTimeout(resolve, ms));
30}