Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit 58cf714

Browse files
authored
Merge pull request #59 from skerschb/varsha804-DOCSP-7636
Varsha804 docsp 7636
2 parents 696afe8 + b9641c1 commit 58cf714

18 files changed

+430
-250
lines changed

worker/.eslintrc.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"env": {
3+
"commonjs": true,
4+
"es6": true,
5+
"node": true,
6+
"jest": true
7+
},
8+
"extends": "eslint:recommended",
9+
"globals": {
10+
"Atomics": "readonly",
11+
"SharedArrayBuffer": "readonly"
12+
},
13+
"parserOptions": {
14+
"ecmaVersion": 2018
15+
},
16+
"rules": {
17+
"quotes": [2, "single", { "allowTemplateLiterals": true}],
18+
"no-console": "off"
19+
}
20+
}

worker/jest.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
globalSetup: './tests/mongo/setup.js',
3-
globalTeardown: './tests/mongo/teardown.js',
4-
testEnvironment: './tests/mongo/mongo-environment.js',
2+
globalSetup: './tests/mongo/setup.js',
3+
globalTeardown: './tests/mongo/teardown.js',
4+
testEnvironment: './tests/mongo/mongo-environment.js'
55
};

worker/jobTypes/S3Publish.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ const fs = require('fs-extra');
22
const workerUtils = require('../utils/utils');
33

44
class S3PublishClass {
5-
65
constructor(GitHubJob) {
76
this.GitHubJob = GitHubJob;
7+
fs.pathExists();
88
}
99

1010
async pushToStage(logger) {
@@ -13,26 +13,35 @@ class S3PublishClass {
1313
const exec = workerUtils.getExecPromise();
1414
const command = this.GitHubJob.deployCommands.join(' && ');
1515
const { stdout, stderr } = await exec(command);
16+
console.log(stderr);
1617
let stdoutMod = '';
1718
// get only last part of message which includes # of files changes + s3 link
1819
if (stdout.indexOf('Summary') !== -1) {
1920
stdoutMod = stdout.substr(stdout.indexOf('Summary'));
20-
}
21+
}
2122
return new Promise(function(resolve, reject) {
2223
logger.save(`${'(stage)'.padEnd(15)}Finished pushing to staging`);
23-
logger.save(`${'(stage)'.padEnd(15)}Staging push details:\n\n${stdoutMod}`);
24+
logger.save(
25+
`${'(stage)'.padEnd(15)}Staging push details:\n\n${stdoutMod}`
26+
);
2427
resolve({
25-
'status': 'success',
26-
'stdout': stdoutMod,
28+
status: 'success',
29+
stdout: stdoutMod
2730
});
31+
reject({
32+
status: 'failre',
33+
stdout: stderr
34+
})
2835
});
2936
} catch (errResult) {
3037
if (
3138
errResult.hasOwnProperty('code') ||
3239
errResult.hasOwnProperty('signal') ||
3340
errResult.hasOwnProperty('killed')
3441
) {
35-
logger.save(`${'(stage)'.padEnd(15)}failed with code: ${errResult.code}`);
42+
logger.save(
43+
`${'(stage)'.padEnd(15)}failed with code: ${errResult.code}`
44+
);
3645
logger.save(`${'(stage)'.padEnd(15)}stdErr: ${errResult.stderr}`);
3746
throw errResult;
3847
}
@@ -41,10 +50,10 @@ class S3PublishClass {
4150

4251
async pushToProduction(logger) {
4352
// todo
53+
logger.save('')
4454
}
45-
4655
}
4756

4857
module.exports = {
4958
S3PublishClass: S3PublishClass
50-
};
59+
};

worker/jobTypes/fastlyJob.js

Lines changed: 0 additions & 55 deletions
This file was deleted.

worker/jobTypes/githubJob.js

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const simpleGit = require('simple-git/promise');
44
const request = require('request');
55

66
class GitHubJobClass {
7-
87
// pass in a job payload to setup class
98
constructor(currentJob) {
109
this.currentJob = currentJob;
@@ -39,6 +38,7 @@ class GitHubJobClass {
3938
returnObject['content'] = response;
4039
}
4140
resolve(returnObject);
41+
reject(error);
4242
});
4343
});
4444
}
@@ -56,6 +56,7 @@ class GitHubJobClass {
5656
return new Promise(function(resolve, reject) {
5757
logger.save(`${'(rm)'.padEnd(15)}Finished cleaning repo`);
5858
resolve(true);
59+
reject(false);
5960
});
6061
}
6162

