From 19d1a35d6644b2cc5cec3120bbdbe16f26ef0de4 Mon Sep 17 00:00:00 2001 From: Beshoy Girgis Date: Mon, 28 Feb 2022 13:22:27 -0600 Subject: [PATCH] fix: Use correct host for China region console 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. --- 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 9df33ea7c..c1c401e2b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -201,7 +201,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.substr(0, 2) == '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..ba9511920 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.substr(0, 2) == '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') {