Compare commits

...

2 Commits

Author SHA1 Message Date
Google Admin 6d85b071a4 Refactor Github Action per b/485167538 (#19311)
Co-authored-by: Ben Knutson <benknutson@google.com>
2026-02-17 19:13:39 -05:00
Shreya a90a4dfe5a init 2025-09-01 18:03:19 -04:00
2 changed files with 90 additions and 11 deletions
@@ -71,8 +71,10 @@ jobs:
if: |-
github.event_name == 'workflow_dispatch' && !contains(steps.get_issue_data.outputs.labels, 'status/need-triage')
run: |
echo "Issue #${{ github.event.inputs.issue_number }} does not have the 'status/need-triage' label. Stopping workflow."
echo "Issue #${GITHUB_EVENT_INPUTS_ISSUE_NUMBER} does not have the 'status/need-triage' label. Stopping workflow."
exit 1
env:
GITHUB_EVENT_INPUTS_ISSUE_NUMBER: ${{ github.event.inputs.issue_number }}
- name: 'Checkout'
uses: 'actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8' # ratchet:actions/checkout@v5
+87 -10
View File
@@ -376,18 +376,95 @@ export class IdeClient {
(ConnectionConfig & { workspacePath?: string }) | undefined
> {
if (!this.ideProcessInfo) {
return {};
}
try {
const portFile = path.join(
os.tmpdir(),
`gemini-ide-server-${this.ideProcessInfo.pid}.json`,
);
const portFileContents = await fs.promises.readFile(portFile, 'utf8');
return JSON.parse(portFileContents);
} catch (_) {
return undefined;
}
const tmpdir = os.tmpdir();
let files: string[];
try {
files = await fs.promises.readdir(tmpdir);
} catch (_e) {
// Failed to read tmpdir, no config file.
return undefined;
}
const serverFiles = files.filter((f) => f.startsWith('gemini-ide-server-'));
if (serverFiles.length === 0) {
return undefined;
}
// Rule 1: if there is a single file that matches "gemini-ide-server-" &
// that file name == "gemini-ide-server-{this.ideProcessInfo.pid}.json",
// then return that file.
if (serverFiles.length === 1) {
const expectedFile = `gemini-ide-server-${this.ideProcessInfo.pid}.json`;
if (serverFiles[0] === expectedFile) {
try {
const portFile = path.join(tmpdir, serverFiles[0]);
const portFileContents = await fs.promises.readFile(portFile, 'utf8');
return JSON.parse(portFileContents);
} catch (_e) {
// Ignore read error, proceed to rule 2 logic which will re-read.
}
}
}
// Rule 2: find all files that match "gemini-ide-server-".
// remove any files where the ppid in the file does not match ideProcessInfo.
// also filter out any files where the workspacePath is either "" or !isWithinWorkspace.
// if multiple files remain, use the file where the port matches the env var port
const expectedFile = `gemini-ide-server-${this.ideProcessInfo.pid}.json`;
const otherServerFiles = serverFiles.filter(
(file) => file !== expectedFile,
);
const potentialConfigs = [];
for (const file of otherServerFiles) {
try {
const portFile = path.join(tmpdir, file);
const portFileContents = await fs.promises.readFile(portFile, 'utf8');
const config = JSON.parse(portFileContents);
potentialConfigs.push(config);
} catch (_e) {
// Ignore files that can't be read or parsed
}
}
let filteredConfigs = potentialConfigs.filter(
(config) => config.ppid === this.ideProcessInfo!.pid,
);
filteredConfigs = filteredConfigs.filter((config) => {
if (!config.workspacePath || config.workspacePath === '') {
return false;
}
const { isValid } = IdeClient.validateWorkspacePath(
config.workspacePath,
this.currentIdeDisplayName,
process.cwd(),
);
return isValid;
});
if (filteredConfigs.length === 0) {
return undefined;
}
if (filteredConfigs.length === 1) {
return filteredConfigs[0];
}
const portFromEnv = this.getPortFromEnv();
if (portFromEnv) {
const configFromEnv = filteredConfigs.find(
(config) => config.port === portFromEnv,
);
if (configFromEnv) {
return configFromEnv;
}
}
return undefined;
}
private createProxyAwareFetch() {