Skip to content

Commit

Permalink
chore(build) add to check and fix errors (#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcasimir authored Sep 29, 2020
1 parent 7139dbb commit c5c1fdc
Show file tree
Hide file tree
Showing 21 changed files with 72 additions and 82 deletions.
5 changes: 0 additions & 5 deletions packages/build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,6 @@ const artifact = await createTarball(
);
```

## Installation
```shell
npm install --save @mongosh/build
```

[evergreen-url]: https://evergreen.mongodb.com/waterfall/mongosh
[config-url]: https://github.com/mongodb-js/mongosh/blob/393b505c179b64fbb72e0481c63f1723a3c56f06/config/build.conf.js
[build-img]: ./build.png
2 changes: 1 addition & 1 deletion packages/build/examples/input.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log('Hello World!');
console.info('Hello World!');
4 changes: 3 additions & 1 deletion packages/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"compile-ts": "tsc -p tsconfig.json",
"prepublish": "npm run compile-ts",
"test": "mocha -r \"../../scripts/import-expansions.js\" --timeout 15000 --colors -r ts-node/register \"./src/**/*.spec.ts\"",
"test-ci": "mocha -r \"../../scripts/import-expansions.js\" --timeout 15000 -r ts-node/register \"./src/**/*.spec.ts\""
"test-ci": "mocha -r \"../../scripts/import-expansions.js\" --timeout 15000 -r ts-node/register \"./src/**/*.spec.ts\"",
"lint": "eslint \"**/*.{js,ts,tsx}\"",
"check": "npm run lint"
},
"license": "Apache-2.0",
"publishConfig": {
Expand Down
1 change: 0 additions & 1 deletion packages/build/src/analytics.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import path from 'path';
import { expect } from 'chai';
import { createAnalyticsConfig } from './analytics';

Expand Down
6 changes: 3 additions & 3 deletions packages/build/src/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import util from 'util'
import util from 'util';
import fs from 'fs';
import handlebars from 'handlebars';

/**
* The template.
*/
const TEMPLATE = `module.exports = { SEGMENT_API_KEY: "{{segmentKey}}" };`;
const TEMPLATE = 'module.exports = { SEGMENT_API_KEY: "{{segmentKey}}" };';

/**
* Create the analytics config.
Expand All @@ -27,7 +27,7 @@ const createAnalyticsConfig = (segmentKey: string): string => {
*/
const writeAnalyticsConfig = (file: string, segmentKey: string) => {
const template = createAnalyticsConfig(segmentKey);
console.log('mongosh: writing analytics template:', file);
console.info('mongosh: writing analytics template:', file);
// Cannot use fs/promises on Cygwin.
return util.promisify(fs.writeFile)(file, template);
};
Expand Down
12 changes: 6 additions & 6 deletions packages/build/src/barque.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ describe('Barque', () => {
it('creates tmp directory that exists', async() => {
const curatorDirPath = await barque.createCuratorDir();

let accessErr
let accessErr;
try {
await fs.access(curatorDirPath)
await fs.access(curatorDirPath);
} catch (e) {
accessErr = e
accessErr = e;
}
// eslint-disable-next-line
expect(accessErr).to.be.undefined
Expand All @@ -170,11 +170,11 @@ describe('Barque', () => {

await barque.extractLatestCurator(curatorDirPath);

let accessErr
let accessErr;
try {
await fs.access(curatorPath)
await fs.access(curatorPath);
} catch (e) {
accessErr = e
accessErr = e;
}
// eslint-disable-next-line
expect(accessErr).to.be.undefined
Expand Down
10 changes: 5 additions & 5 deletions packages/build/src/barque.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BuildVariant from './build-variant';
import child_process from 'child_process';
import childProcess from 'child_process';
import gunzip from 'gunzip-maybe';
import Platform from './platform';
import fetch from 'node-fetch';
Expand All @@ -12,13 +12,13 @@ import util from 'util';
import path from 'path';

const pipeline = util.promisify(stream.pipeline);
const execFile = util.promisify(child_process.execFile);
const execFile = util.promisify(childProcess.execFile);

const LATEST_CURATOR =
'https://s3.amazonaws.com/boxes.10gen.com/build/curator/curator-dist-ubuntu1604-latest.tar.gz';

// make sure everything written in /tmp is cleared if an uncaught exception occurs
tmp.setGracefulCleanup()
// make sure everything written in /tmp is cleared if an uncaught exception occurs
tmp.setGracefulCleanup();

/**
* Distro enum to be used when making a curator call.
Expand Down Expand Up @@ -180,7 +180,7 @@ export class Barque {
*
*/
async extractLatestCurator(dest: string): Promise<any> {
const response = await fetch(LATEST_CURATOR)
const response = await fetch(LATEST_CURATOR);
if (response.ok) {
return pipeline(
response.body,
Expand Down
14 changes: 7 additions & 7 deletions packages/build/src/build-and-upload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('buildAndRelease', () => {
});

[true, false].forEach((isPublicRelease) => {
it(`uploads the artifact to evergreen if is ${isPublicRelease ? 'a' : 'not a'} public release`, async () => {
it(`uploads the artifact to evergreen if is ${isPublicRelease ? 'a' : 'not a'} public release`, async() => {
githubRepo = createStubRepo({
shouldDoPublicRelease: sinon.stub().returns(Promise.resolve(isPublicRelease))
});
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('buildAndRelease', () => {
});
});

it('releases to github if a public release', async () => {
it('releases to github if a public release', async() => {
githubRepo = createStubRepo({
shouldDoPublicRelease: sinon.stub().resolves(true)
});
Expand All @@ -116,7 +116,7 @@ describe('buildAndRelease', () => {
);
});

it('does not release to github if not a public release', async () => {
it('does not release to github if not a public release', async() => {
githubRepo = createStubRepo({
shouldDoPublicRelease: sinon.stub().resolves(false)
});
Expand All @@ -137,7 +137,7 @@ describe('buildAndRelease', () => {
expect(uploadToDownloadCenter).to.not.have.been.called;
});

it('releases to barque if a public release', async () => {
it('releases to barque if a public release', async() => {
githubRepo = createStubRepo({
shouldDoPublicRelease: sinon.stub().returns(Promise.resolve(true))
});
Expand All @@ -158,7 +158,7 @@ describe('buildAndRelease', () => {
expect(barque.releaseToBarque).to.have.been.called;
});

it('does not releases to barque if not a public release', async () => {
it('does not releases to barque if not a public release', async() => {
githubRepo = createStubRepo({
shouldDoPublicRelease: sinon.stub().resolves(false)
});
Expand All @@ -179,7 +179,7 @@ describe('buildAndRelease', () => {
expect(barque.releaseToBarque).to.not.have.been.called;
});

it('releases to downloads centre if a public release', async () => {
it('releases to downloads centre if a public release', async() => {
githubRepo = createStubRepo({
shouldDoPublicRelease: sinon.stub().resolves(true),
releaseToGithub: sinon.stub().resolves(true)
Expand All @@ -201,7 +201,7 @@ describe('buildAndRelease', () => {
expect(githubRepo.releaseToGithub).to.have.been.calledWith(tarballFile, config);
});

it('does not release to downloads centre if not a public release', async () => {
it('does not release to downloads centre if not a public release', async() => {
githubRepo = createStubRepo({
shouldDoPublicRelease: sinon.stub().resolves(false),
releaseToGithub: sinon.stub().resolves(true)
Expand Down
12 changes: 6 additions & 6 deletions packages/build/src/build-and-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ export default async function buildAndUpload(
compileAndZipExecutable: (Config) => Promise<TarballFile>,
uploadToEvergreen: (artifact: string, awsKey: string, awsSecret: string, project: string, revision: string) => Promise<void>,
uploadToDownloadCenter: (artifact: string, awsKey: string, awsSecret: string) => Promise<void>): Promise<void> {
console.log(
console.info(
'mongosh: beginning release with config:',
redactConfig(config)
);

// Build the executable.
const tarballFile = await compileAndZipExecutable(config);
console.log('mongosh: created tarball:', tarballFile);
console.info('mongosh: created tarball:', tarballFile);

if (config.dryRun) return;

Expand All @@ -31,13 +31,13 @@ export default async function buildAndUpload(
config.project,
config.revision
);
console.log('mongosh: internal release completed.');
console.info('mongosh: internal release completed.');

const evergreenTarball = getArtifactUrl(config.project, config.revision, tarballFile.path);

// Only release to public from master and when tagged with the right version.
if (await githubRepo.shouldDoPublicRelease(config)) {
console.log('mongosh: start public release.');
console.info('mongosh: start public release.');

await uploadToDownloadCenter(
tarballFile.path,
Expand All @@ -46,11 +46,11 @@ export default async function buildAndUpload(
);

await barque.releaseToBarque(evergreenTarball);
console.log('mongosh: submitting to barque complete');
console.info('mongosh: submitting to barque complete');

await githubRepo.releaseToGithub(tarballFile, config);
}

console.log('mongosh: finished release process.');
console.info('mongosh: finished release process.');
}

3 changes: 1 addition & 2 deletions packages/build/src/compile-and-zip-executable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export default async function compileAndZipExecutable(config: Config): Promise<T
// step.
if (os.platform() === Platform.MacOs && !config.dryRun) {
return await macOSSignAndNotarize(executable, config, runCreateTarball);
} else {
return await runCreateTarball();
}
return await runCreateTarball();
}
2 changes: 1 addition & 1 deletion packages/build/src/compile-exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const compileExec = async(
await generateInput(input, execInput, analyticsConfig, segmentKey);

const executable = executablePath(outputDir, os.platform());
console.log('mongosh: creating binary:', executable);
console.info('mongosh: creating binary:', executable);

const { compileJSFileAsBinary } = require('boxednode');
await new SignableCompiler(execInput, executable, execNodeVersion)
Expand Down
4 changes: 2 additions & 2 deletions packages/build/src/download-center.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const CONFIG = `
const createDownloadCenterConfig = (version: string): string => {
const template = handlebars.compile(CONFIG);
const rendered = template({ version: version });
console.log('mongosh: created download center template:', rendered);
console.info('mongosh: created download center template:', rendered);
return rendered;
};

Expand All @@ -116,7 +116,7 @@ const uploadToDownloadCenter = (s3: S3, config: string): Promise<any> => {
Key: `${DIRECTORY}/${FILENAME}`,
Body: config
};
console.log('mongosh: uploading config to download center');
console.info('mongosh: uploading config to download center');
return upload(uploadParams, s3);
};

