Skip to content

Commit

Permalink
feat: Add more debugging, including link to the ECS or CodeDeploy con…
Browse files Browse the repository at this point in the history
…sole (#56)
  • Loading branch information
clareliguori authored Apr 20, 2020
1 parent 7dc1449 commit f0b3966
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async function updateEcsService(ecs, clusterName, service, taskDefArn, waitForSe
service: service,
taskDefinition: taskDefArn
}).promise();
core.info(`Deployment started. Watch this deployment's progress in the Amazon ECS console: https://console.aws.amazon.com/ecs/home?region=${aws.config.region}#/clusters/${clusterName}/services/${service}/events`);

// Wait for service stability
if (waitForService && waitForService.toLowerCase() === 'true') {
Expand Down Expand Up @@ -169,6 +170,7 @@ async function createCodeDeployDeployment(codedeploy, clusterName, service, task
}
}).promise();
core.setOutput('codedeploy-deployment-id', createDeployResponse.deploymentId);
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}`);

// Wait for deployment to complete
if (waitForService && waitForService.toLowerCase() === 'true') {
Expand Down Expand Up @@ -220,7 +222,15 @@ async function run() {
path.join(process.env.GITHUB_WORKSPACE, taskDefinitionFile);
const fileContents = fs.readFileSync(taskDefPath, 'utf8');
const taskDefContents = removeIgnoredAttributes(cleanNullKeys(yaml.parse(fileContents)));
const registerResponse = await ecs.registerTaskDefinition(taskDefContents).promise();
let registerResponse;
try {
registerResponse = await ecs.registerTaskDefinition(taskDefContents).promise();
} catch (error) {
core.setFailed("Failed to register task definition in ECS: " + error.message);
core.debug("Task definition contents:");
core.debug(JSON.stringify(taskDefContents, undefined, 4));
throw(error);
}
const taskDefArn = registerResponse.taskDefinition.taskDefinitionArn;
core.setOutput('task-definition-arn', taskDefArn);

Expand Down
15 changes: 12 additions & 3 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const mockCodeDeployGetDeploymentGroup = jest.fn();
const mockCodeDeployWaiter = jest.fn();
jest.mock('aws-sdk', () => {
return {
config: {
region: 'fake-region'
},
ECS: jest.fn(() => ({
registerTaskDefinition: mockEcsRegisterTaskDef,
updateService: mockEcsUpdateService,
Expand Down Expand Up @@ -158,6 +161,7 @@ describe('Deploy to ECS', () => {
taskDefinition: 'task:def:arn'
});
expect(mockEcsWaiter).toHaveBeenCalledTimes(0);
expect(core.info).toBeCalledWith("Deployment started. Watch this deployment's progress in the Amazon ECS console: https://console.aws.amazon.com/ecs/home?region=fake-region#/clusters/cluster-789/services/service-456/events");
});

test('cleans null keys out of the task definition contents', async () => {
Expand Down Expand Up @@ -299,6 +303,8 @@ describe('Deploy to ECS', () => {

expect(mockEcsUpdateService).toHaveBeenCalledTimes(0);
expect(mockEcsWaiter).toHaveBeenCalledTimes(0);

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");
});

test('registers the task definition contents and creates a CodeDeploy deployment, waits for 1 hour + deployment group\'s wait time', async () => {
Expand Down Expand Up @@ -807,13 +813,16 @@ describe('Deploy to ECS', () => {
expect(core.setFailed).toBeCalledWith('Unsupported deployment controller: EXTERNAL');
});

test('error is caught by core.setFailed', async () => {

test('error is caught if task def registration fails', async () => {
mockEcsRegisterTaskDef.mockImplementation(() => {
throw new Error();
throw new Error("Could not parse");
});

await run();

expect(core.setFailed).toBeCalled();
expect(core.setFailed).toHaveBeenCalledTimes(2);
expect(core.setFailed).toHaveBeenNthCalledWith(1, 'Failed to register task definition in ECS: Could not parse');
expect(core.setFailed).toHaveBeenNthCalledWith(2, 'Could not parse');
});
});

0 comments on commit f0b3966

Please sign in to comment.