Skip to content

Commit

Permalink
fix(hadron-build, compass): restore Isolated and Readonly special beh…
Browse files Browse the repository at this point in the history
…avior in packaged application COMPASS-8129 (#6147)

* fix(hadron-build): make sure that target gets the distribution in CI consistently

* chore(ci): add missing HADRON_DISTRIBUTION env to coverage, multiple-connections, gen-vuln-check tasks

* chore(hadron-build): fix tests

* chore(hadron-build): account for distribution being passed to the Target constructor options

* fix(hadron-build): includes not has

* chore(hadron-build): update test
  • Loading branch information
gribnoysup authored Aug 21, 2024
1 parent 0616adf commit 9a9b2bb
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 121 deletions.
2 changes: 1 addition & 1 deletion .evergreen/compass_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if [[ "$OSTYPE" == "cygwin" ]]; then
fi

echo "Creating signed release build..."
npm run package-compass-nocompile $COMPASS_DISTRIBUTION
npm run package-compass-nocompile
npm run generate-first-party-deps-json

ls -la packages/compass/dist
Expand Down
11 changes: 7 additions & 4 deletions .evergreen/functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,13 @@ functions:
shell: bash
env:
<<: *compass-env
HADRON_DISTRIBUTION: ${compass_distribution}
script: |
set -e
# Load environment variables
eval $(.evergreen/print-compass-env.sh)
# Generates and expansion file with build target metadata in packages/compass/expansions.yml
npm run --workspace mongodb-compass build-info -- ${target_platform} ${target_arch} --format=yaml --flatten ${compass_distribution} --out expansions.raw.yml
npm run --workspace mongodb-compass build-info -- ${target_platform} ${target_arch} --format=yaml --flatten --out expansions.raw.yml
# the 'author' key conflicts with evergreen's own expansion
grep -v '^author:' < packages/compass/expansions.raw.yml > packages/compass/expansions.yml
- command: expansions.update
Expand Down Expand Up @@ -405,7 +406,7 @@ functions:
<<: *compass-env
DEBUG: ${debug}
npm_config_loglevel: ${npm_loglevel}
COMPASS_DISTRIBUTION: ${compass_distribution}
HADRON_DISTRIBUTION: ${compass_distribution}
script: |
set -e
Expand Down Expand Up @@ -443,7 +444,7 @@ functions:
<<: *compass-env
DEBUG: ${debug}
npm_config_loglevel: ${npm_loglevel}
COMPASS_DISTRIBUTION: ${compass_distribution}
HADRON_DISTRIBUTION: ${compass_distribution}
SIGNING_SERVER_HOSTNAME: ${SIGNING_SERVER_HOSTNAME}
SIGNING_SERVER_PRIVATE_KEY: ${SIGNING_SERVER_PRIVATE_KEY}
SIGNING_SERVER_PRIVATE_KEY_CYGPATH: ${SIGNING_SERVER_PRIVATE_KEY_CYGPATH}
Expand Down Expand Up @@ -586,6 +587,7 @@ functions:
E2E_TEST_GROUPS: ${e2e_test_groups}
E2E_TEST_GROUP: ${e2e_test_group}
ATLAS_LOCAL_VERSION: latest
HADRON_DISTRIBUTION: compass
script: |
set -e
# Load environment variables
Expand Down Expand Up @@ -614,6 +616,7 @@ functions:
MONGODB_RUNNER_VERSION: ${mongodb_version|}
E2E_TEST_GROUPS: ${e2e_test_groups}
E2E_TEST_GROUP: ${e2e_test_group}
HADRON_DISTRIBUTION: compass
script: |
set -e
# Load environment variables
Expand All @@ -623,7 +626,6 @@ functions:
npm run --unsafe-perm --workspace compass-e2e-tests test-ci -- -- --test-multiple-connections
test-packaged-app:
- command: shell.exec
# Fail the task if it's idle for 10 mins
Expand Down Expand Up @@ -946,6 +948,7 @@ functions:
DEBUG: ${debug}
SNYK_TOKEN: ${snyk_token}
JIRA_API_TOKEN: ${jira_api_token}
HADRON_DISTRIBUTION: compass
script: |
set -e
# Load environment variables
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ In addition to running lerna commands directly, there are a few convenient npm s
To build compass you can run `package-compass` script:

```sh
npm run package-compass
HADRON_DISTRIBUTION='compass' npm run package-compass
```

You can change the type of distribution you are building with `HADRON_DISTRIBUTION` environmental variable:
It is required to provide `HADRON_DISTRIBUTION` env variable explicitly. You can change the type of distribution you are building by setting a different `HADRON_DISTRIBUTION` value:

```sh
HADRON_DISTRIBUTION='compass-readonly' npm run package-compass
Expand Down
3 changes: 0 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"release": "npm run release --workspace mongodb-compass --",
"reformat": "lerna run reformat --stream --no-bail",
"package-compass": "npm run package-compass --workspace=mongodb-compass --",
"package-compass-debug": "npm run package-compass-debug --workspace=mongodb-compass --",
"package-compass-nocompile": "npm run package-compass-nocompile --workspace=mongodb-compass --",
"prestart": "npm run compile --workspace=@mongodb-js/webpack-config-compass",
"prestart-web": "npm run prestart",
Expand Down
5 changes: 2 additions & 3 deletions packages/compass/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
}
],
"distributions": {
"default": "compass",
"compass": {
"name": "mongodb-compass",
"productName": "MongoDB Compass",
Expand Down Expand Up @@ -143,7 +142,7 @@
"install": "node scripts/download-fonts.js && node scripts/download-csfle.js",
"electron-rebuild": "electron-rebuild --only kerberos,keytar,interruptor,os-dns-native,win-export-certificate-and-key,macos-export-certificate-and-key --prebuild-tag-prefix not-real-prefix-to-force-rebuild",
"prestart": "npm run electron-rebuild",
"start": "npm run webpack serve -- --mode development",
"start": "HADRON_DISTRIBUTION=${HADRON_DISTRIBUTION:-compass} npm run webpack serve -- --mode development",
"test-electron": "npm run test-main && npm run test-renderer",
"test-main": "xvfb-maybe electron-mocha --no-sandbox \"./src/main/**/*.spec.*\" \"./src/main/**/*.test.*\"",
"test-renderer": "xvfb-maybe electron-mocha --no-sandbox --config ./.mocharc.renderer.js \"./src/app/**/*.spec.*\"",
Expand All @@ -158,7 +157,7 @@
"package-compass-nocompile": "hadron-build release",
"prepackage-compass": "npm run compile",
"package-compass": "npm run package-compass-nocompile",
"package-compass-debug": "DEBUG='*' HADRON_SKIP_INSTALLER=true NO_ASAR=true npm run package-compass",
"package-compass-debug": "DEBUG='hadron*,compass*' HADRON_SKIP_INSTALLER=true NO_ASAR=true npm run package-compass",
"upload": "hadron-build upload",
"download": "hadron-build download",
"evergreen-expansions": "hadron-build info --format=yaml --flatten > expansions.yml",
Expand Down
1 change: 0 additions & 1 deletion packages/hadron-build/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const yargs = require('yargs')
.command(require('./commands/info'))
.command(require('./commands/upload'))
.command(require('./commands/download'))
.command(require('./commands/verify'))
.demand(1, 'Please specify a command.')
.strict()
.env()
Expand Down
3 changes: 0 additions & 3 deletions packages/hadron-build/commands/info.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
const _ = require('lodash');
const Target = require('../lib/target');
const verifyDistro = require('../lib/distro');
const Table = require('cli-table');
const yaml = require('js-yaml');
const inspect = require('util').inspect;
Expand Down Expand Up @@ -74,8 +73,6 @@ const toTable = (target) => {
};

exports.handler = (argv) => {
verifyDistro(argv);

let target = new Target(argv.dir, {
version: argv.version,
platform: argv.platform,
Expand Down
8 changes: 0 additions & 8 deletions packages/hadron-build/commands/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

const Target = require('../lib/target');
const verifyDistro = require('../lib/distro');
const cli = require('mongodb-js-cli')('hadron-build:release');
const util = require('util');
const format = util.format;
Expand All @@ -30,8 +29,6 @@ const run = require('./../lib/run');
const rebuild = require('@electron/rebuild').rebuild;
const { signArchive } = require('./../lib/signtool');

const verify = require('./verify');

exports.command = 'release';

exports.describe = ':shipit:';
Expand Down Expand Up @@ -514,8 +511,6 @@ exports.builder = {
}
};

_.assign(exports.builder, verify.builder);


/**
* @param {any} argv Parsed command arguments
Expand All @@ -525,8 +520,6 @@ _.assign(exports.builder, verify.builder);
exports.run = async (argv, done) => {
cli.argv = argv;

verifyDistro(argv);

const target = new Target(argv.dir);

cli.debug(`Building distribution: ${target.distribution}`);
Expand All @@ -551,7 +544,6 @@ exports.run = async (argv, done) => {
const noAsar = process.env.NO_ASAR === 'true' || argv.no_asar;

const tasks = _.flatten([
() => verify.tasks(argv),
task('copy npmrc from root', ({ dir }, done) => {
fs.cp(
path.resolve(dir, '..', '..', '.npmrc'),
Expand Down
53 changes: 0 additions & 53 deletions packages/hadron-build/commands/verify.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/hadron-build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ exports = function() {};
exports.release = require('./commands/release');
exports.upload = require('./commands/upload');
exports.download = require('./commands/download');
exports.verify = require('./commands/verify');

module.exports = exports;
13 changes: 0 additions & 13 deletions packages/hadron-build/lib/distro.js

This file was deleted.

17 changes: 16 additions & 1 deletion packages/hadron-build/lib/target.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,27 @@ class Target {
this.pkg = pkg;

const distributions = pkg.config.hadron.distributions;
const distribution = opts.distribution ?? process.env.HADRON_DISTRIBUTION;

if (!distribution) {
throw new Error(
'You need to explicitly set HADRON_DISTRIBUTION or pass `distribution` option to Target constructor before building Compass'
);
}

if (!supportedDistributions.includes(distribution)) {
throw new Error(
`Unknown distribution "${distribution}". Available distributions: ${supportedDistributions.join(
', '
)}`
);
}

_.defaults(opts, { version: process.env.HADRON_APP_VERSION }, pkg, {
platform: process.platform,
arch: process.arch,
sign: true,
distribution: process.env.HADRON_DISTRIBUTION || distributions.default
distribution,
});

this.distribution = opts.distribution;
Expand Down
3 changes: 3 additions & 0 deletions packages/hadron-build/test/fixtures/hadron-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
"productName": "MongoDB Compass Enterprise super long test name",
"plugins": [],
"styles": [ "index" ]
},
"foo-bar": {
"name": "foo-bar"
}
},
"endpoint": "https://hadron-app.herokuapp.com",
Expand Down
26 changes: 0 additions & 26 deletions packages/hadron-build/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ describe('hadron-build', () => {
expect(hadronBuild).to.be.a('function');
});

describe('::release', () => {
it('should include options from commands::verify', () => {
expect(commands.release.builder).to.have.property('nodejs_version');
expect(commands.release.builder).to.have.property('npm_version');
});
});

describe('::test', () => {
const DEFAULT_ARGS = {
_: [],
Expand Down Expand Up @@ -84,23 +77,4 @@ describe('hadron-build', () => {
it('should spawn electron-mocha');
});
});

describe('::verify', () => {
it('should have a `nodejs_version` option', () => {
expect(commands.verify.builder).to.have.property('nodejs_version');
});

it('should have a `npm_version` option', () => {
expect(commands.verify.builder).to.have.property('npm_version');
});

it('should use `engines.node` for the default `nodejs_version` option');

it('should use `engines.npm` for the default `npm_version` option');

describe('::handler', () => {
it('should check the environment\'s npm installation');
it('should check the environment\'s node.js installation');
});
});
});
4 changes: 2 additions & 2 deletions packages/hadron-build/test/target.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('target', () => {

it('allows to override distribution config with env vars', () => {
Object.assign(process.env, {
HADRON_DISTRIBUTION: 'my-custom-distribution',
HADRON_DISTRIBUTION: 'compass-isolated',
HADRON_PRODUCT: 'compass-compass',
HADRON_PRODUCT_NAME: 'MongoDB Compass My Awesome Edition',
HADRON_READONLY: 'true',
Expand All @@ -49,7 +49,7 @@ describe('target', () => {

const target = new Target(path.join(__dirname, 'fixtures', 'hadron-app'));

expect(target).to.have.property('distribution', 'my-custom-distribution');
expect(target).to.have.property('distribution', 'compass-isolated');
expect(target).to.have.property('name', 'compass-compass');
expect(target).to.have.property(
'productName',
Expand Down

0 comments on commit 9a9b2bb

Please sign in to comment.