Expand Down
6 changes: 3 additions & 3 deletions packages/build/src/evergreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ const uploadArtifactToEvergreen = (artifact: string, awsKey: string, awsSecret:
Body: fs.createReadStream(artifact)
};

console.log(`mongosh: uploading ${artifact} to evergreen bucket:`, BUCKET, key);
console.log(`mongosh: artifact download url: https://s3.amazonaws.com/${BUCKET}/${key}`);
console.info(`mongosh: uploading ${artifact} to evergreen bucket:`, BUCKET, key);
console.info(`mongosh: artifact download url: https://s3.amazonaws.com/${BUCKET}/${key}`);
return upload(uploadParams, s3);
};

const getArtifactUrl = (project: string, revision: string, artifact: string): string => {
return `https://s3.amazonaws.com/${BUCKET}/${project}/${revision}/${path.basename(artifact)}`
return `https://s3.amazonaws.com/${BUCKET}/${project}/${revision}/${path.basename(artifact)}`;
};

export default uploadArtifactToEvergreen;
Expand Down
4 changes: 2 additions & 2 deletions packages/build/src/execute-once.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ export default function runOnlyOnOnePlatform(codeSectionLabel, config, cb: Funct
const platformForSingleRun = Platform.MacOs;

if (config.platform === platformForSingleRun) {
console.log(
console.info(
'mongosh: running', codeSectionLabel,
'since platform ===', platformForSingleRun
);

return cb();
}

console.log(
console.info(
'mongosh: skipping', codeSectionLabel,
'since platform !==', platformForSingleRun
);
Expand Down
2 changes: 1 addition & 1 deletion packages/build/src/generate-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const generateInput = async(input: string, execInput: string, analyticsConfig: s
// cli-repl's analytics-config file.
await writeAnalyticsConfig(analyticsConfig, segmentKey);

console.log('mongosh: creating bundle:', execInput);
console.info('mongosh: creating bundle:', execInput);

// Parcel is the saviour here since it was the only bundling
// tool that could figure out how to handle everything in a
Expand Down
8 changes: 3 additions & 5 deletions packages/build/src/macos-sign.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import fs from 'fs';
import util from 'util';
import codesign from 'node-codesign';
import { notarize as nodeNotarize } from 'electron-notarize';
import Config from './config';
import { createTarball, TarballFile } from './tarball';
import { TarballFile } from './tarball';

/**
* Notarizes the zipped mongosh. Will send the tarball to Apple and poll apple
Expand Down Expand Up @@ -41,10 +40,9 @@ const macOSSignAndNotarize = async(
executable: string,
config: Config,
runCreateTarball: () => Promise<TarballFile>): Promise<TarballFile> => {

console.log('mongosh: signing:', executable);
console.info('mongosh: signing:', executable);
await sign(executable, config.appleAppIdentity, config.entitlementsFile);
console.log('mongosh: notarizing and creating tarball:', executable);
console.info('mongosh: notarizing and creating tarball:', executable);
const artifact = await runCreateTarball();
await notarize(
config.bundleId,
Expand Down
4 changes: 2 additions & 2 deletions packages/build/src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default async function publish(
): Promise<void> {
if (config.dryRun) return;

console.log(
console.info(
'mongosh: beginning publish release with config:',
redactConfig(config)
);
Expand All @@ -24,7 +24,7 @@ export default async function publish(

await githubRepo.promoteRelease(config);

console.log('mongosh: finished release process.');
console.info('mongosh: finished release process.');
}


3 changes: 1 addition & 2 deletions packages/build/src/signable-compiler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Platform from './platform';
import os from 'os';
import { promises as fs } from 'fs';

/**
* A compiler that can produce an executable that is actually
Expand Down Expand Up @@ -29,7 +28,7 @@ class SignableCompiler {
await exec({
configureArgs:
os.platform() === Platform.Windows ? ['openssl-no-asm'] :
os.platform() === Platform.MacOs ? ['--openssl-no-asm'] : [],
os.platform() === Platform.MacOs ? ['--openssl-no-asm'] : [],
sourceFile: this.sourceFile,
targetFile: this.targetFile,
nodeVersionRange: this.nodeVersionRange,
Expand Down
Loading

0 comments on commit c5c1fdc

Please sign in to comment.