diff --git a/README.md b/README.md index 9e15eefdb..bbf0ed830 100644 --- a/README.md +++ b/README.md @@ -127,9 +127,12 @@ $ gulp build 2. Run tests 3. Build everything 4. Bump the version in `package.json` -5. Commit the version change -6. Create a git tag -7. Run `git push` to `upstream/master` +5. Generate a changelog based on the git log +6. Commit the version change & `CHANGELOG.md` +7. Create a git tag +8. Run `git push` to `upstream/master` +9. Publish a release to Github releases (if `GH_TOKEN` is available) +10. Publish to npm ```bash # Major release @@ -151,6 +154,15 @@ $ aegir-release --env node $ gulp release --env node ``` +You can generate a changelog for all versions by using `--first` + +```bash +$ aegir-relase --first +``` + +You can skip all changelog generation and the github release by passing +in `--no-changelog`. + ## Other Notes There is a badge. diff --git a/package.json b/package.json index 2cc9fde7b..9aefe0052 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "babel-preset-es2015": "^6.9.0", "brfs": "^1.4.3", "chalk": "^1.1.3", + "conventional-github-releaser": "^1.1.3", "coveralls": "^2.11.12", "eslint": "^3.2.0", "eslint-config-standard": "^5.3.5", @@ -39,6 +40,7 @@ "gulp": "^3.9.1", "gulp-babel": "^6.1.2", "gulp-bump": "^2.2.0", + "gulp-conventional-changelog": "^1.1.0", "gulp-eslint": "^3.0.1", "gulp-filter": "^4.0.0", "gulp-git": "^1.10.0", diff --git a/src/utils.js b/src/utils.js index 0b7e0cc58..f72f88568 100644 --- a/src/utils.js +++ b/src/utils.js @@ -2,6 +2,7 @@ const runSequence = require('run-sequence') const $ = require('gulp-load-plugins')() +const fs = require('fs') // Workaround gulp not exiting if there are some // resources not freed @@ -34,3 +35,7 @@ exports.fail = (msg) => { $.util.log($.util.colors.red(msg)) process.exit(1) } + +exports.getVersion = () => { + return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version +} diff --git a/tasks/release/bump.js b/tasks/release/bump.js index b55b4031f..c57bbbe2c 100644 --- a/tasks/release/bump.js +++ b/tasks/release/bump.js @@ -2,9 +2,10 @@ const $ = require('gulp-load-plugins')() const semver = require('semver') -const fs = require('fs') const _ = require('lodash') +const getVersion = require('../../src/utils').getVersion + function getType () { if (_.includes($.util.env._, 'major')) return 'major' if (_.includes($.util.env._, 'minor')) return 'minor' @@ -13,21 +14,13 @@ function getType () { return 'patch' } -function getCurrentVersion () { - return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version -} - module.exports = (gulp, done) => { const type = getType() - const newVersion = semver.inc(getCurrentVersion(), type) + const newVersion = semver.inc(getVersion(), type) $.util.log('Releasing %s', newVersion) return gulp.src('./package.json') .pipe($.bump({version: newVersion})) .pipe(gulp.dest('./')) - .pipe($.git.add()) - .pipe($.git.commit(`chore: release version v${newVersion}`, {args: '-n'})) - .pipe($.filter('package.json')) - .pipe($.tagVersion()) } diff --git a/tasks/release/changelog.js b/tasks/release/changelog.js new file mode 100644 index 000000000..4a12e4646 --- /dev/null +++ b/tasks/release/changelog.js @@ -0,0 +1,19 @@ +'use strict' + +const $ = require('gulp-load-plugins')() + +module.exports = (gulp, done) => { + if ($.util.env.changelog === false) { + $.util.log('Skipping changelog generation') + return done() + } + + const releaseCount = $.util.env.first ? 0 : 1 + + return gulp.src('CHANGELOG.md') + .pipe($.conventionalChangelog({ + preset: 'angular', + releaseCount + })) + .pipe(gulp.dest('./')) +} diff --git a/tasks/release/commit.js b/tasks/release/commit.js new file mode 100644 index 000000000..ea174a603 --- /dev/null +++ b/tasks/release/commit.js @@ -0,0 +1,15 @@ +'use strict' + +const $ = require('gulp-load-plugins')() + +const getVersion = require('../../src/utils').getVersion + +module.exports = (gulp, done) => { + const newVersion = getVersion() + + return gulp.src(['package.json', 'CHANGELOG.md']) + .pipe($.git.add()) + .pipe($.git.commit(`chore: release version v${newVersion}`, {args: '-n'})) + .pipe($.filter('package.json')) + .pipe($.tagVersion()) +} diff --git a/tasks/release/github.js b/tasks/release/github.js new file mode 100644 index 000000000..c555df5e0 --- /dev/null +++ b/tasks/release/github.js @@ -0,0 +1,28 @@ +'use strict' + +const $ = require('gulp-load-plugins')() +const conventionalGithubReleaser = require('conventional-github-releaser') + +module.exports = (gulp, done) => { + if ($.util.env.changelog === false) { + $.util.log('Skipping github release') + return done() + } + + const token = process.env.GH_TOKEN || $.util.env.token + + if (!token) { + $.util.log($.util.colors.yellow(` +Skipping Github release as you are missing an oauth token. +You can supply one by either using $GH_TOKEN or --token. + `)) + return done() + } + + conventionalGithubReleaser({ + type: 'oauth', + token + }, { + preset: 'angular' + }, done) +} diff --git a/tasks/release/post-build.js b/tasks/release/post-build.js index 816b48195..e41043beb 100644 --- a/tasks/release/post-build.js +++ b/tasks/release/post-build.js @@ -6,7 +6,10 @@ module.exports = (gulp, done) => { runSequence.use(gulp)( 'release:contributors', 'release:bump', + 'release:changelog', + 'release:commit', 'release:push', + 'release:github', 'release:publish', done )