Skip to content

Commit

Permalink
log which build
Browse files Browse the repository at this point in the history
  • Loading branch information
mmeigs committed Dec 11, 2023
1 parent 2adf502 commit 4c8d4c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 97 deletions.
95 changes: 6 additions & 89 deletions api/controllers/v1/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@ import { markBuildArtifactsForDeletion, validateJsonWebhook } from '../../handle
import { DocsetsRepository } from '../../../src/repositories/docsetsRepository';
import { ReposBranchesDocsetsDocument } from '../../../modules/persistence/src/services/metadata/repos_branches';
import { PushEvent } from '@octokit/webhooks-types';
import { MONOREPO_NAME } from '../../../src/monorepo/utils/monorepo-constants';
import { getMonorepoPaths } from '../../../src/monorepo';
import { getUpdatedFilePaths } from '../../../src/monorepo/utils/path-utils';
import { JobStatus } from '../../../src/entities/job';

async function prepGithubPushPayload(
githubEvent: any,

Check warning on line 12 in api/controllers/v1/github.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
repoBranchesRepository: RepoBranchesRepository,
prefix: string,
repoInfo: ReposBranchesDocsetsDocument,
directory?: string
repoInfo: ReposBranchesDocsetsDocument
) {
const branch_name = githubEvent.ref.split('/')[2];
const branch_info = await repoBranchesRepository.getRepoBranchAliases(
Expand Down Expand Up @@ -61,7 +56,6 @@ async function prepGithubPushPayload(
urlSlug: urlSlug,
prefix: prefix,
project: project,
directory: directory,
},
logs: [],
};
Expand Down Expand Up @@ -116,70 +110,14 @@ export const TriggerBuild = async (event: any = {}, context: any = {}): Promise<
}

const env = c.get<string>('env');

async function createAndInsertJob(path?: string) {
const repoInfo = await docsetsRepository.getRepo(body.repository.name, path);
const jobPrefix = repoInfo?.prefix ? repoInfo['prefix'][env] : '';
const job = await prepGithubPushPayload(body, repoBranchesRepository, jobPrefix, repoInfo, path);

const repoInfo = await docsetsRepository.getRepo(body.repository.name);
const jobPrefix = repoInfo?.prefix ? repoInfo['prefix'][env] : '';
// TODO: Make job be of type Job
const job = await prepGithubPushPayload(body, repoBranchesRepository, jobPrefix, repoInfo);
try {
consoleLogger.info(job.title, 'Creating Job');
const jobId = await jobRepository.insertJob(job, c.get('jobsQueueUrl'));
jobRepository.notify(jobId, c.get('jobUpdatesQueueUrl'), JobStatus.inQueue, 0);
consoleLogger.info(job.title, `Created Job ${jobId}`);
}

if (body.repository.name === MONOREPO_NAME) {
// TODO: MONOREPO feature flag needed here
consoleLogger.info(body.repository.full_name, `past feature flag and monorepo conditional`);
let monorepoPaths: string[] = [];
try {
if (body.head_commit && body.repository.owner.name) {
consoleLogger.info(
body.repository.full_name,
`commitSha: ${body.head_commit.id}\nrepoName: ${body.repository.name}\nownerName: ${
body.repository.owner.name
}\nUpdatedfilepaths: ${getUpdatedFilePaths(body.head_commit)}`
);
monorepoPaths = await getMonorepoPaths({
commitSha: body.head_commit.id,
repoName: body.repository.name,
ownerName: body.repository.owner.name,
updatedFilePaths: getUpdatedFilePaths(body.head_commit),
consoleLogger,
});
consoleLogger.info(body.repository.full_name, `Monorepo Paths with new changes: ${monorepoPaths}`);
}
} catch (error) {
console.warn('Warning, attempting to get repo paths caused an error', error);
}

/* Create and insert Job for each monorepo project that has changes */
for (const path of monorepoPaths) {
consoleLogger.info(body.repository.full_name, `Each path: ${path}`);
// TODO: Deal with nested monorepo projects
/* For now, we will ignore nested monorepo projects until necessary */
if (path.split('/').length > 1) continue;

try {
await createAndInsertJob(path);
} catch (err) {
return {
statusCode: 500,
headers: { 'Content-Type': 'text/plain' },
body: err,
};
}
}

return {
statusCode: 202,
headers: { 'Content-Type': 'text/plain' },
body: 'Jobs Queued',
};
}

try {
await createAndInsertJob();
} catch (err) {
return {
statusCode: 500,
Expand All @@ -192,27 +130,6 @@ export const TriggerBuild = async (event: any = {}, context: any = {}): Promise<
headers: { 'Content-Type': 'text/plain' },
body: 'Job Queued',
};

// const repoInfo = await docsetsRepository.getRepo(body.repository.name);
// const jobPrefix = repoInfo?.prefix ? repoInfo['prefix'][env] : '';
// // TODO: Make job be of type Job
// const job = await prepGithubPushPayload(body, repoBranchesRepository, jobPrefix, repoInfo);
// try {
// consoleLogger.info(job.title, 'Creating Job');
// const jobId = await jobRepository.insertJob(job, c.get('jobsQueueUrl'));
// consoleLogger.info(job.title, `Created Job ${jobId}`);
// } catch (err) {
// return {
// statusCode: 500,
// headers: { 'Content-Type': 'text/plain' },
// body: err,
// };
// }
// return {
// statusCode: 202,
// headers: { 'Content-Type': 'text/plain' },
// body: 'Job Queued',
// };
};

export const MarkBuildArtifactsForDeletion = markBuildArtifactsForDeletion;
11 changes: 3 additions & 8 deletions src/job/jobHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,22 +717,17 @@ export abstract class JobHandler {
this._currJob._id,
`* Starting Job with ID: ${this._currJob._id} and type: ${this._currJob.payload.jobType}`
);
await this._logger.save(this._currJob._id, `* Starting Job with repo name: ${this._currJob.payload.repoName}`);
try {
// this.cleanup();
// await this.cloneRepo(this._config.get<string>('repo_dir'));
// this._logger.save(this._currJob._id, 'Cloned Repo');
// await this.commitCheck();
// this._logger.save(this._currJob._id, 'Checked Commit');
// await this.pullRepo();
// this._logger.save(this._currJob._id, 'Pulled Repo');

// TODO: MONOREPO feature flag needed here
if (
// process.env.FEATURE_FLAG_MONOREPO_PATH === 'true' &&
this._currJob.payload.repoName === MONOREPO_NAME
) {
await this._logger.save(this._currJob._id, `* Using build without Makefiles`);
await this.build();
} else {
await this._logger.save(this._currJob._id, `* Using build with Makefiles`);
await this.buildWithMakefiles();
}

Expand Down

0 comments on commit 4c8d4c3

Please sign in to comment.