@@ -65,11 +66,18 @@ class GitHubJobClass {
6566
logger.save(`${'(GIT)'.padEnd(15)}running fetch`);
6667
try {
6768
if (!currentJob.payload.branchName) {
68-
logger.save(`${'(CLONE)'.padEnd(15)}failed due to insufficient definition`);
69+
logger.save(
70+
`${'(CLONE)'.padEnd(15)}failed due to insufficient definition`
71+
);
6972
throw new Error('branch name not indicated');
7073
}
7174
const basePath = this.getBasePath();
72-
const repoPath = basePath + '/' + currentJob.payload.repoOwner + '/' + currentJob.payload.repoName;
75+
const repoPath =
76+
basePath +
77+
'/' +
78+
currentJob.payload.repoOwner +
79+
'/' +
80+
currentJob.payload.repoName;
7381
await simpleGit('repos')
7482
.silent(false)
7583
.clone(repoPath, `${this.getRepoDirName(currentJob)}`)
@@ -91,6 +99,7 @@ class GitHubJobClass {
9199
return new Promise(function(resolve, reject) {
92100
logger.save(`${'(GIT)'.padEnd(15)}Finished git clone`);
93101
resolve(true);
102+
reject(false);
94103
});
95104
}
96105

@@ -106,13 +115,10 @@ class GitHubJobClass {
106115

107116
try {
108117
const exec = workerUtils.getExecPromise();
109-
const basePath = this.getBasePath();
110-
const repoPath = basePath + '/' + currentJob.payload.repoOwner + '/' + currentJob.payload.repoName;
111-
112118
const pullRepoCommands = [
113119
`cd repos/${this.getRepoDirName(currentJob)}`,
114120
`git checkout ${currentJob.payload.branchName}`,
115-
`git pull origin ${currentJob.payload.branchName}`,
121+
`git pull origin ${currentJob.payload.branchName}`
116122
];
117123

118124
await exec(pullRepoCommands.join(' && '));
@@ -122,28 +128,37 @@ class GitHubJobClass {
122128
`. /venv/bin/activate`,
123129
`cd repos/${this.getRepoDirName(currentJob)}`,
124130
`rm -f makefile`,
125-
`make html`,
131+
`make html`
126132
];
127133

128134
const deployCommands = [
129135
`. /venv/bin/activate`,
130136
`cd repos/${this.getRepoDirName(currentJob)}`,
131-
`make stage`,
137+
`make stage`
132138
];
133139

134140
// the way we now build is to search for a specific function string in worker.sh
135141
// which then maps to a specific target that we run
136-
const workerContents = fs.readFileSync(`repos/${this.getRepoDirName(currentJob)}/worker.sh`, { encoding: 'utf8' });
142+
const workerContents = fs.readFileSync(
143+
`repos/${this.getRepoDirName(currentJob)}/worker.sh`,
144+
{ encoding: 'utf8' }
145+
);
137146
const workerLines = workerContents.split(/\r?\n/);
138147

139148
// overwrite repo makefile with the one our team maintains
140149
const makefileContents = await this.downloadMakefile();
141150
if (makefileContents && makefileContents.status === 'success') {
142-
await fs.writeFileSync(`repos/${this.getRepoDirName(currentJob)}/Makefile`, makefileContents.content, { encoding: 'utf8', flag: 'w' });
151+
await fs.writeFileSync(
152+
`repos/${this.getRepoDirName(currentJob)}/Makefile`,
153+
makefileContents.content,
154+
{ encoding: 'utf8', flag: 'w' }
155+
);
143156
} else {
144-
console.log('ERROR: makefile does not exist in /makefiles directory on meta branch.');
157+
console.log(
158+
'ERROR: makefile does not exist in /makefiles directory on meta branch.'
159+
);
145160
}
146-
161+
147162
// check if need to build next-gen instead
148163
for (let i = 0; i < workerLines.length; i++) {
149164
if (workerLines[i] === '"build-and-stage-next-gen"') {
@@ -162,11 +177,19 @@ class GitHubJobClass {
162177

163178
return new Promise(function(resolve, reject) {
164179
logger.save(`${'(BUILD)'.padEnd(15)}Finished Build`);
165-
logger.save(`${'(BUILD)'.padEnd(15)}worker.sh run details:\n\n${stdout}\n---\n${stderr}`);
180+
logger.save(
181+
`${'(BUILD)'.padEnd(
182+
15
183+
)}worker.sh run details:\n\n${stdout}\n---\n${stderr}`
184+
);
166185
resolve({
167-
'status': 'success',
168-
'stdout': stdout,
169-
'stderr': stderr,
186+
status: 'success',
187+
stdout: stdout,
188+
stderr: stderr
189+
});
190+
reject({
191+
status: 'success',
192+
stderr: stderr
170193
});
171194
});
172195
} catch (errResult) {
@@ -175,15 +198,16 @@ class GitHubJobClass {
175198
errResult.hasOwnProperty('signal') ||
176199
errResult.hasOwnProperty('killed')
177200
) {
178-
logger.save(`${'(BUILD)'.padEnd(15)}failed with code: ${errResult.code}`);
201+
logger.save(
202+
`${'(BUILD)'.padEnd(15)}failed with code: ${errResult.code}`
203+
);
179204
logger.save(`${'(BUILD)'.padEnd(15)}stdErr: ${errResult.stderr}`);
180205
throw errResult;
181206
}
182207
}
183208
}
184-
185209
}
186210

187211
module.exports = {
188212
GitHubJobClass: GitHubJobClass
189-
};
213+
};

worker/jobTypes/githubPushJob.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
const fs = require('fs-extra');
1+
//const fs = require('fs-extra');
22
const workerUtils = require('../utils/utils');
33
const GitHubJob = require('../jobTypes/githubJob').GitHubJobClass;
44
const S3Publish = require('../jobTypes/S3Publish').S3PublishClass;
5-
const simpleGit = require('simple-git/promise');
65
const validator = require('validator');
76

87
const buildTimeout = 60 * 450;
9-
const uploadToS3Timeout = 20;
108

119
const invalidJobDef = new Error('job not valid');
1210

11+
12+
1313
//anything that is passed to an exec must be validated or sanitized
1414
//we use the term sanitize here lightly -- in this instance this // ////validates
1515
function safeString(stringToCheck) {
@@ -60,6 +60,7 @@ async function startGithubBuild(job, logger) {
6060

6161
return new Promise(function(resolve, reject) {
6262
resolve(true);
63+
reject(false);
6364
});
6465
}
6566
}
@@ -76,6 +77,7 @@ async function pushToStage(publisher, logger) {
7677

7778
return new Promise(function(resolve, reject) {
7879
resolve(true);
80+
reject(false);
7981
});
8082
}
8183
}
@@ -89,13 +91,21 @@ async function runGithubPush(currentJob) {
8991
!currentJob.payload.repoName ||
9092
!currentJob.payload.branchName
9193
) {
92-
workerUtils.logInMongo(currentJob,`${'(BUILD)'.padEnd(15)}failed due to insufficient definition`);
94+
workerUtils.logInMongo(
95+
currentJob,
96+
`${'(BUILD)'.padEnd(15)}failed due to insufficient definition`
97+
);
9398
throw invalidJobDef;
9499
}
95100

96101
// master branch cannot run through staging build
97102
if (currentJob.payload.branchName === 'master') {
98-
workerUtils.logInMongo(currentJob, `${'(BUILD)'.padEnd(15)} failed, master branch not supported on staging builds`);
103+
workerUtils.logInMongo(
104+
currentJob,
105+
`${'(BUILD)'.padEnd(
106+
15
107+
)} failed, master branch not supported on staging builds`
108+
);
99109
throw new Error('master branches not supported');
100110
}
101111

@@ -107,7 +117,7 @@ async function runGithubPush(currentJob) {
107117
},
108118
sendSlackMsg: function(message) {
109119
workerUtils.populateCommunicationMessageInMongo(currentJob, message);
110-
},
120+
}
111121
};
112122
};
113123

@@ -144,5 +154,5 @@ async function runGithubPush(currentJob) {
144154

145155
module.exports = {
146156
runGithubPush,
147-
safeGithubPush,
148-
};
157+
safeGithubPush
158+
};

0 commit comments

Comments
 (0)