From ce09c382fe756d0cba3c67468c573542bc19c4ce Mon Sep 17 00:00:00 2001 From: Ivan Akulov Date: Wed, 19 Jun 2019 18:10:00 +0300 Subject: [PATCH 1/8] =?UTF-8?q?Resolve=20the=20=E2=80=9CCommand=20failed:?= =?UTF-8?q?=20git=20write-tree=E2=80=9D=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #25. --- src/index.js | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/index.js b/src/index.js index 513ca28..250c846 100644 --- a/src/index.js +++ b/src/index.js @@ -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) + for (const functionName of this.serverless.service.getAllFunctions()) { + const func = this.serverless.service.getFunction(functionName); + + const sha1 = await this._getValue('sha1'); + this.exportGitVariable(func, 'GIT_COMMIT_SHORT', sha1); + + const commit = await this._getValue('commit'); + this.exportGitVariable(func, 'GIT_COMMIT_LONG', commit); + + const branch = await this._getValue('branch'); + this.exportGitVariable(func, 'GIT_BRANCH', branch); + + const isDirty = await this._getValue('isDirty'); + this.exportGitVariable(func, 'GIT_IS_DIRTY', isDirty); + } } exportGitVariable(func, variableName, gitValue) { From 170865bb93bd89c81bc5b65735867d3cf28e8709 Mon Sep 17 00:00:00 2001 From: Ivan Akulov Date: Wed, 19 Jun 2019 18:43:56 +0300 Subject: [PATCH 2/8] Fix styling issues --- src/index.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/index.js b/src/index.js index 250c846..12573df 100644 --- a/src/index.js +++ b/src/index.js @@ -96,19 +96,19 @@ export default class ServerlessGitVariables { } for (const functionName of this.serverless.service.getAllFunctions()) { - const func = this.serverless.service.getFunction(functionName); - + const func = this.serverless.service.getFunction(functionName) + const sha1 = await this._getValue('sha1'); - this.exportGitVariable(func, 'GIT_COMMIT_SHORT', sha1); - + this.exportGitVariable(func, 'GIT_COMMIT_SHORT', sha1) + const commit = await this._getValue('commit'); - this.exportGitVariable(func, 'GIT_COMMIT_LONG', commit); - + this.exportGitVariable(func, 'GIT_COMMIT_LONG', commit) + const branch = await this._getValue('branch'); - this.exportGitVariable(func, 'GIT_BRANCH', branch); - + this.exportGitVariable(func, 'GIT_BRANCH', branch) + const isDirty = await this._getValue('isDirty'); - this.exportGitVariable(func, 'GIT_IS_DIRTY', isDirty); + this.exportGitVariable(func, 'GIT_IS_DIRTY', isDirty) } } From db20282d024baa8e40f4326469f446520c508118 Mon Sep 17 00:00:00 2001 From: Ivan Akulov Date: Fri, 21 Jun 2019 11:29:26 +0300 Subject: [PATCH 3/8] Remove extra semicolons --- src/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 12573df..ae55876 100644 --- a/src/index.js +++ b/src/index.js @@ -98,16 +98,16 @@ export default class ServerlessGitVariables { for (const functionName of this.serverless.service.getAllFunctions()) { const func = this.serverless.service.getFunction(functionName) - const sha1 = await this._getValue('sha1'); + const sha1 = await this._getValue('sha1') this.exportGitVariable(func, 'GIT_COMMIT_SHORT', sha1) - const commit = await this._getValue('commit'); + const commit = await this._getValue('commit') this.exportGitVariable(func, 'GIT_COMMIT_LONG', commit) - const branch = await this._getValue('branch'); + const branch = await this._getValue('branch') this.exportGitVariable(func, 'GIT_BRANCH', branch) - const isDirty = await this._getValue('isDirty'); + const isDirty = await this._getValue('isDirty') this.exportGitVariable(func, 'GIT_IS_DIRTY', isDirty) } } From 56a840d9dee4eb57b31fcd8219654cb69e8c171e Mon Sep 17 00:00:00 2001 From: Ivan Akulov Date: Thu, 27 Jun 2019 10:51:52 +0300 Subject: [PATCH 4/8] Add the forgotten GIT_REPOSITORY variable --- src/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/index.js b/src/index.js index ae55876..7e4cbae 100644 --- a/src/index.js +++ b/src/index.js @@ -109,6 +109,9 @@ export default class ServerlessGitVariables { const isDirty = await this._getValue('isDirty') this.exportGitVariable(func, 'GIT_IS_DIRTY', isDirty) + + const repository = await this._getValue('repository') + this.exportGitVariable(func, 'GIT_REPOSITORY', repository) } } From 92f26301dde0c6f5313dfcc06381a1cfc5897b15 Mon Sep 17 00:00:00 2001 From: Ivan Akulov Date: Thu, 27 Jun 2019 10:57:18 +0300 Subject: [PATCH 5/8] Move `await`s out of the loop --- src/index.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/index.js b/src/index.js index 7e4cbae..24dde04 100644 --- a/src/index.js +++ b/src/index.js @@ -94,23 +94,20 @@ export default class ServerlessGitVariables { if (exportGitVariables === false) { return } + + 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) - const sha1 = await this._getValue('sha1') - this.exportGitVariable(func, 'GIT_COMMIT_SHORT', sha1) - - const commit = await this._getValue('commit') + this.exportGitVariable(func, 'GIT_COMMIT_SHORT', sha1) this.exportGitVariable(func, 'GIT_COMMIT_LONG', commit) - - const branch = await this._getValue('branch') this.exportGitVariable(func, 'GIT_BRANCH', branch) - - const isDirty = await this._getValue('isDirty') this.exportGitVariable(func, 'GIT_IS_DIRTY', isDirty) - - const repository = await this._getValue('repository') this.exportGitVariable(func, 'GIT_REPOSITORY', repository) } } From a2a52a802b6ccc7252a97ad71f7d8a2230292591 Mon Sep 17 00:00:00 2001 From: Ivan Akulov Date: Thu, 27 Jun 2019 11:17:36 +0300 Subject: [PATCH 6/8] Remove trailing spaces --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 24dde04..67d2539 100644 --- a/src/index.js +++ b/src/index.js @@ -94,7 +94,7 @@ export default class ServerlessGitVariables { if (exportGitVariables === false) { return } - + const sha1 = await this._getValue('sha1') const commit = await this._getValue('commit') const branch = await this._getValue('branch') @@ -104,7 +104,7 @@ export default class ServerlessGitVariables { 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_SHORT', sha1) this.exportGitVariable(func, 'GIT_COMMIT_LONG', commit) this.exportGitVariable(func, 'GIT_BRANCH', branch) this.exportGitVariable(func, 'GIT_IS_DIRTY', isDirty) From c3f9fa1ce324b619dd97f6b15e4c256c8e6917ee Mon Sep 17 00:00:00 2001 From: Jacob Meacham Date: Thu, 27 Jun 2019 13:09:57 -0600 Subject: [PATCH 7/8] Run rebuild --- lib/index.js | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/lib/index.js b/lib/index.js index c2cbcaa..c878efa 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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) { From 2c9d0c8de520edbb7d79ac8cf341824d19f040a5 Mon Sep 17 00:00:00 2001 From: Jacob Meacham Date: Thu, 27 Jun 2019 13:13:08 -0600 Subject: [PATCH 8/8] Prepare for 3.3.2 release --- README.md | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f6d9370..b48255b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package.json b/package.json index 3f95992..dbb0b61 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-plugin-git-variables", - "version": "3.3.1", + "version": "3.3.2", "engines": { "node": ">=7.0" },