Skip to content

Commit

Permalink
Enchancements to the build process - changelog generation (#332)
Browse files Browse the repository at this point in the history
* Release script now accepts a base branch rather than take master

* Added automatic changelog generator

* Added more release process commands

* Fixed version source
  • Loading branch information
Steve Hobbs authored Jan 15, 2020
1 parent f8172a7 commit 2b410d1
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ coverage
stats.html
cypress/screenshots
cypress/videos
.release
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"prepack": "npm run build && npm run test:es-check && npm run test && node ./scripts/prepack",
"precommit": "pretty-quick --staged",
"release": "node ./scripts/release",
"release:clean": "node ./scripts/cleanup",
"publish:cdn": "ccu --trace"
},
"devDependencies": {
Expand Down
61 changes: 61 additions & 0 deletions scripts/changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
if (process.platform === 'win32') {
console.error('Must be run on a Unix OS');
process.exit(1);
}

const repo = 'auth0-spa-js';
const fs = require('fs');
const path = require('path');
const execSync = require('child_process').execSync;
const moment = require('moment');

module.exports = function(newVersion) {
return new Promise((resolve, reject) => {
const tmp = fs.readFileSync('.release', 'utf-8');

const currentVersion = fs.readFileSync(
path.resolve(tmp, 'current-version'),
'utf-8'
);

const changelogPath = path.resolve(tmp, 'CHANGELOG.md');
const stream = fs.createWriteStream(changelogPath);
const webtask = `https://webtask.it.auth0.com/api/run/wt-hernan-auth0_com-0/oss-changelog.js?webtask_no_cache=1&repo=${repo}&milestone=v${newVersion}`;
const command = `curl -f -s -H "Accept: text/markdown" "${webtask}"`;
const changes = execSync(command, { encoding: 'utf-8' });

const previous = execSync(
'sed "s/# Change Log//" CHANGELOG.md | sed \'1,2d\''
);

stream.once('open', function(fd) {
stream.write('# Change Log');
stream.write('\n');
stream.write('\n');

stream.write(
`## [v${newVersion}](https://github.com/auth0/${repo}/tree/v${newVersion}) (${moment().format(
'YYYY-MM-DD'
)})`
);

stream.write('\n');

stream.write(
`[Full Changelog](https://github.com/auth0/${repo}/compare/v${currentVersion}...v${newVersion})`
);

stream.write('\n');
stream.write(changes);
stream.write('\n');
stream.write(previous);
stream.end();
});

stream.once('close', function(fd) {
execSync(`mv ${changelogPath} CHANGELOG.md`, { stdio: 'inherit' });
execSync('git add CHANGELOG.md', { stdio: 'inherit' });
resolve();
});
});
};
23 changes: 23 additions & 0 deletions scripts/cleanup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const execSync = require('child_process').execSync;
const fs = require('fs');

if (fs.existsSync('dist')) {
execSync(`rm -r dist`, { stdio: 'inherit' });
}

if (fs.existsSync('coverage')) {
execSync(`rm -r coverage`, { stdio: 'inherit' });
}

if (!fs.existsSync('.release')) {
console.log('No in progress release found');
process.exit(0);
}

const tmp = fs.readFileSync('.release');

if (fs.existsSync(tmp)) {
execSync(`rm -r ${tmp}`, { stdio: 'inherit' });
}

execSync(`rm -r .release`, { stdio: 'inherit' });
25 changes: 23 additions & 2 deletions scripts/release.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
const fs = require('fs');
const pkg = require('../package.json');
const exec = require('./exec');
const writeChangelog = require('./changelog');
const path = require('path');
const tmp = fs.mkdtempSync(`.release-tmp-`);

if (!fs.existsSync('.release')) {
fs.writeFileSync('.release', tmp);
} else {
console.error('Found a pending release. Please run `npm run release:clean`');
process.exit(1);
}

const newVersion = process.argv[2];
if (!newVersion) {
throw new Error('usage: `release new_version`');
throw new Error('usage: `release new_version [branch]`');
}

var lastVersionFile = path.resolve(tmp, 'current-version');
fs.writeFileSync(lastVersionFile, pkg.version);

const branch = process.argv[3];

(async () => {
await exec('git checkout master');
if (branch) {
await exec(`git checkout ${branch}`);
}

await exec('git pull');
await exec(`git checkout -b prepare/${newVersion}`);

Expand All @@ -23,7 +41,10 @@ if (!newVersion) {
'./package.json',
JSON.stringify({ ...pkg, version: newVersion }, null, 2)
);

fs.writeFileSync('./src/version.ts', `export default '${newVersion}';`);

await exec('npm run docs');

await writeChangelog(newVersion);
})();

0 comments on commit 2b410d1

Please sign in to comment.