From 250217bff4afbd33024ad9b452647b6aacfac1d7 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Tue, 15 Sep 2020 11:29:40 +0000 Subject: [PATCH] Fix destructuring assignment for deployment groups that have no previous deployment --- create-deployment.js | 26 ++++++++++++++------------ dist/index.js | 26 ++++++++++++++------------ 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/create-deployment.js b/create-deployment.js index b33eedb..be7ffeb 100644 --- a/create-deployment.js +++ b/create-deployment.js @@ -73,24 +73,26 @@ exports.createDeployment = async function(applicationName, fullRepositoryName, b } if (runNumber) { - var {deploymentGroupInfo: {lastAttemptedDeployment: {deploymentId: lastAttemptedDeploymentId}}} = await codeDeploy.getDeploymentGroup({ + var {deploymentGroupInfo: {lastAttemptedDeployment: {deploymentId: lastAttemptedDeploymentId} = {}}} = await codeDeploy.getDeploymentGroup({ applicationName: applicationName, deploymentGroupName: deploymentGroupName, }).promise(); - var {deploymentInfo: {description: lastAttemptedDeploymentDescription}} = await codeDeploy.getDeployment({ - deploymentId: lastAttemptedDeploymentId, - }).promise(); + if (lastAttemptedDeploymentId) { + var {deploymentInfo: {description: lastAttemptedDeploymentDescription}} = await codeDeploy.getDeployment({ + deploymentId: lastAttemptedDeploymentId, + }).promise(); - var matches, lastAttemptedDeploymentRunNumber; + var matches, lastAttemptedDeploymentRunNumber; - if (matches = lastAttemptedDeploymentDescription.match(/run_number=(\d+)/)) { - lastAttemptedDeploymentRunNumber = matches[1]; - if (parseInt(lastAttemptedDeploymentRunNumber) > parseInt(runNumber)) { - core.setFailed(`🙅‍♂️ The last attempted deployment as returned by the AWS API has been created by a higher run number ${lastAttemptedDeploymentRunNumber}, this is run number ${runNumber}. Aborting.`); - return; - } else { - console.log(`🔎 Last attempted deployment was from run number ${lastAttemptedDeploymentRunNumber}, this is run number ${runNumber} - proceeding.`); + if (matches = lastAttemptedDeploymentDescription.match(/run_number=(\d+)/)) { + lastAttemptedDeploymentRunNumber = matches[1]; + if (parseInt(lastAttemptedDeploymentRunNumber) > parseInt(runNumber)) { + core.setFailed(`🙅‍♂️ The last attempted deployment as returned by the AWS API has been created by a higher run number ${lastAttemptedDeploymentRunNumber}, this is run number ${runNumber}. Aborting.`); + return; + } else { + console.log(`🔎 Last attempted deployment was from run number ${lastAttemptedDeploymentRunNumber}, this is run number ${runNumber} - proceeding.`); + } } } diff --git a/dist/index.js b/dist/index.js index 66cea80..015945a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -89,24 +89,26 @@ exports.createDeployment = async function(applicationName, fullRepositoryName, b } if (runNumber) { - var {deploymentGroupInfo: {lastAttemptedDeployment: {deploymentId: lastAttemptedDeploymentId}}} = await codeDeploy.getDeploymentGroup({ + var {deploymentGroupInfo: {lastAttemptedDeployment: {deploymentId: lastAttemptedDeploymentId} = {}}} = await codeDeploy.getDeploymentGroup({ applicationName: applicationName, deploymentGroupName: deploymentGroupName, }).promise(); - var {deploymentInfo: {description: lastAttemptedDeploymentDescription}} = await codeDeploy.getDeployment({ - deploymentId: lastAttemptedDeploymentId, - }).promise(); + if (lastAttemptedDeploymentId) { + var {deploymentInfo: {description: lastAttemptedDeploymentDescription}} = await codeDeploy.getDeployment({ + deploymentId: lastAttemptedDeploymentId, + }).promise(); - var matches, lastAttemptedDeploymentRunNumber; + var matches, lastAttemptedDeploymentRunNumber; - if (matches = lastAttemptedDeploymentDescription.match(/run_number=(\d+)/)) { - lastAttemptedDeploymentRunNumber = matches[1]; - if (parseInt(lastAttemptedDeploymentRunNumber) > parseInt(runNumber)) { - core.setFailed(`🙅‍♂️ The last attempted deployment as returned by the AWS API has been created by a higher run number ${lastAttemptedDeploymentRunNumber}, this is run number ${runNumber}. Aborting.`); - return; - } else { - console.log(`🔎 Last attempted deployment was from run number ${lastAttemptedDeploymentRunNumber}, this is run number ${runNumber} - proceeding.`); + if (matches = lastAttemptedDeploymentDescription.match(/run_number=(\d+)/)) { + lastAttemptedDeploymentRunNumber = matches[1]; + if (parseInt(lastAttemptedDeploymentRunNumber) > parseInt(runNumber)) { + core.setFailed(`🙅‍♂️ The last attempted deployment as returned by the AWS API has been created by a higher run number ${lastAttemptedDeploymentRunNumber}, this is run number ${runNumber}. Aborting.`); + return; + } else { + console.log(`🔎 Last attempted deployment was from run number ${lastAttemptedDeploymentRunNumber}, this is run number ${runNumber} - proceeding.`); + } } }