Skip to content

Commit c94f77f

Browse files
Add CodeDeploy deployment description as parameter (aws-actions#200)
* feat: CodeDeploy deployment description parameter * Remove reference to default value in parameter description Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent b96c18d commit c94f77f

File tree

3 files changed

+96
-2
lines changed

3 files changed

+96
-2
lines changed

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ inputs:
2828
codedeploy-deployment-group:
2929
description: "The name of the AWS CodeDeploy deployment group, if the ECS service uses the CODE_DEPLOY deployment controller. Will default to 'DgpECS-{cluster}-{service}'."
3030
required: false
31+
codedeploy-deployment-description:
32+
description: "A description of the deployment, if the ECS service uses the CODE_DEPLOY deployment controller."
33+
required: false
3134
force-new-deployment:
3235
description: 'Whether to force a new deployment of the service. Valid value is "true". Will default to not force a new deployment.'
3336
required: false

index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ async function createCodeDeployDeployment(codedeploy, clusterName, service, task
172172
let codeDeployGroup = core.getInput('codedeploy-deployment-group', { required: false });
173173
codeDeployGroup = codeDeployGroup ? codeDeployGroup : `DgpECS-${clusterName}-${service}`;
174174

175+
let codeDeployDescription = core.getInput('codedeploy-deployment-description', { required: false });
176+
175177
let deploymentGroupDetails = await codedeploy.getDeploymentGroup({
176178
applicationName: codeDeployApp,
177179
deploymentGroupName: codeDeployGroup
@@ -199,7 +201,7 @@ async function createCodeDeployDeployment(codedeploy, clusterName, service, task
199201

200202
// Start the deployment with the updated appspec contents
201203
core.debug('Starting CodeDeploy deployment');
202-
const createDeployResponse = await codedeploy.createDeployment({
204+
let deploymentParams = {
203205
applicationName: codeDeployApp,
204206
deploymentGroupName: codeDeployGroup,
205207
revision: {
@@ -209,7 +211,12 @@ async function createCodeDeployDeployment(codedeploy, clusterName, service, task
209211
sha256: appSpecHash
210212
}
211213
}
212-
}).promise();
214+
};
215+
// If it hasn't been set then we don't even want to pass it to the api call to maintain previous behaviour.
216+
if (codeDeployDescription) {
217+
deploymentParams.description = codeDeployDescription
218+
}
219+
const createDeployResponse = await codedeploy.createDeployment(deploymentParams).promise();
213220
core.setOutput('codedeploy-deployment-id', createDeployResponse.deploymentId);
214221
core.info(`Deployment started. Watch this deployment's progress in the AWS CodeDeploy console: https://console.aws.amazon.com/codesuite/codedeploy/deployments/${createDeployResponse.deploymentId}?region=${aws.config.region}`);
215222

index.test.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,90 @@ describe('Deploy to ECS', () => {
752752
expect(mockEcsWaiter).toHaveBeenCalledTimes(0);
753753
});
754754

755+
test('registers the task definition contents and creates a CodeDeploy deployment with custom application, deployment group and description', async () => {
756+
core.getInput = jest
757+
.fn(input => {
758+
return {
759+
'task-definition': 'task-definition.json',
760+
'service': 'service-456',
761+
'cluster': 'cluster-789',
762+
'wait-for-service-stability': 'TRUE',
763+
'codedeploy-application': 'Custom-Application',
764+
'codedeploy-deployment-group': 'Custom-Deployment-Group',
765+
'codedeploy-deployment-description': 'Custom-Deployment'
766+
}[input];
767+
});
768+
769+
mockEcsDescribeServices.mockImplementation(() => {
770+
return {
771+
promise() {
772+
return Promise.resolve({
773+
failures: [],
774+
services: [{
775+
status: 'ACTIVE',
776+
deploymentController: {
777+
type: 'CODE_DEPLOY'
778+
}
779+
}]
780+
});
781+
}
782+
};
783+
});
784+
785+
await run();
786+
expect(core.setFailed).toHaveBeenCalledTimes(0);
787+
788+
expect(mockEcsRegisterTaskDef).toHaveBeenNthCalledWith(1, { family: 'task-def-family'});
789+
expect(core.setOutput).toHaveBeenNthCalledWith(1, 'task-definition-arn', 'task:def:arn');
790+
expect(mockEcsDescribeServices).toHaveBeenNthCalledWith(1, {
791+
cluster: 'cluster-789',
792+
services: ['service-456']
793+
});
794+
795+
expect(mockCodeDeployCreateDeployment).toHaveBeenNthCalledWith(1, {
796+
applicationName: 'Custom-Application',
797+
deploymentGroupName: 'Custom-Deployment-Group',
798+
description: 'Custom-Deployment',
799+
revision: {
800+
revisionType: 'AppSpecContent',
801+
appSpecContent: {
802+
content: JSON.stringify({
803+
Resources: [{
804+
TargetService: {
805+
Type: 'AWS::ECS::Service',
806+
Properties: {
807+
TaskDefinition: 'task:def:arn',
808+
LoadBalancerInfo: {
809+
ContainerName: "web",
810+
ContainerPort: 80
811+
}
812+
}
813+
}
814+
}]
815+
}),
816+
sha256: '0911d1e99f48b492e238d1284d8ddb805382d33e1d1fc74ffadf37d8b7e6d096'
817+
}
818+
}
819+
});
820+
821+
expect(mockCodeDeployWaiter).toHaveBeenNthCalledWith(1, 'deploymentSuccessful', {
822+
deploymentId: 'deployment-1',
823+
$waiter: {
824+
delay: 15,
825+
maxAttempts: (
826+
EXPECTED_DEFAULT_WAIT_TIME +
827+
EXPECTED_CODE_DEPLOY_TERMINATION_WAIT_TIME +
828+
EXPECTED_CODE_DEPLOY_DEPLOYMENT_READY_WAIT_TIME
829+
) * 4
830+
}
831+
});
832+
833+
expect(mockEcsUpdateService).toHaveBeenCalledTimes(0);
834+
expect(mockEcsWaiter).toHaveBeenCalledTimes(0);
835+
836+
expect(core.info).toBeCalledWith("Deployment started. Watch this deployment's progress in the AWS CodeDeploy console: https://console.aws.amazon.com/codesuite/codedeploy/deployments/deployment-1?region=fake-region");
837+
});
838+
755839
test('registers the task definition contents at an absolute path', async () => {
756840
core.getInput = jest.fn().mockReturnValueOnce('/hello/task-definition.json');
757841
fs.readFileSync.mockImplementation((pathInput, encoding) => {

0 commit comments

Comments
 (0)