Skip to content

Commit

Permalink
Fix destructuring assignment for deployment groups that have no previ…
Browse files Browse the repository at this point in the history
…ous deployment
  • Loading branch information
mpdude committed Sep 15, 2020
1 parent fc0c006 commit 250217b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
26 changes: 14 additions & 12 deletions create-deployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
}
}
}

Expand Down
26 changes: 14 additions & 12 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
}
}
}

Expand Down

0 comments on commit 250217b

Please sign in to comment.