Skip to content

Commit

Permalink
Merge branch 'release/3.3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-meacham committed Jun 27, 2019
2 parents 4796362 + 2c9d0c8 commit f0eceab
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 35 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -46,6 +46,8 @@ For more information on annotated and lightweight tags go to the [git documentat
* If you're using serverless 1.16.x or above, use the >=2.x.x version of this plugin.

# Version History
* 3.3.2
- Fixed issue with sporadic command failures (Thanks to @iamakulov)
* 3.3.1
- Changed approach for finding repository name, to fix plugin on Windows
* 3.3.0
Expand Down
38 changes: 23 additions & 15 deletions lib/index.js
Expand Up @@ -125,22 +125,30 @@ class ServerlessGitVariables {
}

exportGitVariables() {
const exportGitVariables = this.serverless.service.custom && this.serverless.service.custom.exportGitVariables;
if (exportGitVariables === false) {
return _promise2.default.resolve();
}
var _this3 = this;

const promises = this.serverless.service.getAllFunctions().map(functionName => {
return _promise2.default.all([this._getValue('sha1'), this._getValue('commit'), this._getValue('branch'), this._getValue('isDirty'), this._getValue('repository')]).then(([sha1, commit, branch, isDirty, repository]) => {
const func = this.serverless.service.getFunction(functionName);
this.exportGitVariable(func, 'GIT_COMMIT_SHORT', sha1);
this.exportGitVariable(func, 'GIT_COMMIT_LONG', commit);
this.exportGitVariable(func, 'GIT_BRANCH', branch);
this.exportGitVariable(func, 'GIT_IS_DIRTY', isDirty);
this.exportGitVariable(func, 'GIT_REPOSITORY', repository);
});
});
return _promise2.default.all(promises);
return (0, _asyncToGenerator3.default)(function* () {
const exportGitVariables = _this3.serverless.service.custom && _this3.serverless.service.custom.exportGitVariables;
if (exportGitVariables === false) {
return;
}

const sha1 = yield _this3._getValue('sha1');
const commit = yield _this3._getValue('commit');
const branch = yield _this3._getValue('branch');
const isDirty = yield _this3._getValue('isDirty');
const repository = yield _this3._getValue('repository');

for (const functionName of _this3.serverless.service.getAllFunctions()) {
const func = _this3.serverless.service.getFunction(functionName);

_this3.exportGitVariable(func, 'GIT_COMMIT_SHORT', sha1);
_this3.exportGitVariable(func, 'GIT_COMMIT_LONG', commit);
_this3.exportGitVariable(func, 'GIT_BRANCH', branch);
_this3.exportGitVariable(func, 'GIT_IS_DIRTY', isDirty);
_this3.exportGitVariable(func, 'GIT_REPOSITORY', repository);
}
})();
}

exportGitVariable(func, variableName, gitValue) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "serverless-plugin-git-variables",
"version": "3.3.1",
"version": "3.3.2",
"engines": {
"node": ">=7.0"
},
Expand Down
36 changes: 17 additions & 19 deletions src/index.js
Expand Up @@ -89,29 +89,27 @@ export default class ServerlessGitVariables {
return value
}

exportGitVariables() {
async exportGitVariables() {
const exportGitVariables = this.serverless.service.custom && this.serverless.service.custom.exportGitVariables
if (exportGitVariables === false) {
return Promise.resolve()
return
}

const promises = this.serverless.service.getAllFunctions().map((functionName) => {
return Promise.all([
this._getValue('sha1'),
this._getValue('commit'),
this._getValue('branch'),
this._getValue('isDirty'),
this._getValue('repository')
]).then(([sha1, commit, branch, isDirty, repository]) => {
const func = this.serverless.service.getFunction(functionName)
this.exportGitVariable(func, 'GIT_COMMIT_SHORT', sha1)
this.exportGitVariable(func, 'GIT_COMMIT_LONG', commit)
this.exportGitVariable(func, 'GIT_BRANCH', branch)
this.exportGitVariable(func, 'GIT_IS_DIRTY', isDirty)
this.exportGitVariable(func, 'GIT_REPOSITORY', repository)
})
})
return Promise.all(promises)
const sha1 = await this._getValue('sha1')
const commit = await this._getValue('commit')
const branch = await this._getValue('branch')
const isDirty = await this._getValue('isDirty')
const repository = await this._getValue('repository')

for (const functionName of this.serverless.service.getAllFunctions()) {
const func = this.serverless.service.getFunction(functionName)

this.exportGitVariable(func, 'GIT_COMMIT_SHORT', sha1)
this.exportGitVariable(func, 'GIT_COMMIT_LONG', commit)
this.exportGitVariable(func, 'GIT_BRANCH', branch)
this.exportGitVariable(func, 'GIT_IS_DIRTY', isDirty)
this.exportGitVariable(func, 'GIT_REPOSITORY', repository)
}
}

exportGitVariable(func, variableName, gitValue) {
Expand Down

0 comments on commit f0eceab

Please sign in to comment.