Skip to content

Commit

Permalink
fix: Use correct host for China region console
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
egyptianbman committed Feb 28, 2022
1 parent 802a3b6 commit 86d0773
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
5 changes: 4 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.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') {
Expand Down
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
21 changes: 17 additions & 4 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'});
Expand All @@ -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') {
Expand Down

0 comments on commit 86d0773

Please sign in to comment.