Skip to content

Commit

Permalink
[DOP-4033]: Create base job for standard builds ie jobs with makefile…
Browse files Browse the repository at this point in the history
…s that don't override shared,mk
  • Loading branch information
branberry committed Sep 26, 2023
1 parent 7d4dca6 commit 43efb54
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
11 changes: 11 additions & 0 deletions src/commands/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ export async function readFileAndExec(command: string, filePath: string, args?:
return response;
}

export async function getPatchId(repoDir: string): Promise<string> {
const filePath = path.join(repoDir, 'myPatch.patch');

const { stdout: gitPatchId } = await readFileAndExec('git', filePath, ['patch-id']);

return gitPatchId.slice(0, 7);
}

export async function getCommitHash(): Promise<string> {
// git rev-parse --short HEAD
const response = await executeCliCommand('git', ['rev-parse', '--short', 'HEAD']);
Expand All @@ -76,3 +84,6 @@ export async function getCommitHash(): Promise<string> {

export const checkIfPatched = async (repoDir: string) => !(await existsAsync(path.join(repoDir, 'myPatch.patch')));
export const getRepoDir = (repoName: string) => path.join(__dirname, `repos/${repoName}`);

export const RSTSPEC_FLAG =
'--rstspec=https://raw.githubusercontent.com/mongodb/snooty-parser/latest/snooty/rstspec.toml';
36 changes: 36 additions & 0 deletions src/commands/src/shared/base-job.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { getRepoDir, checkIfPatched, getCommitHash, executeCliCommand, getPatchId, RSTSPEC_FLAG } from '../helpers';

export abstract class BaseJob {
repoName: string;

constructor(repoName: string) {
this.repoName = repoName;
}

async nextGenParse(repoName: string): Promise<void> {
const repoDir = getRepoDir(repoName);

const commandArgs = ['build', repoDir, '--output', `${repoDir}/bundle.zip`, RSTSPEC_FLAG];

const hasPatch = await checkIfPatched(repoDir);

if (hasPatch) {
const [patchId, commitHash] = await Promise.all([getPatchId(repoDir), getCommitHash()]);

commandArgs.push('--commit');
commandArgs.push(commitHash);

commandArgs.push('--patch');
commandArgs.push(patchId);
}

await executeCliCommand('snooty', commandArgs);
}
async nextGenHtml(repoName: string) {
getRepoDir(repoName);
}

async nextGenDeploy() {
throw new Error('Not implemented');
}
}
10 changes: 0 additions & 10 deletions src/commands/src/shared/next-gen-parse.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import path from 'path';

import { checkIfPatched, executeCliCommand, getCommitHash, getRepoDir, readFileAndExec } from '../helpers';

const RSTSPEC_FLAG = '--rstspec=https://raw.githubusercontent.com/mongodb/snooty-parser/latest/snooty/rstspec.toml';

async function getPatchId(repoDir: string): Promise<string> {
const filePath = path.join(repoDir, 'myPatch.patch');

const { stdout: gitPatchId } = await readFileAndExec('git', filePath, ['patch-id']);

return gitPatchId.slice(0, 7);
}

export async function nextGenParse(repoName: string): Promise<void> {
const repoDir = getRepoDir(repoName);

Expand Down

0 comments on commit 43efb54

Please sign in to comment.