Skip to content

Commit 250217b

Browse files
committed
Fix destructuring assignment for deployment groups that have no previous deployment
1 parent fc0c006 commit 250217b

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

create-deployment.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,26 @@ exports.createDeployment = async function(applicationName, fullRepositoryName, b
7373
}
7474

7575
if (runNumber) {
76-
var {deploymentGroupInfo: {lastAttemptedDeployment: {deploymentId: lastAttemptedDeploymentId}}} = await codeDeploy.getDeploymentGroup({
76+
var {deploymentGroupInfo: {lastAttemptedDeployment: {deploymentId: lastAttemptedDeploymentId} = {}}} = await codeDeploy.getDeploymentGroup({
7777
applicationName: applicationName,
7878
deploymentGroupName: deploymentGroupName,
7979
}).promise();
8080

81-
var {deploymentInfo: {description: lastAttemptedDeploymentDescription}} = await codeDeploy.getDeployment({
82-
deploymentId: lastAttemptedDeploymentId,
83-
}).promise();
81+
if (lastAttemptedDeploymentId) {
82+
var {deploymentInfo: {description: lastAttemptedDeploymentDescription}} = await codeDeploy.getDeployment({
83+
deploymentId: lastAttemptedDeploymentId,
84+
}).promise();
8485

85-
var matches, lastAttemptedDeploymentRunNumber;
86+
var matches, lastAttemptedDeploymentRunNumber;
8687

87-
if (matches = lastAttemptedDeploymentDescription.match(/run_number=(\d+)/)) {
88-
lastAttemptedDeploymentRunNumber = matches[1];
89-
if (parseInt(lastAttemptedDeploymentRunNumber) > parseInt(runNumber)) {
90-
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.`);
91-
return;
92-
} else {
93-
console.log(`🔎 Last attempted deployment was from run number ${lastAttemptedDeploymentRunNumber}, this is run number ${runNumber} - proceeding.`);
88+
if (matches = lastAttemptedDeploymentDescription.match(/run_number=(\d+)/)) {
89+
lastAttemptedDeploymentRunNumber = matches[1];
90+
if (parseInt(lastAttemptedDeploymentRunNumber) > parseInt(runNumber)) {
91+
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.`);
92+
return;
93+
} else {
94+
console.log(`🔎 Last attempted deployment was from run number ${lastAttemptedDeploymentRunNumber}, this is run number ${runNumber} - proceeding.`);
95+
}
9496
}
9597
}
9698

dist/index.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,26 @@ exports.createDeployment = async function(applicationName, fullRepositoryName, b
8989
}
9090

9191
if (runNumber) {
92-
var {deploymentGroupInfo: {lastAttemptedDeployment: {deploymentId: lastAttemptedDeploymentId}}} = await codeDeploy.getDeploymentGroup({
92+
var {deploymentGroupInfo: {lastAttemptedDeployment: {deploymentId: lastAttemptedDeploymentId} = {}}} = await codeDeploy.getDeploymentGroup({
9393
applicationName: applicationName,
9494
deploymentGroupName: deploymentGroupName,
9595
}).promise();
9696

97-
var {deploymentInfo: {description: lastAttemptedDeploymentDescription}} = await codeDeploy.getDeployment({
98-
deploymentId: lastAttemptedDeploymentId,
99-
}).promise();
97+
if (lastAttemptedDeploymentId) {
98+
var {deploymentInfo: {description: lastAttemptedDeploymentDescription}} = await codeDeploy.getDeployment({
99+
deploymentId: lastAttemptedDeploymentId,
100+
}).promise();
100101

101-
var matches, lastAttemptedDeploymentRunNumber;
102+
var matches, lastAttemptedDeploymentRunNumber;
102103

103-
if (matches = lastAttemptedDeploymentDescription.match(/run_number=(\d+)/)) {
104-
lastAttemptedDeploymentRunNumber = matches[1];
105-
if (parseInt(lastAttemptedDeploymentRunNumber) > parseInt(runNumber)) {
106-
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.`);
107-
return;
108-
} else {
109-
console.log(`🔎 Last attempted deployment was from run number ${lastAttemptedDeploymentRunNumber}, this is run number ${runNumber} - proceeding.`);
104+
if (matches = lastAttemptedDeploymentDescription.match(/run_number=(\d+)/)) {
105+
lastAttemptedDeploymentRunNumber = matches[1];
106+
if (parseInt(lastAttemptedDeploymentRunNumber) > parseInt(runNumber)) {
107+
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.`);
108+
return;
109+
} else {
110+
console.log(`🔎 Last attempted deployment was from run number ${lastAttemptedDeploymentRunNumber}, this is run number ${runNumber} - proceeding.`);
111+
}
110112
}
111113
}
112114

0 commit comments

Comments
 (0)