Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ability to perform tarball dry-run #308

Merged
merged 2 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ Compile the standalone executable:
npm run compile-exec
```

Compile a specific package, e.g. the `.deb` for Debian:

```shell
npm run release -- --dry --build-variant=Debian
```

## Contributing
For issues, please create a ticket in our [JIRA Pr
ject](https://jira.mongodb.org/browse/MONGOSH).
Expand Down
3 changes: 2 additions & 1 deletion config/build.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@ module.exports = {
repo: {
owner: 'mongodb-js',
repo: 'mongosh'
}
},
dryRun: false
};
7 changes: 6 additions & 1 deletion packages/build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ const config = {
repo: {
owner: 'owner',
repo: 'repo',
}
},
dryRun: false
}

const runRelease = async() => {
Expand All @@ -82,6 +83,10 @@ const release = require('@mongosh/build');
const configObject = {};
await release(config);
```

If `config.dryRun` is set, this will only package a tarball and skip all later
steps.

#### await compileExec()
Create a compiled down binary. Binary is created for the provided platform (e.g.
windows will build `mongosh.exe`). Before we compile the binary, we bundle
Expand Down
2 changes: 2 additions & 0 deletions packages/build/src/build-and-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export default async function buildAndRelease(
const tarballFile = await compileAndZipExecutable(config);
console.log('mongosh: created tarball:', tarballFile);

if (config.dryRun) return;

// Always release internally to evergreen
await uploadToEvergreen(
tarballFile.path,
Expand Down
1 change: 1 addition & 0 deletions packages/build/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ export default interface Config {
owner: string;
repo: string;
};
dryRun?: boolean;
}
3 changes: 2 additions & 1 deletion packages/build/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import compileExec from './compile-exec';
import createDownloadCenterConfig from './download-center';
import release from './release';
import { createTarball } from './tarball';
import BuildVariant from './build-variant';

export default release;
export { compileExec, createDownloadCenterConfig, createTarball, release };
export { compileExec, createDownloadCenterConfig, createTarball, release, BuildVariant };
8 changes: 4 additions & 4 deletions scripts/compile-exec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const os = require('os');
const path = require('path');
const { compileExec } = require('@mongosh/build');
const { execSync } = require('child_process');
const config = require(path.join(__dirname, '..', 'config', 'build.conf.js'));

const run = async() => {
console.log(`node --version ${execSync('node --version')}`);
console.log(`node --version ${process.version}`);

await compileExec(
config.input,
Expand All @@ -15,7 +14,8 @@ const run = async() => {
config.analyticsConfig,
config.segmentKey
);
process.exit(0);
};

run();
run().then(
() => process.exit(0),
(err) => process.nextTick(() => { throw err; }));
21 changes: 17 additions & 4 deletions scripts/release.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
require('./import-expansions');

const path = require('path');
const { release } = require(path.join('..', 'packages', 'build'));
const { release, BuildVariant } = require(path.join('..', 'packages', 'build'));
const config = require(path.join(__dirname, '..', 'config', 'build.conf.js'));

/**
* Run the release process.
*/
const runRelease = async() => {
if (process.argv.includes('--dry')) {
config.dryRun = true;
}
const cliBuildVariant =
process.argv.map((arg) => arg.match(/^--build-variant=(.+)$/)).filter(Boolean)[0];
if (cliBuildVariant !== undefined) {
config.buildVariant = cliBuildVariant[1];
}

// Resolve 'Windows' to 'win32' etc.
if (BuildVariant[config.buildVariant])
config.buildVariant = BuildVariant[config.buildVariant];

await release(config);
};

runRelease().then(() => {
process.exit(0);
});
runRelease().then(
() => process.exit(0),
(err) => process.nextTick(() => { throw err; }));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious why process.nextTick is necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intention here is to turn unhandled Promise rejections (which print a warning but do not result in the process exiting with a non-zero exit code) into an uncaught exception (which does result in the process exiting with code 1) – that behavior has a long, long history of debate behind it, and Node.js core will most likely change it in the future (https://medium.com/@nodejs/node-js-promise-reject-use-case-survey-98e3328340c9 has some futher reading on the current state of things, if you’re curious)

If this was re-throwing the error directly, it would just create another rejected Promise, so this is using process.nextTick() to make this independent of the Promise chain and avoid that