Skip to content

Commit c6eacd4

Browse files
authored
chore(build): refactor tarball creation to packaging MONGOSH-630 (#709)
1 parent 2cea844 commit c6eacd4

40 files changed

+379
-298
lines changed

packages/build/src/compile/run-compile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { PackageInformation } from '../tarball';
1+
import type { PackageInformation } from '../packaging/package';
22
import { generateBundle } from './generate-bundle';
33
import { SignableCompiler } from './signable-compiler';
44

packages/build/src/compile/signable-compiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import path from 'path';
66
import childProcess from 'child_process';
77
import { once } from 'events';
88
import { Platform } from '../config';
9-
import type { PackageInformation } from '../tarball';
9+
import type { PackageInformation } from '../packaging/package';
1010
import { compileJSFileAsBinary } from 'boxednode';
1111

1212
async function preCompileHook(nodeSourceTree: string) {

packages/build/src/config/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { PackageInformation } from '../tarball';
1+
import type { PackageInformation } from '../packaging/package';
22
import { BuildVariant } from './build-variant';
33

44
/**

packages/build/src/download-mongodb.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable camelcase, complexity, @typescript-eslint/no-non-null-assertion, no-return-assign, no-empty */
2+
/* istanbul ignore file */
23
import fetch from 'node-fetch';
34
import semver from 'semver';
45
import { promisify } from 'util';

packages/build/src/package/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/build/src/package/download-mongocryptd.ts renamed to packages/build/src/packaging/download-mongocryptd.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* istanbul ignore file */
12
import path from 'path';
23
import { promises as fs, constants as fsConstants } from 'fs';
34
import { downloadMongoDb } from '../download-mongodb';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export * from './run-package';
2+
3+
export {
4+
getPackageFile,
5+
PackageFile,
6+
PackageInformation
7+
} from './package';
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { expect } from 'chai';
2+
import sinon from 'sinon';
3+
import { Config } from '../config';
4+
import { macOSSignAndNotarize } from './macos-sign';
5+
6+
describe('packaging macos-sign', () => {
7+
describe('macOSSignAndNotarize', () => {
8+
let config: Config;
9+
let signStub: sinon.SinonStub;
10+
let notarizeStub: sinon.SinonStub;
11+
let runCreatePackageStub: sinon.SinonStub;
12+
13+
before(() => {
14+
config = {
15+
appleCodesignIdentity: 'signingIdentity',
16+
appleCodesignEntitlementsFile: 'entitlementsFile',
17+
appleNotarizationBundleId: 'bundleId',
18+
appleNotarizationUsername: 'username',
19+
appleNotarizationApplicationPassword: 'password'
20+
} as Config;
21+
22+
signStub = sinon.stub().resolves();
23+
notarizeStub = sinon.stub().resolves();
24+
runCreatePackageStub = sinon.stub().resolves({
25+
path: 'package/path',
26+
contentType: 'pkg'
27+
});
28+
});
29+
30+
context('processes the package', () => {
31+
before(async() => {
32+
await macOSSignAndNotarize(
33+
[
34+
'executable1', 'executable2'
35+
],
36+
config,
37+
runCreatePackageStub,
38+
signStub,
39+
notarizeStub
40+
);
41+
});
42+
43+
it('signs all executables', () => {
44+
expect(signStub).to.have.been.calledTwice;
45+
expect(signStub).to.have.been.calledWith('executable1', config.appleCodesignIdentity, config.appleCodesignEntitlementsFile);
46+
expect(signStub).to.have.been.calledWith('executable2', config.appleCodesignIdentity, config.appleCodesignEntitlementsFile);
47+
});
48+
49+
it('creates the package', () => {
50+
expect(runCreatePackageStub).to.have.been.called;
51+
});
52+
53+
it('notarizes the package', () => {
54+
expect(notarizeStub).to.have.been.calledWith(
55+
config.appleNotarizationBundleId,
56+
'package/path',
57+
config.appleNotarizationUsername,
58+
config.appleNotarizationApplicationPassword
59+
);
60+
});
61+
});
62+
});
63+
});

packages/build/src/package/macos-sign.ts renamed to packages/build/src/packaging/macos-sign.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@ import { notarize as nodeNotarize } from 'electron-notarize';
22
import codesign from 'node-codesign';
33
import util from 'util';
44
import { Config } from '../config';
5-
import { TarballFile } from '../tarball';
5+
import { PackageFile } from './package';
66

77
export async function macOSSignAndNotarize(
88
executables: string[],
99
config: Config,
10-
runCreateTarball: () => Promise<TarballFile>
11-
): Promise<TarballFile> {
10+
runCreatePackage: () => Promise<PackageFile>,
11+
signFn: typeof sign = sign,
12+
notarizeFn: typeof notarize = notarize,
13+
): Promise<PackageFile> {
1214
for (const executable of executables) {
1315
console.info('mongosh: signing:', executable);
14-
await sign(executable, config.appleCodesignIdentity || '', config.appleCodesignEntitlementsFile || '');
16+
await signFn(executable, config.appleCodesignIdentity || '', config.appleCodesignEntitlementsFile || '');
1517
}
16-
const artifact = await runCreateTarball();
18+
const artifact = await runCreatePackage();
1719
console.info('mongosh: notarizing and creating tarball:', artifact.path);
18-
await notarize(
20+
await notarizeFn(
1921
config.appleNotarizationBundleId || '',
2022
artifact.path,
2123
config.appleNotarizationUsername || '',
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { expect } from 'chai';
2+
import sinon from 'sinon';
3+
import { withTempPackageEach } from '../../../test/helpers';
4+
import { ALL_BUILD_VARIANTS } from '../../config';
5+
import { createPackage } from './create-package';
6+
7+
describe('archive create-archive', () => {
8+
describe('can create an archive for all build variants', () => {
9+
const tmpPkg = withTempPackageEach();
10+
11+
let createPosixArchiveStub: sinon.SinonStub;
12+
let createRedhatArchiveStub: sinon.SinonStub;
13+
let createDebianArchiveStub: sinon.SinonStub;
14+
let createMSIArchiveStub:sinon.SinonStub;
15+
let createZipArchiveStub:sinon.SinonStub;
16+
17+
beforeEach(() => {
18+
createPosixArchiveStub = sinon.stub();
19+
createRedhatArchiveStub = sinon.stub();
20+
createDebianArchiveStub = sinon.stub();
21+
createMSIArchiveStub = sinon.stub();
22+
createZipArchiveStub = sinon.stub();
23+
});
24+
25+
ALL_BUILD_VARIANTS.forEach(variant => {
26+
it(`can create a tarball for ${variant}`, async() => {
27+
const result = await createPackage(
28+
tmpPkg.tarballDir,
29+
variant,
30+
tmpPkg.pkgConfig,
31+
createPosixArchiveStub,
32+
createRedhatArchiveStub,
33+
createDebianArchiveStub,
34+
createMSIArchiveStub,
35+
createZipArchiveStub
36+
);
37+
expect(result).to.not.be.undefined;
38+
});
39+
});
40+
41+
it('throws an error for an unknown variant', async() => {
42+
try {
43+
await createPackage(tmpPkg.tarballDir, 'nope' as any, tmpPkg.pkgConfig);
44+
} catch (e) {
45+
expect(e).to.not.be.undefined;
46+
return;
47+
}
48+
expect.fail('Expected error');
49+
});
50+
});
51+
});

0 commit comments

Comments
 (0)