Skip to content

Commit f0b3966

Browse files
authored
feat: Add more debugging, including link to the ECS or CodeDeploy console (#56)
1 parent 7dc1449 commit f0b3966

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ async function updateEcsService(ecs, clusterName, service, taskDefArn, waitForSe
2525
service: service,
2626
taskDefinition: taskDefArn
2727
}).promise();
28+
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`);
2829

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

173175
// Wait for deployment to complete
174176
if (waitForService && waitForService.toLowerCase() === 'true') {
@@ -220,7 +222,15 @@ async function run() {
220222
path.join(process.env.GITHUB_WORKSPACE, taskDefinitionFile);
221223
const fileContents = fs.readFileSync(taskDefPath, 'utf8');
222224
const taskDefContents = removeIgnoredAttributes(cleanNullKeys(yaml.parse(fileContents)));
223-
const registerResponse = await ecs.registerTaskDefinition(taskDefContents).promise();
225+
let registerResponse;
226+
try {
227+
registerResponse = await ecs.registerTaskDefinition(taskDefContents).promise();
228+
} catch (error) {
229+
core.setFailed("Failed to register task definition in ECS: " + error.message);
230+
core.debug("Task definition contents:");
231+
core.debug(JSON.stringify(taskDefContents, undefined, 4));
232+
throw(error);
233+
}
224234
const taskDefArn = registerResponse.taskDefinition.taskDefinitionArn;
225235
core.setOutput('task-definition-arn', taskDefArn);
226236

index.test.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const mockCodeDeployGetDeploymentGroup = jest.fn();
1515
const mockCodeDeployWaiter = jest.fn();
1616
jest.mock('aws-sdk', () => {
1717
return {
18+
config: {
19+
region: 'fake-region'
20+
},
1821
ECS: jest.fn(() => ({
1922
registerTaskDefinition: mockEcsRegisterTaskDef,
2023
updateService: mockEcsUpdateService,
@@ -158,6 +161,7 @@ describe('Deploy to ECS', () => {
158161
taskDefinition: 'task:def:arn'
159162
});
160163
expect(mockEcsWaiter).toHaveBeenCalledTimes(0);
164+
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");
161165
});
162166

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

300304
expect(mockEcsUpdateService).toHaveBeenCalledTimes(0);
301305
expect(mockEcsWaiter).toHaveBeenCalledTimes(0);
306+
307+
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");
302308
});
303309

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

810-
test('error is caught by core.setFailed', async () => {
816+
817+
test('error is caught if task def registration fails', async () => {
811818
mockEcsRegisterTaskDef.mockImplementation(() => {
812-
throw new Error();
819+
throw new Error("Could not parse");
813820
});
814821

815822
await run();
816823

817-
expect(core.setFailed).toBeCalled();
824+
expect(core.setFailed).toHaveBeenCalledTimes(2);
825+
expect(core.setFailed).toHaveBeenNthCalledWith(1, 'Failed to register task definition in ECS: Could not parse');
826+
expect(core.setFailed).toHaveBeenNthCalledWith(2, 'Could not parse');
818827
});
819828
});

0 commit comments

Comments
 (0)