Skip to content

Commit 3ebb0e6

Browse files
author
Aaron Chambers
committed
Merge pull request #13 from alisdair/git-and-version-commit-key-generators
Add git-tag-commit and version-commit key generators
2 parents 0993043 + c519c72 commit 3ebb0e6

29 files changed

+279
-3
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ For detailed information on how configuration of plugins works, please refer to
5454
The type of [Key Generator](#key-generators) to be used.
5555

5656
*Default:* `'file-hash'`
57+
*Alternatives:* `'git-tag-commit'`, `'version-commit'`
5758

5859
## Key Generators
5960

@@ -83,6 +84,24 @@ The list of built project files. This option should be relative to `distDir` and
8384

8485
*Default:* `context.distFiles`
8586

87+
### Git Tag Commit generator
88+
89+
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.
90+
91+
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`.
92+
93+
### Version Commit generator
94+
95+
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.
96+
97+
#### Configuration Options
98+
99+
##### versionFile
100+
101+
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.
102+
103+
*Default:* `package.json`
104+
86105
## Prerequisites
87106

88107
The following properties are expected to be present on the deployment `context` object:

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module.exports = {
2020
distFiles: function(context) {
2121
return context.distFiles;
2222
},
23+
versionFile: 'package.json',
2324
},
2425
didBuild: function(context) {
2526
var self = this;

lib/key-generators/git-tag-commit.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var CoreObject = require('core-object');
2+
var gitRepoInfo = require('git-repo-info');
3+
var Promise = require('ember-cli/lib/ext/promise');
4+
5+
module.exports = CoreObject.extend({
6+
generate: function() {
7+
var path = gitRepoInfo._findRepo();
8+
9+
if (path === null) {
10+
return Promise.reject('Could not find git repository');
11+
}
12+
13+
var info = gitRepoInfo(path);
14+
var tag = info.tag;
15+
var sha = info.sha.slice(0, 8);
16+
17+
if (!info.tag || !sha) {
18+
return Promise.reject('Could not build revision with tag `' + tag + '` and commit hash `' + sha + '`');
19+
}
20+
21+
return Promise.resolve(info.tag + '+' + sha);
22+
}
23+
});

lib/key-generators/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module.exports = {
2-
"file-hash": require('./file-hash')
2+
"file-hash": require('./file-hash'),
3+
"git-tag-commit": require('./git-tag-commit'),
4+
"version-commit": require('./version-commit')
35
};

lib/key-generators/version-commit.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var CoreObject = require('core-object');
2+
var gitRepoInfo = require('git-repo-info');
3+
var fs = require('fs');
4+
var Promise = require('ember-cli/lib/ext/promise');
5+
6+
var denodeify = require('rsvp').denodeify;
7+
var readFile = denodeify(fs.readFile);
8+
9+
module.exports = CoreObject.extend({
10+
init: function(options) {
11+
this._plugin = options.plugin;
12+
},
13+
14+
generate: function() {
15+
var versionFile = this._plugin.readConfig('versionFile');
16+
17+
var path = gitRepoInfo._findRepo();
18+
19+
if (path === null) {
20+
return Promise.reject('Could not find git repository');
21+
}
22+
23+
var info = gitRepoInfo(path);
24+
var sha = info.sha.slice(0, 8);
25+
26+
return readFile(versionFile)
27+
.then(function(contents) {
28+
var json = JSON.parse(contents);
29+
30+
if (!json.version || !sha) {
31+
return Promise.reject('Could not build revision with version `' + json.version + '` and commit hash `' + sha + '`');
32+
}
33+
34+
return json.version + '+' + sha;
35+
});
36+
}
37+
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@
4646
"dependencies": {
4747
"chalk": "^1.0.0",
4848
"core-object": "^1.1.0",
49-
"ember-cli-deploy-plugin": "0.1.3",
5049
"ember-cli-babel": "^5.0.0",
50+
"ember-cli-deploy-plugin": "0.1.3",
51+
"git-repo-info": "^1.1.2",
5152
"minimatch": "^2.0.4",
5253
"rsvp": "^3.0.18"
5354
},
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"version": "3.2.1"
3+
}

tests/fixtures/repo/dotgit/HEAD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/master

tests/fixtures/repo/dotgit/config

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = true
4+
bare = false
5+
logallrefupdates = true
6+
ignorecase = true
7+
precomposeunicode = true

tests/fixtures/repo/dotgit/index

225 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)