Skip to content

Commit 23acd87

Browse files
committed
fix: truncate overly long code deploy descriptions
1 parent a581b23 commit 23acd87

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];
@@ -316,9 +312,11 @@ async function createCodeDeployDeployment(codedeploy, clusterName, service, task
316312
}
317313
}
318314
};
315+
319316
// If it hasn't been set then we don't even want to pass it to the api call to maintain previous behaviour.
320317
if (codeDeployDescription) {
321-
deploymentParams.description = codeDeployDescription
318+
// CodeDeploy Deployment Descriptions have a max length of 512 characters, so truncate if necessary
319+
deploymentParams.description = (codeDeployDescription.length <= 512) ? codeDeployDescription : `${codeDeployDescription.substring(0,511)}…`;
322320
}
323321
const createDeployResponse = await codedeploy.createDeployment(deploymentParams).promise();
324322
core.setOutput('codedeploy-deployment-id', createDeployResponse.deploymentId);

index.test.js

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

944+
test('registers the task definition contents and creates a CodeDeploy deployment with custom application, deployment group and long description', async () => {
945+
core.getInput = jest
946+
.fn(input => {
947+
return {
948+
'task-definition': 'task-definition.json',
949+
'service': 'service-456',
950+
'cluster': 'cluster-789',
951+
'wait-for-service-stability': 'TRUE',
952+
'codedeploy-application': 'Custom-Application',
953+
'codedeploy-deployment-group': 'Custom-Deployment-Group',
954+
'codedeploy-deployment-description': 'Custom-Deployment'.repeat(31)
955+
}[input];
956+
});
957+
958+
mockEcsDescribeServices.mockImplementation(() => {
959+
return {
960+
promise() {
961+
return Promise.resolve({
962+
failures: [],
963+
services: [{
964+
status: 'ACTIVE',
965+
deploymentController: {
966+
type: 'CODE_DEPLOY'
967+
}
968+
}]
969+
});
970+
}
971+
};
972+
});
973+
974+
await run();
975+
expect(core.setFailed).toHaveBeenCalledTimes(0);
976+
977+
expect(mockEcsRegisterTaskDef).toHaveBeenNthCalledWith(1, { family: 'task-def-family'});
978+
expect(core.setOutput).toHaveBeenNthCalledWith(1, 'task-definition-arn', 'task:def:arn');
979+
expect(mockEcsDescribeServices).toHaveBeenNthCalledWith(1, {
980+
cluster: 'cluster-789',
981+
services: ['service-456']
982+
});
983+
984+
expect(mockCodeDeployCreateDeployment).toHaveBeenNthCalledWith(1, {
985+
applicationName: 'Custom-Application',
986+
deploymentGroupName: 'Custom-Deployment-Group',
987+
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…',
988+
revision: {
989+
revisionType: 'AppSpecContent',
990+
appSpecContent: {
991+
content: JSON.stringify({
992+
Resources: [{
993+
TargetService: {
994+
Type: 'AWS::ECS::Service',
995+
Properties: {
996+
TaskDefinition: 'task:def:arn',
997+
LoadBalancerInfo: {
998+
ContainerName: "web",
999+
ContainerPort: 80
1000+
}
1001+
}
1002+
}
1003+
}]
1004+
}),
1005+
sha256: '0911d1e99f48b492e238d1284d8ddb805382d33e1d1fc74ffadf37d8b7e6d096'
1006+
}
1007+
}
1008+
});
1009+
1010+
expect(mockCodeDeployWaiter).toHaveBeenNthCalledWith(1, 'deploymentSuccessful', {
1011+
deploymentId: 'deployment-1',
1012+
$waiter: {
1013+
delay: 15,
1014+
maxAttempts: (
1015+
EXPECTED_DEFAULT_WAIT_TIME +
1016+
EXPECTED_CODE_DEPLOY_TERMINATION_WAIT_TIME +
1017+
EXPECTED_CODE_DEPLOY_DEPLOYMENT_READY_WAIT_TIME
1018+
) * 4
1019+
}
1020+
});
1021+
1022+
expect(mockEcsUpdateService).toHaveBeenCalledTimes(0);
1023+
expect(mockEcsWaiter).toHaveBeenCalledTimes(0);
1024+
1025+
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");
1026+
});
1027+
9441028
test('registers the task definition contents at an absolute path', async () => {
9451029
core.getInput = jest.fn().mockReturnValueOnce('/hello/task-definition.json');
9461030
fs.readFileSync.mockImplementation((pathInput, encoding) => {
@@ -1175,7 +1259,7 @@ describe('Deploy to ECS', () => {
11751259
launchType: "EC2",
11761260
taskDefinition: 'task:def:arn',
11771261
overrides: { containerOverrides: [{ name: 'someapp', command: 'somecmd' }] },
1178-
networkConfiguration: { awsVpcNetworkConfiguration: { subnets: ['a', 'b'], securityGroups: ['c', 'd'] } }
1262+
networkConfiguration: { awsvpcConfiguration: { subnets: ['a', 'b'], securityGroups: ['c', 'd'] } }
11791263
});
11801264
expect(core.setOutput).toHaveBeenNthCalledWith(2, 'run-task-arn', ["arn:aws:ecs:fake-region:account_id:task/arn"]);
11811265
});

0 commit comments

Comments
 (0)