Skip to content

Commit

Permalink
fix(build): github api calls for homebrew release fail MONGOSH-1928 (#…
Browse files Browse the repository at this point in the history
…2387)

* fix(build): github api calls for homebrew release fail MONGOSH-1928

* docs: add a comment

* refactor: rename function and add console error
  • Loading branch information
alenakhineika authored Feb 27, 2025
1 parent 2377d4a commit c9507b7
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions packages/build/src/homebrew/generate-formula.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
import * as semver from 'semver';
import type { GithubRepo } from '@mongodb-js/devtools-github-repo';

/**
* When sending requests via Octokit, a situation can arise where the server closes the connection,
* but the client still believes it’s open and attempts to write to it,
* what leads to receiving an EPIPE error from the OS, indicating the connection has already been closed.
* In such cases, retrying the request can help establish a new, functional connection.
*/
async function getFormulaFromRepositoryWithRetry(
homebrewCore: GithubRepo,
remainingRetries = 3
) {
try {
return await homebrewCore.getFileContent('Formula/m/mongosh.rb', 'master');
} catch (error: any) {
if (error.message.includes('EPIPE') && remainingRetries > 0) {
console.error(error);
return await getFormulaFromRepositoryWithRetry(
homebrewCore,
remainingRetries - 1
);
} else {
throw error;
}
}
}

export async function generateUpdatedFormula(
context: { version: string; sha: string },
homebrewCore: GithubRepo,
isDryRun: boolean
): Promise<string | null> {
const currentFormula = await homebrewCore.getFileContent(
'Formula/m/mongosh.rb',
'master'
);
const currentFormula = await getFormulaFromRepositoryWithRetry(homebrewCore);

const urlMatch = /url "([^"]+)"/g.exec(currentFormula.content);
const shaMatch = /sha256 "([^"]+)"/g.exec(currentFormula.content);
Expand Down

0 comments on commit c9507b7

Please sign in to comment.