Skip to content

Commit bfe35b5

Browse files
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>
1 parent 7b56beb commit bfe35b5

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

dist/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,10 @@ async function updateEcsService(ecs, clusterName, service, taskDefArn, waitForSe
277277
taskDefinition: taskDefArn,
278278
forceNewDeployment: forceNewDeployment
279279
}).promise();
280-
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`);
280+
281+
const consoleHostname = aws.config.region.startsWith('cn') ? 'console.amazonaws.cn' : 'console.aws.amazon.com';
282+
283+
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`);
281284

282285
// Wait for service stability
283286
if (waitForService && waitForService.toLowerCase() === 'true') {

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ async function updateEcsService(ecs, clusterName, service, taskDefArn, waitForSe
2929
taskDefinition: taskDefArn,
3030
forceNewDeployment: forceNewDeployment
3131
}).promise();
32-
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`);
32+
33+
const consoleHostname = aws.config.region.startsWith('cn') ? 'console.amazonaws.cn' : 'console.aws.amazon.com';
34+
35+
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`);
3336

3437
// Wait for service stability
3538
if (waitForService && waitForService.toLowerCase() === 'true') {

index.test.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ const mockEcsWaiter = jest.fn();
1313
const mockCodeDeployCreateDeployment = jest.fn();
1414
const mockCodeDeployGetDeploymentGroup = jest.fn();
1515
const mockCodeDeployWaiter = jest.fn();
16+
let config = {
17+
region: 'fake-region',
18+
};
19+
1620
jest.mock('aws-sdk', () => {
1721
return {
18-
config: {
19-
region: 'fake-region'
20-
},
22+
config,
2123
ECS: jest.fn(() => ({
2224
registerTaskDefinition: mockEcsRegisterTaskDef,
2325
updateService: mockEcsUpdateService,
@@ -146,7 +148,7 @@ describe('Deploy to ECS', () => {
146148
});
147149
});
148150

149-
test('registers the task definition contents and updates the service', async () => {
151+
test('registers the task definition contents and updates the service', async () => {
150152
await run();
151153
expect(core.setFailed).toHaveBeenCalledTimes(0);
152154
expect(mockEcsRegisterTaskDef).toHaveBeenNthCalledWith(1, { family: 'task-def-family'});
@@ -165,6 +167,17 @@ describe('Deploy to ECS', () => {
165167
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");
166168
});
167169

170+
test('prints Chinese console domain for cn regions', async () => {
171+
const originalRegion = config.region;
172+
config.region = 'cn-fake-region';
173+
await run();
174+
175+
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");
176+
177+
// reset
178+
config.region = originalRegion;
179+
});
180+
168181
test('cleans null keys out of the task definition contents', async () => {
169182
fs.readFileSync.mockImplementation((pathInput, encoding) => {
170183
if (encoding != 'utf8') {

0 commit comments

Comments
 (0)