embark/scripts/release
Pascal Precht ab41860d9b chore: introduce release script
This commit automates our release process. It takes care of a couple of things:

- Bumps version number in package.json as needed, see below
- Generates changelog based on commit history
- Create release commit
- Tags release commit
- Pushes release commit including tags to upstream repository
- Publishes release on npm

There are a couple of options supported. The base command is run like this:

```
npm run release
```

This will do a minor bump and try to push to `origin` on `master`. However,
this can be altered with the following options.

```
npm run release -- --dry-run
```

Can be used to perform dry run and not actually committing, tagging, pushing,
publishing anything.

```
npm run release -- --release-as <something>
```

Something can be `minor`, `major`, `patch` or anything you want `foo`, `1.0.0` etc.

```
npm run release -- --prerelease alpha
```

Will create a prerelease version a la `4.0.0-alpha.x`.

```
npm run release -- --prerelease alpha --npm-dist-tag next
```

Publishes a dist tag on npm using dist tag `next`

```
npm run release -- --sign
```

Signs the release commit (you need to have PGP setup for that).

```
npm run release -- --repo-origin pascal --repo-branch foo/bar
```

Pushes the release commit into `pascal/foo/bar`.
2018-11-21 13:28:50 +01:00

91 lines
3.2 KiB
JavaScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
const execSync = require('child_process').execSync;
const minimist = require('minimist');
const standardVersion = require('standard-version');
const chalk = require('chalk');
const args = minimist(process.argv.slice(2));
const DEFAULT_UPSTREAM_REPO_ORIGIN = 'origin';
const DEFAULT_UPSTREAM_REPO_BRANCH = 'master';
const origin = args['repo-origin'] || DEFAULT_UPSTREAM_REPO_ORIGIN;
const branch = args['repo-branch'] || DEFAULT_UPSTREAM_REPO_BRANCH;
const distTag = args['npm-dist-tag'];
console.log(chalk.blue(''), `Fetching from origin '${origin}' to read upstream version...`);
try {
console.log(execSync(`git fetch ${origin}`).toString());
} catch (e) {
console.log(chalk.red('✘'), 'Couldn\'t fetch latest commits. Please check the error above.');
return;
}
const localRef = execSync(`git rev-parse ${branch}`).toString();
const originRef = execSync(`git rev-parse ${origin}/${branch}`).toString();
if (localRef !== originRef) {
console.log(chalk.red('✘'), `Local branch '${branch}' is not up to date with '${origin}/${branch}'. Please update your local branch first.`);
return;
}
console.log(chalk.green('✔'), 'Release branch is up to date with remote branch.');
console.log(chalk.blue(''), 'Reinstalling node_modules just to make sure that everything is up to date...');
try {
console.log(execSync('npm run install_all').toString());
console.log(chalk.green('✔'), 'Depencencies installed.');
} catch (e) {
console.log(chalk.red('✘'), 'A problem occured. Please check the error above');
return;
}
standardVersion({
dryRun: args['dry-run'],
prerelease: args.prerelease,
sign: args.sign,
releaseAs: args['release-as']
}).then(() => {
if (!args['dry-run']) {
console.log(chalk.blue(''), `Pushing release commit to origin '${origin}' on branch '${branch}'...`);
try {
const output = execSync(`git push ${origin} ${branch} --follow-tags`).toString();
console.log(chalk.green(output));
console.log(chalk.green('✔'), 'Successfully pushed release commit');
} catch (e) {
console.log(chalk.red('✘'), 'Couldn\'t push release commit. Please check the error above.');
return { error: true };
}
} else {
console.log(chalk.blue(''), 'This is a dry run. Nothing\'s being pushed.');
}
}).then(error => {
if (error) {
return error;
}
console.log(chalk.blue(''), 'Publishing new Embark version on npm...');
let npmPublishCommand = distTag ? `npm publish --tag ${distTag}` : 'npm publish';
npmPublishCommand += args['dry-run'] ? ' --dry-run' : '';
try {
const output = execSync(npmPublishCommand).toString();
console.log(chalk.green(output));
if (args['dry-run']) {
console.log(chalk.blue(''), 'This was a dry run: Successfuly published latest version.');
} else {
console.log(chalk.green('✔'), 'Successfully published latest version.');
}
} catch (e) {
console.log(chalk.red('✘'), 'Couldn\'t publish version on npm. Please check the error above.');
return { error: true };
}
}).then(error => {
if (error) {
console.log(chalk.red('✘'), 'Stopping right here. Make sure to clean up commits and tags if needed.');
} else {
console.log(chalk.green('✔'), 'Woohoo! Done.');
}
});