From bfe35b582b00dd351d71abc7af67f91e493c0802 Mon Sep 17 00:00:00 2001 From: Beshoy Girgis Date: Tue, 2 Aug 2022 12:42:28 -0500 Subject: [PATCH] fix: Use correct host for China region console (#309) The China region's console is located at https://console.amazonaws.cn/. This PR checks the region configured and prints the correct console link since the global console doesn't auto redirect. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- dist/index.js | 5 ++++- index.js | 5 ++++- index.test.js | 21 +++++++++++++++++---- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/dist/index.js b/dist/index.js index cc5e3a10a..c4308d4b3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -277,7 +277,10 @@ async function updateEcsService(ecs, clusterName, service, taskDefArn, waitForSe taskDefinition: taskDefArn, forceNewDeployment: forceNewDeployment }).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`); + + const consoleHostname = aws.config.region.startsWith('cn') ? 'console.amazonaws.cn' : 'console.aws.amazon.com'; + + core.info(`Deployment started. Watch this deployment's progress in the Amazon ECS console: https://${consoleHostname}/ecs/home?region=${aws.config.region}#/clusters/${clusterName}/services/${service}/events`); // Wait for service stability if (waitForService && waitForService.toLowerCase() === 'true') { diff --git a/index.js b/index.js index 361d3e0a4..115438848 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,10 @@ async function updateEcsService(ecs, clusterName, service, taskDefArn, waitForSe taskDefinition: taskDefArn, forceNewDeployment: forceNewDeployment }).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`); + + const consoleHostname = aws.config.region.startsWith('cn') ? 'console.amazonaws.cn' : 'console.aws.amazon.com'; + + core.info(`Deployment started. Watch this deployment's progress in the Amazon ECS console: https://${consoleHostname}/ecs/home?region=${aws.config.region}#/clusters/${clusterName}/services/${service}/events`); // Wait for service stability if (waitForService && waitForService.toLowerCase() === 'true') { diff --git a/index.test.js b/index.test.js index adc35feb0..00ec3e36a 100644 --- a/index.test.js +++ b/index.test.js @@ -13,11 +13,13 @@ const mockEcsWaiter = jest.fn(); const mockCodeDeployCreateDeployment = jest.fn(); const mockCodeDeployGetDeploymentGroup = jest.fn(); const mockCodeDeployWaiter = jest.fn(); +let config = { + region: 'fake-region', +}; + jest.mock('aws-sdk', () => { return { - config: { - region: 'fake-region' - }, + config, ECS: jest.fn(() => ({ registerTaskDefinition: mockEcsRegisterTaskDef, updateService: mockEcsUpdateService, @@ -146,7 +148,7 @@ describe('Deploy to ECS', () => { }); }); - test('registers the task definition contents and updates the service', async () => { + test('registers the task definition contents and updates the service', async () => { await run(); expect(core.setFailed).toHaveBeenCalledTimes(0); expect(mockEcsRegisterTaskDef).toHaveBeenNthCalledWith(1, { family: 'task-def-family'}); @@ -165,6 +167,17 @@ describe('Deploy to ECS', () => { 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('prints Chinese console domain for cn regions', async () => { + const originalRegion = config.region; + config.region = 'cn-fake-region'; + await run(); + + expect(core.info).toBeCalledWith("Deployment started. Watch this deployment's progress in the Amazon ECS console: https://console.amazonaws.cn/ecs/home?region=cn-fake-region#/clusters/cluster-789/services/service-456/events"); + + // reset + config.region = originalRegion; + }); + test('cleans null keys out of the task definition contents', async () => { fs.readFileSync.mockImplementation((pathInput, encoding) => { if (encoding != 'utf8') {