-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(build): restructure build helpers to use classes MONGOSH-2007 (
- Loading branch information
Showing
18 changed files
with
989 additions
and
1,183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,88 @@ | ||
import type { GithubRepo } from '@mongodb-js/devtools-github-repo'; | ||
import { generateUpdatedFormula } from './generate-formula'; | ||
import { updateHomebrewFork } from './update-homebrew-fork'; | ||
import { httpsSha256 } from './utils'; | ||
|
||
export async function publishToHomebrew( | ||
homebrewCore: GithubRepo, | ||
homebrewCoreFork: GithubRepo, | ||
packageVersion: string, | ||
githubReleaseLink: string, | ||
isDryRun: boolean, | ||
httpsSha256Fn = httpsSha256, | ||
generateFormulaFn = generateUpdatedFormula, | ||
updateHomebrewForkFn = updateHomebrewFork | ||
): Promise<void> { | ||
const cliReplPackageUrl = `https://registry.npmjs.org/@mongosh/cli-repl/-/cli-repl-${packageVersion}.tgz`; | ||
const packageSha = isDryRun | ||
? `dryRun-fakesha256-${Date.now()}` | ||
: await httpsSha256Fn(cliReplPackageUrl); | ||
|
||
const homebrewFormula = await generateFormulaFn( | ||
{ version: packageVersion, sha: packageSha }, | ||
homebrewCore, | ||
isDryRun | ||
); | ||
if (!homebrewFormula) { | ||
console.warn('There are no changes to the homebrew formula'); | ||
return; | ||
} | ||
import { generateUpdatedFormula as generateUpdatedFormulaFn } from './generate-formula'; | ||
import { updateHomebrewFork as updateHomebrewForkFn } from './update-homebrew-fork'; | ||
import { httpsSha256 as httpsSha256Fn } from './utils'; | ||
|
||
export type HomebrewPublisherConfig = { | ||
homebrewCore: GithubRepo; | ||
homebrewCoreFork: GithubRepo; | ||
packageVersion: string; | ||
githubReleaseLink: string; | ||
isDryRun?: boolean; | ||
}; | ||
|
||
const forkBranch = await updateHomebrewForkFn({ | ||
packageVersion, | ||
packageSha, | ||
homebrewFormula, | ||
homebrewCore, | ||
homebrewCoreFork, | ||
isDryRun, | ||
}); | ||
if (!forkBranch) { | ||
console.warn('There are no changes to the homebrew formula'); | ||
return; | ||
export class HomebrewPublisher { | ||
readonly httpsSha256: typeof httpsSha256Fn; | ||
readonly generateFormula: typeof generateUpdatedFormulaFn; | ||
readonly updateHomebrewFork: typeof updateHomebrewForkFn; | ||
|
||
constructor( | ||
public config: HomebrewPublisherConfig, | ||
{ | ||
httpsSha256 = httpsSha256Fn, | ||
generateFormula = generateUpdatedFormulaFn, | ||
updateHomebrewFork = updateHomebrewForkFn, | ||
} = {} | ||
) { | ||
this.httpsSha256 = httpsSha256; | ||
this.generateFormula = generateFormula; | ||
this.updateHomebrewFork = updateHomebrewFork; | ||
} | ||
|
||
const description = `This PR was created automatically and bumps \`mongosh\` to the latest published version \`${packageVersion}\`.\n\nFor additional details see ${githubReleaseLink}.`; | ||
async publish(): Promise<void> { | ||
const { | ||
isDryRun, | ||
homebrewCore, | ||
packageVersion, | ||
homebrewCoreFork, | ||
githubReleaseLink, | ||
} = this.config; | ||
|
||
const cliReplPackageUrl = `https://registry.npmjs.org/@mongosh/cli-repl/-/cli-repl-${packageVersion}.tgz`; | ||
const packageSha = isDryRun | ||
? `dryRun-fakesha256-${Date.now()}` | ||
: await this.httpsSha256(cliReplPackageUrl); | ||
|
||
const homebrewFormula = await this.generateFormula( | ||
{ version: packageVersion, sha: packageSha }, | ||
homebrewCore, | ||
isDryRun || false | ||
); | ||
if (!homebrewFormula) { | ||
console.warn('There are no changes to the homebrew formula'); | ||
return; | ||
} | ||
|
||
const forkBranch = await this.updateHomebrewFork({ | ||
packageVersion, | ||
packageSha, | ||
homebrewFormula, | ||
homebrewCore, | ||
homebrewCoreFork, | ||
isDryRun: isDryRun || false, | ||
}); | ||
if (!forkBranch) { | ||
console.warn('There are no changes to the homebrew formula'); | ||
return; | ||
} | ||
|
||
const description = `This PR was created automatically and bumps \`mongosh\` to the latest published version \`${packageVersion}\`.\n\nFor additional details see ${githubReleaseLink}.`; | ||
|
||
if (isDryRun) { | ||
await homebrewCoreFork.deleteBranch(forkBranch); | ||
console.warn('Deleted branch instead of creating homebrew PR'); | ||
return; | ||
if (isDryRun) { | ||
await homebrewCoreFork.deleteBranch(forkBranch); | ||
console.warn('Deleted branch instead of creating homebrew PR'); | ||
return; | ||
} | ||
const pr = await homebrewCore.createPullRequest( | ||
`mongosh ${packageVersion}`, | ||
description, | ||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions | ||
`${homebrewCoreFork.repo.owner}:${forkBranch}`, | ||
'master' | ||
); | ||
console.info( | ||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions | ||
`Created PR #${pr.prNumber} in ${homebrewCore.repo.owner}/${homebrewCore.repo.repo}: ${pr.url}` | ||
); | ||
} | ||
const pr = await homebrewCore.createPullRequest( | ||
`mongosh ${packageVersion}`, | ||
description, | ||
`${homebrewCoreFork.repo.owner}:${forkBranch}`, | ||
'master' | ||
); | ||
console.info( | ||
`Created PR #${pr.prNumber} in ${homebrewCore.repo.owner}/${homebrewCore.repo.repo}: ${pr.url}` | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.