Skip to content

Commit ab77eed

Browse files
committed
fix: truncate overly long code deploy descriptions
1 parent 9a8a47a commit ab77eed

File tree

3 files changed

+90
-8
lines changed

3 files changed

+90
-8
lines changed

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ inputs:
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
3131
codedeploy-deployment-description:
32-
description: "A description of the deployment, if the ECS service uses the CODE_DEPLOY deployment controller."
32+
description: "A description of the deployment, if the ECS service uses the CODE_DEPLOY deployment controller. NOTE: This will be truncated to 512 characters if necessary."
3333
required: false
3434
force-new-deployment:
3535
description: 'Whether to force a new deployment of the service. Valid value is "true". Will default to not force a new deployment.'

index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes) {
5555

5656
const taskArns = runTaskResponse.tasks.map(task => task.taskArn);
5757
core.setOutput('run-task-arn', taskArns);
58-
59-
taskArns.map(taskArn => {
60-
let taskId = taskArn.split('/').pop();
61-
core.info(`Task running: https://console.aws.amazon.com/ecs/home?region=${aws.config.region}#/clusters/${clusterName}/tasks`)
62-
});
58+
core.info(`Task running: https://console.aws.amazon.com/ecs/home?region=${aws.config.region}#/clusters/${clusterName}/tasks`);
6359

6460
if (runTaskResponse.failures && runTaskResponse.failures.length > 0) {
6561
const failure = runTaskResponse.failures[0];
@@ -313,9 +309,11 @@ async function createCodeDeployDeployment(codedeploy, clusterName, service, task
313309
}
314310
}
315311
};
312+
316313
// If it hasn't been set then we don't even want to pass it to the api call to maintain previous behaviour.
317314
if (codeDeployDescription) {
318-
deploymentParams.description = codeDeployDescription
315+
// CodeDeploy Deployment Descriptions have a max length of 512 characters, so truncate if necessary
316+
deploymentParams.description = (codeDeployDescription.length <= 512) ? codeDeployDescription : `${codeDeployDescription.substring(0,511)}…`;
319317
}
320318
const createDeployResponse = await codedeploy.createDeployment(deploymentParams).promise();
321319
core.setOutput('codedeploy-deployment-id', createDeployResponse.deploymentId);

index.test.js

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,90 @@ describe('Deploy to ECS', () => {
893893
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");
894894
});
895895

896+
test('registers the task definition contents and creates a CodeDeploy deployment with custom application, deployment group and long description', async () => {
897+
core.getInput = jest
898+
.fn(input => {
899+
return {
900+
'task-definition': 'task-definition.json',
901+
'service': 'service-456',
902+
'cluster': 'cluster-789',
903+
'wait-for-service-stability': 'TRUE',
904+
'codedeploy-application': 'Custom-Application',
905+
'codedeploy-deployment-group': 'Custom-Deployment-Group',
906+
'codedeploy-deployment-description': 'Custom-Deployment'.repeat(31)
907+
}[input];
908+
});
909+
910+
mockEcsDescribeServices.mockImplementation(() => {
911+
return {
912+
promise() {
913+
return Promise.resolve({
914+
failures: [],
915+
services: [{
916+
status: 'ACTIVE',
917+
deploymentController: {
918+
type: 'CODE_DEPLOY'
919+
}
920+
}]
921+
});
922+
}
923+
};
924+
});
925+
926+
await run();
927+
expect(core.setFailed).toHaveBeenCalledTimes(0);
928+
929+
expect(mockEcsRegisterTaskDef).toHaveBeenNthCalledWith(1, { family: 'task-def-family'});
930+
expect(core.setOutput).toHaveBeenNthCalledWith(1, 'task-definition-arn', 'task:def:arn');
931+
expect(mockEcsDescribeServices).toHaveBeenNthCalledWith(1, {
932+
cluster: 'cluster-789',
933+
services: ['service-456']
934+
});
935+
936+
expect(mockCodeDeployCreateDeployment).toHaveBeenNthCalledWith(1, {
937+
applicationName: 'Custom-Application',
938+
deploymentGroupName: 'Custom-Deployment-Group',
939+
description: 'Custom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentC…',
940+
revision: {
941+
revisionType: 'AppSpecContent',
942+
appSpecContent: {
943+
content: JSON.stringify({
944+
Resources: [{
945+
TargetService: {
946+
Type: 'AWS::ECS::Service',
947+
Properties: {
948+
TaskDefinition: 'task:def:arn',
949+
LoadBalancerInfo: {
950+
ContainerName: "web",
951+
ContainerPort: 80
952+
}
953+
}
954+
}
955+
}]
956+
}),
957+
sha256: '0911d1e99f48b492e238d1284d8ddb805382d33e1d1fc74ffadf37d8b7e6d096'
958+
}
959+
}
960+
});
961+
962+
expect(mockCodeDeployWaiter).toHaveBeenNthCalledWith(1, 'deploymentSuccessful', {
963+
deploymentId: 'deployment-1',
964+
$waiter: {
965+
delay: 15,
966+
maxAttempts: (
967+
EXPECTED_DEFAULT_WAIT_TIME +
968+
EXPECTED_CODE_DEPLOY_TERMINATION_WAIT_TIME +
969+
EXPECTED_CODE_DEPLOY_DEPLOYMENT_READY_WAIT_TIME
970+
) * 4
971+
}
972+
});
973+
974+
expect(mockEcsUpdateService).toHaveBeenCalledTimes(0);
975+
expect(mockEcsWaiter).toHaveBeenCalledTimes(0);
976+
977+
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");
978+
});
979+
896980
test('registers the task definition contents at an absolute path', async () => {
897981
core.getInput = jest.fn().mockReturnValueOnce('/hello/task-definition.json');
898982
fs.readFileSync.mockImplementation((pathInput, encoding) => {
@@ -1127,7 +1211,7 @@ describe('Deploy to ECS', () => {
11271211
launchType: "EC2",
11281212
taskDefinition: 'task:def:arn',
11291213
overrides: { containerOverrides: [{ name: 'someapp', command: 'somecmd' }] },
1130-
networkConfiguration: { awsVpcNetworkConfiguration: { subnets: ['a', 'b'], securityGroups: ['c', 'd'] } }
1214+
networkConfiguration: { awsvpcConfiguration: { subnets: ['a', 'b'], securityGroups: ['c', 'd'] } }
11311215
});
11321216
expect(core.setOutput).toHaveBeenNthCalledWith(2, 'run-task-arn', ["arn:aws:ecs:fake-region:account_id:task/arn"]);
11331217
});

0 commit comments

Comments
 (0)