Skip to content

Commit

Permalink
Merge pull request #39 from pivotal-cf/release-task
Browse files Browse the repository at this point in the history
Add gulp task for cutting a new release

[Finishes #79540384]
  • Loading branch information
gpleiss committed Oct 22, 2014
2 parents 7b99d42 + 01532ae commit babb217
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ node_modules/
/vendor/
.idea/
/dist/
/dist.zip

## Specific to RubyMotion:
.dat*
Expand Down
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
## Pivotal UI Changelog

### Latest Changes
<a name="0.1.0"></a>
## 0.1.0 (2014-10-20)

Upgraded to Bootstrap 3.2.0

Expand Down
25 changes: 21 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,29 @@ If you create a new component, re-run `gulp test` to load the component in CssCr
Each commit should be "green" (i.e. it should not break any existing functionality). In addition, attempt to make each commit a complete idea. A single commit should not contain unrelated changes.
We follow the [Conventional Changelog](https://github.com/ajoslin/conventional-changelog/blob/master/CONVENTIONS.md) commit message format. Your message should include information about whether it includes major, minor or patch level changes. You may be wondering what major, minor, and patch mean in the context of CSS. Please follow these guidelines:
Your message should include information about the patch level of the changes made. You may be wondering what major, minor, and patch mean in the context of CSS. Please follow these guidelines:
* **Major** - A breaking change which alters either *class names* or expected *HTML*.
* **Minor** - Either an *additional feature* (e.g. a new component), or an update which changes *Sass variables*
* **Patch** - A *non-breaking change, bug fix, or design update* that any team should be able to upgrade to without changing their html. An example of this is updating the background color of the danger button or fixing the alignment of the horizontal tabs (as long as no html changes are required).
* **Major** - A breaking change which alters either *class names* or expected *HTML*. These commits can be labeled either as `feat(): ` or `fix(): `, but must also contain a `BREAKING CHANGE:` followed by what kind of breaking change it is (e.g., class name, sass variable, html, style) in the body of the commit.
* **Minor** - Either an *additional feature* (e.g. a new component), or an update which changes *Sass variables*. These commits should be labeled as `feat(): `.
* **Patch** - A *non-breaking change, bug fix, or design update* that any team should be able to upgrade to without changing their html. An example of this is updating the background color of the danger button or fixing the alignment of the horizontal tabs (as long as no html changes are required). These commits should be labeled as `fix(): `.
For example, for a patch, your commit might look like this:
```
fix(table): headers are now capitalized by default
- sections 1 & 2
```
and example of a breaking change might look like this:
```
feat(color): "orange-color" class is now named "light-orange"
BREAKING CHANGE: class name
```
For additonal information regarding commit message format consult the [Conventional Changelog](https://github.com/ajoslin/conventional-changelog/blob/master/CONVENTIONS.md).
## Documenting components
We use [hologram for documentation and styleguide generation](https://github.com/trulia/hologram). The component docs are created from markdown comments in the SCSS.
Expand Down
26 changes: 26 additions & 0 deletions CORE_TEAM_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,29 @@ Cloudbees will deploy to <http://styleguide.cfapps.io>.
### If you need to deploy manually (you most likely do not)

$ cf push -f manifest.yml

## Creating a new release
1. Create a [github access token](https://help.github.com/articles/creating-an-access-token-for-command-line-use/).
(Be sure to copy it to your clipboard)

1. Set the `RELEASE_TOKEN` enviornment variable to your github access token.

1. Make sure you are on master, and that you have no local changes.

1. Run `gulp release`. This will:
- Automatically determine the type of release (patch, major, minor)
- Updates the version in `package.json`
- Updates `CHANGELOG.md` with auto-generated release notes
- Creates a tag for the new version
- Pushes version bump and new tag to github
- Creates `dist.zip` in the root directory
- Creates a draft github release with the auto-generated release notes
- Uploads the `variables.scss` file to the release

1. In github, upload `dist.zip` to the release.

1. Be sure to name the release an ice cream flavor.

1. When satisfied with the release notes, publish!

![](http://images2.fanpop.com/images/photos/3600000/Lucille-Animated-gif-arrested-development-3695222-275-155.gif)
161 changes: 153 additions & 8 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ var fs = require('fs');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var argv = require('yargs').argv;
var changelog = require('conventional-changelog');
var zip = require('gulp-zip');
var bump = require('gulp-bump');
var git = require('gulp-git');
require('shelljs/global');
var rest = require('restler');
var versionChanges;

gulp.task('default', [
'watch',
Expand All @@ -27,6 +34,50 @@ gulp.task('ci', [
'assets'
]);

gulp.task('release', [
'_pushVersion',
'_zip',
], function(done) {
rest.post('https://api.github.com/repos/pivotal-cf/pivotal-ui/releases', {
query: {
access_token: process.env.RELEASE_TOKEN,
},
data: JSON.stringify({
'tag_name': tagName(),
'name': tagName(),
'body': versionChanges,
'draft': true
})
}).on('complete', function(result, response) {
if (!/2../.test(response.statusCode)) {
handleError(result, {callback: done});
}
fs.readFile('src/pivotal-ui/components/variables.scss', {encoding: 'utf-8'}, function(err, sass) {
if (err) {
handleError(err);
done();
}
rest.post('https://uploads.github.com/repos/pivotal-cf/pivotal-ui/releases/' + result.id + '/assets', {
query: {
name: 'variables.scss',
access_token: process.env.RELEASE_TOKEN,
},
headers: {
'Content-Type': 'text/plain'
},
data: sass,
}).on('complete', function(result, response) {
if (!/2../.test(response.statusCode)) {
handleError(result);
return done();
}
console.log('Successfully created draft release ' + tagName());
done();
});
});
});
});

gulp.task('watch', ['assets', '_copyTestAssets'], function() {
gulp.watch(['src/**/*', 'hologram/**/*'], ['assets', '_copyTestAssets']);
});
Expand Down Expand Up @@ -157,9 +208,9 @@ gulp.task('_copyTestAssets', ['assets'], function() {
]).pipe(gulp.dest('./test/dist/'));
});

gulp.task('_createTestFileList', ['assets'], function(cb) {
gulp.task('_createTestFileList', ['assets'], function(done) {
fs.readdir('./test/components/', function(err, files) {
if (err) { handleError(err) }
if (err) { handleError(err, {callback: done}); }

var stream = gulp.src('./test/regressionRunner.ejs')
.pipe(ejs({
Expand All @@ -169,7 +220,7 @@ gulp.task('_createTestFileList', ['assets'], function(cb) {
}))
.pipe(gulp.dest('./test/'));

stream.on('finish', cb)
stream.on('finish', done)
});
});

Expand All @@ -178,13 +229,107 @@ gulp.task('_cssCritic', ['lint', '_copyTestAssets', '_createTestFileList'], func
.pipe(open("./test/regressionRunner.html",{app:"firefox"}));
});

function isFatal() {
return !!argv.fatal;
gulp.task('_changelog', ['_bumpPackage'], function(done) {
changelog({
version: version(),
file: 'tmp/foo',
}, function(err, log) {
if (err) { handleError(err, {callback: done}); }

versionChanges = log;
fs.readFile('CHANGELOG.md', function(err, oldLog) {
if (err) { handleError(err, {callback: done}); }

fs.writeFile('CHANGELOG.md', versionChanges + oldLog, function(err) {
if (err) { handleError(err, {callback: done}); }
done();
});
});
});
});

gulp.task('_zip', [
'assets',
], function(){
return gulp.src('dist/*')
.pipe(zip('dist.zip'))
.pipe(gulp.dest('./'));
});

gulp.task('_bumpPackage', [], function(done) {
determineReleaseType(function(err, releaseType) {
if (err) {
handleError(err, {isFatal: true});
}

var stream = gulp.src(['./package.json'])
.pipe(bump({type: releaseType}))
.pipe(gulp.dest('./'));

stream.on('finish', done);
});
});

gulp.task('_bumpVersion', ['_bumpPackage', '_changelog'], function(){
return gulp.src(['package.json','CHANGELOG.md'])
.pipe(git.commit('v' + version()));
});

gulp.task('_tagVersion', ['_bumpVersion'], function(done) {
git.tag(tagName(), tagName(), done);
});

gulp.task('_pushVersion', ['_tagVersion'], function() {
// These calls are synchronous in case there is a prompt for credentials
var res = exec('git push origin HEAD');
if (res.code !== 0) {
handleError('Unable to push version', {isFatal: true});
}

res = exec('git push origin ' + tagName());
if (res.code !== 0) {
handleError('Unable to push tag', {isFatal: true});
}
});

function determineReleaseType(callback) {
changelog({
version: version(),
file: 'tmp/foo'
}, function(err, log) {
if (err) {
callback(err, null);
} else if (/# breaking changes/i.test(log)) {
callback(null, 'major');
} else if (/# features/i.test(log)) {
callback(null, 'minor');
} else if (/# bug fixes/i.test(log)) {
callback(null, 'patch');
} else {
callback('No changes found', null);
}
});
}

function tagName() {
return 'v' + version();
}

function version() {
return packageJson().version;
}

function packageJson() {
return JSON.parse(fs.readFileSync("./package.json", "utf8"));
}

function handleError(err) {
console.error(err)
if (isFatal()) {
function handleError(err, opts) {
opts = opts || {};

console.error(err);
if (!!argv.fatal || opts.isFatal) {
process.exit(1);
} else if (opts.callback) {
opts.callback();
}
}
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,29 @@
"devDependencies": {
"browserify": "^5.12.0",
"browserify-shim": "^3.7.0",
"conventional-changelog": "^0.0.11",
"csscritic": "^0.4.0",
"del": "^0.1.3",
"grunt": "^0.4.5",
"grunt-semantic-release": "^0.2.1",
"gulp": "^3.8.8",
"gulp-bump": "^0.1.11",
"gulp-compass": "^1.3.1",
"gulp-connect": "^2.0.6",
"gulp-ejs": "^0.3.1",
"gulp-git": "^0.5.2",
"gulp-hologram": "^1.1.0",
"gulp-jshint": "^1.8.5",
"gulp-open": "^0.2.8",
"gulp-zip": "^2.0.2",
"jshint-stylish": "^1.0.0",
"restler": "^3.2.2",
"shelljs": "^0.3.0",
"vinyl-source-stream": "^1.0.0",
"yargs": "^1.3.2"
},
"description": "***",
"version": "0.0.3",
"version": "0.1.0",
"main": "Gruntfile.js",
"dependencies": {
"bootstrap-sass": "^3.2.0",
Expand Down

0 comments on commit babb217

Please sign in to comment.