Skip to content

Commit

Permalink
Merge pull request #16 from achambers/construct-revision-data
Browse files Browse the repository at this point in the history
Return revision metadata instead of just revisionKey
  • Loading branch information
lukemelia committed Sep 13, 2015
2 parents 4cd269e + f53a982 commit 67ab245
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 116 deletions.
20 changes: 10 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ Thank you to all who took the time to contribute!

#### Community Contributions

- [#1](https://github.com/zapnito/ember-cli-deploy-revision-key/pull/1) Create a tag form the hash of the index.html [@achambers](https://github.com/achambers)
- [#3](https://github.com/zapnito/ember-cli-deploy-revision-key/pull/3) Updated to be in line with how ember-cli-deploy handles context data [@achambers](https://github.com/achambers)
- [#4](https://github.com/zapnito/ember-cli-deploy-revision-key/pull/4) Remove dependency on index path [@achambers](https://github.com/achambers)
- [#5](https://github.com/zapnito/ember-cli-deploy-revision-key/pull/5) Now filePattern is relative to the dist dir stored in `context.distDir` [@achambers](https://github.com/achambers)
- [#6](https://github.com/zapnito/ember-cli-deploy-revision-key/pull/6) Rename index-hash to file-hash [@lukemelia](https://github.com/lukemelia)
- [#7](https://github.com/zapnito/ember-cli-deploy-revision-key/pull/7) Change to use `configure` hook instead of `willDeploy` [@achambers](https://github.com/achambers)
- [#8](https://github.com/zapnito/ember-cli-deploy-revision-key/pull/8) Renamed project and all references to `tags` [@achambers](https://github.com/achambers)
- [#9](https://github.com/zapnito/ember-cli-deploy-revision-key/pull/9) `configure` primes the config with data from the deployment context [@achambers](https://github.com/achambers)
- [#10](https://github.com/zapnito/ember-cli-deploy-revision-key/pull/10) Restructure to use ember-cli-deploy-plugin, and complete rename to em… [@lukemelia](https://github.com/lukemelia)
- [#12](https://github.com/zapnito/ember-cli-deploy-revision-key/pull/12) Update README for v0.5.0 [@achambers](https://github.com/achambers)
- [#1](https://github.com/zapnito/ember-cli-deploy-revision-data/pull/1) Create a tag form the hash of the index.html [@achambers](https://github.com/achambers)
- [#3](https://github.com/zapnito/ember-cli-deploy-revision-data/pull/3) Updated to be in line with how ember-cli-deploy handles context data [@achambers](https://github.com/achambers)
- [#4](https://github.com/zapnito/ember-cli-deploy-revision-data/pull/4) Remove dependency on index path [@achambers](https://github.com/achambers)
- [#5](https://github.com/zapnito/ember-cli-deploy-revision-data/pull/5) Now filePattern is relative to the dist dir stored in `context.distDir` [@achambers](https://github.com/achambers)
- [#6](https://github.com/zapnito/ember-cli-deploy-revision-data/pull/6) Rename index-hash to file-hash [@lukemelia](https://github.com/lukemelia)
- [#7](https://github.com/zapnito/ember-cli-deploy-revision-data/pull/7) Change to use `configure` hook instead of `willDeploy` [@achambers](https://github.com/achambers)
- [#8](https://github.com/zapnito/ember-cli-deploy-revision-data/pull/8) Renamed project and all references to `tags` [@achambers](https://github.com/achambers)
- [#9](https://github.com/zapnito/ember-cli-deploy-revision-data/pull/9) `configure` primes the config with data from the deployment context [@achambers](https://github.com/achambers)
- [#10](https://github.com/zapnito/ember-cli-deploy-revision-data/pull/10) Restructure to use ember-cli-deploy-plugin, and complete rename to em… [@lukemelia](https://github.com/lukemelia)
- [#12](https://github.com/zapnito/ember-cli-deploy-revision-data/pull/12) Update README for v0.5.0 [@achambers](https://github.com/achambers)

Thank you to all who took the time to contribute!
59 changes: 46 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# ember-cli-deploy-revision-key
# ember-cli-deploy-revision-data

> An ember-cli-deploy plugin to generate a unique revision key based on the current build
> An ember-cli-deploy plugin to generate data about this deploy revision including a unique revision key based on the current build
<hr/>
**WARNING: This plugin is only compatible with ember-cli-deploy versions >= 0.5.0**
<hr/>

This plugin will generate a unique revision key for the current build. The revision key can be used to uniquely identify the particular version of the application.
This plugin will generate revison data for the current build. This data can be used by other plugins to understand more about the current revision being deployed.
The revision key included in the revison data can be used to uniquely identify the particular version of the application.

## What is an ember-cli-deploy plugin?

Expand All @@ -22,7 +23,7 @@ To get up and running quickly, do the following:
- Install this plugin

```bash
$ ember install ember-cli-deploy-revision-key
$ ember install ember-cli-deploy-revision-data
```

- Run the pipeline
Expand All @@ -35,34 +36,44 @@ $ ember deploy
Run the following command in your terminal:

```bash
ember install ember-cli-deploy-revision-key
ember install ember-cli-deploy-revision-data
```

## ember-cli-deploy Hooks Implemented

For detailed information on what plugin hooks are and how they work, please refer to the [Plugin Documentation][1].

- `configure`
- `didBuild`
- `prepare`

## Configuration Options

For detailed information on how configuration of plugins works, please refer to the [Plugin Documentation][1].

### type

The type of [Key Generator](#key-generators) to be used.
The type of [Data Generator](#data-generators) to be used.

*Default:* `'file-hash'`
*Alternatives:* `'git-tag-commit'`, `'version-commit'`

## Key Generators
## Data Generators

Key generators are the strategies used to generate the unique revision key. Currently there is only one Key Generator implementation but we will add more as needed. Some examples of other potential key generators are `GitHash` or `DateTime` generators.
Data generators are the strategies used to generate information about the revision being deployed. A data generator must return an object which contains a property called `revisionKey` which uniquely identifies the current revision. A generator can add any other data that it deems relevant to the data object that it returns.

### File Hash generator

This key generator will fingerprint the `index.html` and return an MD5 hash. The generation of the revision key, using this generator, is guaranteed to be idempotent. That is, the same revision key will be generated for the same set of project files. If the project files change in any way, this will be reflected by a change in the revision key.
This generator contructs a revisionKey from the fingerprint of the `index.html` file.

#### Data fields returned

##### revisionKey

The unique identifier of this build based on the MD5 fingerprint of the `index.html` file. This key is guaranteed to be idempotent. That is, the same revision key will be generated for the same set of project files. If the project files change in any way, this will be reflected by a change in the revision key.

##### timestamp

The timestamp of the current deploy

#### Configuration Options

Expand All @@ -86,19 +97,41 @@ The list of built project files. This option should be relative to `distDir` and

### Git Tag Commit generator

Creates a key based on the most recent git tag and the currently checked-out commit. The tag is the tag identifier, followed by a `+` symbol, followed by the first 8 characters of the commit hash.
Constructs a revision key based on the most recent git tag and the currently checked-out commit.

#### Data fields returned

##### revisionKey

The unique identifier of this build based on the git tag, followed by a `+` symbol, followed by the first 8 characters of the current commit hash.

For example, if your most recent git tag is `v2.0.3`, and the current commit is `0993043d49f9e0[...]`, this generator will return a revision of `v2.0.3+0993043d`.

##### timestamp

The timestamp of the current deploy

### Version Commit generator

Similar to the Git Tag Commit generator, but uses the `package.json` version string instead of the git tag. The JSON file containing the version string can be configured with the `versionFile` option.
Similar to the Git Tag Commit generator but uses the `package.json` version string to construct the revision key instead of the git tag.

#### Data fields returned

##### revisionKey

The unique identifier of this build based on the version in the `package.json`, followed by a `+` symbol, followed by the first 8 characters of the current commit hash.

For example, if your package.json version is `v2.0.3`, and the current commit is `0993043d49f9e0[...]`, this generator will return a revision of `v2.0.3+0993043d`.

##### timestamp

The timestamp of the current deploy

#### Configuration Options

##### versionFile

The file containing your project's version number. Must be a JSON file with a top-level `version` key. Only used by the `version-commit` key generator.
The file containing your project's version number. Must be a JSON file with a top-level `version` key.

*Default:* `package.json`

Expand Down
2 changes: 1 addition & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The following steps should navigate you through the release process to ensure as
8. `git push upstream master`
9. `git tag "vx.y.z"`
10. `git push upstream vx.y.z`
11. `npm publish ./ember-cli-deploy-revision-key-<version>.tgz`
11. `npm publish ./ember-cli-deploy-revision-data-<version>.tgz`

### Create a github release

Expand Down
2 changes: 1 addition & 1 deletion bin/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var compareCommits = Promise.denodeify(github.repos.compareCommits);
var currentVersion = 'v' + require('../package').version;

var user = 'zapnito';
var repo = 'ember-cli-deploy-revision-key';
var repo = 'ember-cli-deploy-revision-data';

compareCommits({
user: user,
Expand Down
2 changes: 1 addition & 1 deletion bin/prepare-release
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

rm -rf node_modules && \
rm -rf ./ember-cli-deploy-revision-key*.tgz && \
rm -rf ./ember-cli-deploy-revision-data*.tgz && \
npm cache clear && \
npm i --no-optional && \
npm link --no-optional && \
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "ember-cli-deploy-revision-key",
"name": "ember-cli-deploy-revision-data",
"dependencies": {
"ember": "1.11.1",
"ember-cli-shims": "ember-cli/ember-cli-shims#0.0.3",
Expand Down
22 changes: 11 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var Promise = require('ember-cli/lib/ext/promise');
var DeployPluginBase = require('ember-cli-deploy-plugin');

module.exports = {
name: 'ember-cli-deploy-revision-key',
name: 'ember-cli-deploy-revision-data',

createDeployPlugin: function(options) {
var DeployPlugin = DeployPluginBase.extend({
Expand All @@ -22,22 +22,22 @@ module.exports = {
},
versionFile: 'package.json',
},
didBuild: function(context) {
prepare: function(context) {
var self = this;
var type = this.readConfig('type');
var KeyGenerator = require('./lib/key-generators')[type];
var keyGenerator = new KeyGenerator({
var DataGenerator = require('./lib/data-generators')[type];
var dataGenerator = new DataGenerator({
plugin: this
});

this.log('creating revision key using `' + type + '`');
return keyGenerator.generate()
.then(function(revisionKey) {
self.log('generated revision key: `' + revisionKey + '`');
return revisionKey;
this.log('creating revision data using `' + type + '`');
return dataGenerator.generate()
.then(function(data) {
self.log('generated revision data for revision: `' + data.revisionKey + '`');
return data;
})
.then(function(revisionKey) {
return { revisionKey: revisionKey };
.then(function(data) {
return { revisionData: data };
})
.catch(this._errorMessage.bind(this));
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,11 @@ module.exports = CoreObject.extend({

return readFile(filePath)
.then(function(contents) {
return md5Hash(contents.toString());
return {
revisionKey: md5Hash(contents.toString()),
timestamp: new Date().toISOString()
};
})
},

_resolveConfigValue: function(key, config, context) {
if(typeof config[key] === 'function') {
return config[key](context);
}

return config[key];
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ module.exports = CoreObject.extend({
return Promise.reject('Could not build revision with tag `' + tag + '` and commit hash `' + sha + '`');
}

return Promise.resolve(info.tag + '+' + sha);
return Promise.resolve({
revisionKey: info.tag + '+' + sha,
timestamp: new Date().toISOString()
});
}
});
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ module.exports = CoreObject.extend({
return Promise.reject('Could not build revision with version `' + json.version + '` and commit hash `' + sha + '`');
}

return json.version + '+' + sha;
return {
revisionKey: json.version + '+' + sha,
timestamp: new Date().toISOString()
};
});
}
});
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ember-cli-deploy-revision-key",
"name": "ember-cli-deploy-revision-data",
"version": "0.1.0-beta.2",
"description": "An ember-cli-plugin to create a unique revision key for the build",
"description": "An ember-cli-deploy plugin to generate data about this deploy revision including a unique revision key based on the current build",
"directories": {
"doc": "doc",
"test": "tests"
Expand All @@ -11,7 +11,7 @@
"build": "ember build",
"test": "node tests/runner.js"
},
"repository": "https://github.com/zapnito/ember-cli-deploy-revision-key",
"repository": "https://github.com/zapnito/ember-cli-deploy-revision-data",
"engines": {
"node": ">= 0.10.0"
},
Expand Down Expand Up @@ -53,7 +53,6 @@
"rsvp": "^3.0.18"
},
"ember-addon": {
"configPath": "tests/dummy/config",
"after": "ember-cli-deploy-json-config"
"configPath": "tests/dummy/config"
}
}
31 changes: 16 additions & 15 deletions tests/unit/index-nodetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ describe('the index', function() {
});

assert.typeOf(plugin.configure, 'function');
assert.typeOf(plugin.didBuild, 'function');
assert.typeOf(plugin.prepare, 'function');
});

describe('configure hook', function() {
it('resolves if config is ok', function() {
var plugin = subject.createDeployPlugin({
name: 'revision-key'
name: 'revision-data'
});

var context = {
ui: mockUi,
config: {
"revision-key": {
"revision-data": {
type: 'file-hash',
filePattern: 'eeee'
}
Expand All @@ -55,13 +55,13 @@ describe('the index', function() {
});
it('warns about missing optional config', function() {
var plugin = subject.createDeployPlugin({
name: 'revision-key'
name: 'revision-data'
});

var context = {
ui: mockUi,
config: {
"revision-key": {
"revision-data": {
}
}
};
Expand All @@ -82,37 +82,37 @@ describe('the index', function() {

it('adds default config to the config object', function() {
var plugin = subject.createDeployPlugin({
name: 'revision-key'
name: 'revision-data'
});

var context = {
ui: mockUi,
config: {
"revision-key": {
"revision-data": {
}
}
};

plugin.beforeHook(context);
plugin.configure(context);

assert.isDefined(context.config['revision-key'].type);
assert.isDefined(context.config['revision-key'].filePattern);
assert.isDefined(context.config['revision-data'].type);
assert.isDefined(context.config['revision-data'].filePattern);
});
});

describe('didBuild hook', function() {
it('returns the revisionKey', function() {
describe('prepare hook', function() {
it('returns the revisionData', function() {
var plugin = subject.createDeployPlugin({
name: 'revision-key'
name: 'revision-data'
});

var context = {
distDir: 'tests/fixtures',
distFiles: ['index.html'],
ui: mockUi,
config: {
"revision-key": {
"revision-data": {
type: 'file-hash',
filePattern: 'index.html',
distDir: function(context) {
Expand All @@ -126,9 +126,10 @@ describe('the index', function() {
};
plugin.beforeHook(context);

return assert.isFulfilled(plugin.didBuild(context))
return assert.isFulfilled(plugin.prepare(context))
.then(function(result) {
assert.equal(result.revisionKey, 'ae1569f72495012cd5e8588e0f2f5d49');
assert.equal(result.revisionData.revisionKey, 'ae1569f72495012cd5e8588e0f2f5d49');
assert.isNotNull(result.revisionData.timestamp);
});
});
});
Expand Down
Loading

0 comments on commit 67ab245

Please sign in to comment.