Skip to content
Permalink
Browse files

chore: make sure the changelog modifications are with the proper git …

…tag (#996)

Also:
* chore: refactor use of exec in version bump script
* chore: fix typo in version bump script
* chore: update release process docs
  • Loading branch information
malept committed Jul 12, 2019
1 parent aa8587b commit 5a5b526f8c424013c7aa0d5d2b0c2a12963eba8a
Showing with 36 additions and 34 deletions.
  1. +2 −3 CONTRIBUTING.md
  2. +34 −31 tools/bump.js
@@ -98,6 +98,5 @@ Here are some things to keep in mind as you file pull requests to fix bugs, add

- if you aren't sure if a release should happen, open an issue
- make sure the tests pass
- `npm run release:(patch|minor|major)`
- create a new GitHub release from the pushed tag with the contents of `CHANGELOG.md` for that version
- close the milestone associated with the version if one is open
- `node tools/bump.js $NEW_VERSION`
- `node tools/publish.js`
@@ -4,30 +4,48 @@ require('colors');
const childProcess = require('child_process');
const fs = require('fs-extra');
const path = require('path');
const { promisify } = require('util');
const semver = require('semver');

const BASE_DIR = path.resolve(__dirname, '..');
const PACKAGES_DIR = path.resolve(BASE_DIR, 'packages');
const ELECTRON_FORGE_PREFIX = '@electron-forge/';

(async () => {
// Check clean working dir
if (childProcess.execSync('git status -s', {
cwd: BASE_DIR,
}).toString() !== '') {
const exec = promisify(childProcess.exec);

async function run(command) {
return exec(command, { cwd: BASE_DIR });
}

async function checkCleanWorkingDir() {
if ((await run('git status -s')).toString() !== '') {
throw 'Your working directory is not clean, please ensure you have a clean working directory before version bumping'.red;
}
}

async function updateChangelog(lastVersion, version) {
await run(`node_modules/.bin/changelog --tag=v${lastVersion}..v${version}`);

require('../ci/fix-changelog'); // eslint-disable-line global-require

await run('git add CHANGELOG.md');
await run(`git commit -m "Update CHANGELOG.md for ${version}"`);
}

(async () => {
checkCleanWorkingDir();

const version = process.argv[2];
if (!version) {
throw 'Must provide a version in argv[1]'.red;
throw 'Must provide a version in argv[2]'.red;
}
if (!semver.valid(version)) {
throw `Must provide a valid semver version in argv[1]. Got ${version}`.red;
throw `Must provide a valid semver version in argv[2]. Got ${version}`.red;
}

console.info(`Setting version of all dependencies: ${version.cyan}`);

let lastVersion;
const { version: lastVersion } = await fs.readJson(path.join(BASE_DIR, 'package.json'));
const dirsToUpdate = [BASE_DIR];

for (const subDir of await fs.readdir(PACKAGES_DIR)) {
@@ -39,7 +57,6 @@ const ELECTRON_FORGE_PREFIX = '@electron-forge/';
for (const dir of dirsToUpdate) {
const pjPath = path.resolve(dir, 'package.json');
const existingPJ = await fs.readJson(pjPath);
lastVersion = existingPJ.version;
existingPJ.version = version;
for (const type of ['dependencies', 'devDependencies', 'optionalDependencies']) {
for (const depKey in existingPJ[type]) {
@@ -51,28 +68,14 @@ const ELECTRON_FORGE_PREFIX = '@electron-forge/';
await fs.writeJson(pjPath, existingPJ, {
spaces: 2,
});
childProcess.execSync(`git add "${path.relative(BASE_DIR, pjPath)}"`, {
cwd: BASE_DIR,
});
await run(`git add "${path.relative(BASE_DIR, pjPath)}"`);
}

childProcess.execSync(`git commit -m "Version Bump: ${version}"`, {
cwd: BASE_DIR,
});
childProcess.execSync(`git tag v${version}`, {
cwd: BASE_DIR,
});

childProcess.execSync(`node_modules/.bin/changelog --tag=v${lastVersion}`, {
cwd: BASE_DIR,
});

require('../ci/fix-changelog');

childProcess.execSync('git add CHANGELOG.md', {
cwd: BASE_DIR,
});
childProcess.execSync('git commit -m "Update CHANGELOG.md"', {
cwd: BASE_DIR,
});
await run(`git commit -m "Release ${version}"`);
await run(`git tag v${version}`);

await updateChangelog(lastVersion, version);

// re-tag to include the changelog
await run(`git tag --force v${version}`);
})().catch(console.error);

0 comments on commit 5a5b526

Please sign in to comment.
You can’t perform that action at this time.