Skip to content

Commit 6399ad6

Browse files
committed
fix: use propagateTags service value
1 parent ce8c673 commit 6399ad6

File tree

3 files changed

+61
-13
lines changed

3 files changed

+61
-13
lines changed

action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ inputs:
7474
description: "Determines whether to turn on Amazon ECS managed tags 'aws:ecs:serviceName' and 'aws:ecs:clusterName' for the tasks in the service."
7575
required: false
7676
propagate-tags:
77-
description: "Determines to propagate the tags from the 'SERVICE' to the task. Will default to 'NONE'."
77+
description: "Determines to propagate the tags from the 'SERVICE' to the task. Will default to service propagateTags value ('NONE' if not set at service creation)."
7878
required: false
7979
outputs:
8080
task-definition-arn:

index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ async function run() {
403403
if (enableECSManagedTagsInput !== '') {
404404
enableECSManagedTags = enableECSManagedTagsInput.toLowerCase() === 'true';
405405
}
406-
const propagateTags = core.getInput('propagate-tags', { required: false }) || 'NONE';
406+
let propagateTags = core.getInput('propagate-tags', { required: false }) || '';
407407

408408
// Register the task definition
409409
core.debug('Registering the task definition');
@@ -451,6 +451,11 @@ async function run() {
451451
if (serviceResponse.status != 'ACTIVE') {
452452
throw new Error(`Service is ${serviceResponse.status}`);
453453
}
454+
// set propagateTags to the current value if no input provided
455+
if (describeResponse.services[0].propagateTags != null && propagateTags === '') {
456+
propagateTags = describeResponse.services[0].propagateTags;
457+
core.debug(`Current service 'propagateTags' value '${describeResponse.services[0].propagateTags}' will be set to service`);
458+
}
454459

455460
if (!serviceResponse.deploymentController || !serviceResponse.deploymentController.type || serviceResponse.deploymentController.type === 'ECS') {
456461
// Service uses the 'ECS' deployment controller, so we can call UpdateService

index.test.js

+54-11
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ describe('Deploy to ECS', () => {
9696
() => Promise.resolve({
9797
failures: [],
9898
services: [{
99-
status: 'ACTIVE'
99+
status: 'ACTIVE'
100100
}]
101101
})
102102
);
@@ -187,7 +187,7 @@ describe('Deploy to ECS', () => {
187187
taskDefinition: 'task:def:arn',
188188
forceNewDeployment: false,
189189
enableECSManagedTags: null,
190-
propagateTags: 'NONE'
190+
propagateTags: ''
191191
});
192192
expect(waitUntilServicesStable).toHaveBeenCalledTimes(0);
193193
expect(core.info).toBeCalledWith("Deployment started. Watch this deployment's progress in the Amazon ECS console: https://fake-region.console.aws.amazon.com/ecs/v2/clusters/cluster-789/services/service-456/events?region=fake-region");
@@ -220,7 +220,7 @@ describe('Deploy to ECS', () => {
220220
taskDefinition: 'task:def:arn',
221221
forceNewDeployment: false,
222222
enableECSManagedTags: null,
223-
propagateTags: 'NONE'
223+
propagateTags: ''
224224
});
225225
expect(waitUntilServicesStable).toHaveBeenCalledTimes(0);
226226
expect(core.info).toBeCalledWith("Deployment started. Watch this deployment's progress in the Amazon ECS console: https://fake-region.console.aws.amazon.com/ecs/v2/clusters/cluster-789/services/service-456/events?region=fake-region");
@@ -955,7 +955,7 @@ describe('Deploy to ECS', () => {
955955
taskDefinition: 'task:def:arn',
956956
forceNewDeployment: false,
957957
enableECSManagedTags: null,
958-
propagateTags: 'NONE'
958+
propagateTags: ''
959959
});
960960
expect(waitUntilServicesStable).toHaveBeenNthCalledWith(
961961
1,
@@ -996,7 +996,7 @@ describe('Deploy to ECS', () => {
996996
taskDefinition: 'task:def:arn',
997997
forceNewDeployment: false,
998998
enableECSManagedTags: null,
999-
propagateTags: 'NONE'
999+
propagateTags: ''
10001000
});
10011001
expect(waitUntilServicesStable).toHaveBeenNthCalledWith(
10021002
1,
@@ -1037,7 +1037,7 @@ describe('Deploy to ECS', () => {
10371037
taskDefinition: 'task:def:arn',
10381038
forceNewDeployment: false,
10391039
enableECSManagedTags: null,
1040-
propagateTags: 'NONE'
1040+
propagateTags: ''
10411041
});
10421042
expect(waitUntilServicesStable).toHaveBeenNthCalledWith(
10431043
1,
@@ -1080,7 +1080,7 @@ describe('Deploy to ECS', () => {
10801080
taskDefinition: 'task:def:arn',
10811081
forceNewDeployment: true,
10821082
enableECSManagedTags: null,
1083-
propagateTags: 'NONE'
1083+
propagateTags: ''
10841084
});
10851085
});
10861086

@@ -1106,7 +1106,7 @@ describe('Deploy to ECS', () => {
11061106
taskDefinition: 'task:def:arn',
11071107
forceNewDeployment: false,
11081108
enableECSManagedTags: null,
1109-
propagateTags: 'NONE'
1109+
propagateTags: ''
11101110
});
11111111
});
11121112

@@ -1277,7 +1277,7 @@ describe('Deploy to ECS', () => {
12771277
taskDefinition: 'task:def:arn',
12781278
forceNewDeployment: false,
12791279
enableECSManagedTags: null,
1280-
propagateTags: 'NONE',
1280+
propagateTags: '',
12811281
});
12821282
expect(mockRunTask).toHaveBeenCalledWith({
12831283
startedBy: 'someJoe',
@@ -1618,7 +1618,7 @@ describe('Deploy to ECS', () => {
16181618
.mockReturnValueOnce('') // force-new-deployment
16191619
.mockReturnValueOnce('') // desired-count
16201620
.mockReturnValueOnce('true') // enable-ecs-managed-tags
1621-
.mockReturnValueOnce('SERVICE'); // propagate-tags
1621+
.mockReturnValueOnce('SERVICE'); // propagate-tags
16221622

16231623
await run();
16241624
expect(core.setFailed).toHaveBeenCalledTimes(0);
@@ -1650,9 +1650,52 @@ describe('Deploy to ECS', () => {
16501650
.mockReturnValueOnce('') // force-new-deployment
16511651
.mockReturnValueOnce('') // desired-count
16521652
.mockReturnValueOnce('false') // enable-ecs-managed-tags
1653-
.mockReturnValueOnce('SERVICE'); // propagate-tags
1653+
.mockReturnValueOnce('SERVICE'); // propagate-tags
1654+
1655+
await run();
1656+
expect(core.setFailed).toHaveBeenCalledTimes(0);
1657+
1658+
expect(mockEcsRegisterTaskDef).toHaveBeenNthCalledWith(1, { family: 'task-def-family' });
1659+
expect(core.setOutput).toHaveBeenNthCalledWith(1, 'task-definition-arn', 'task:def:arn');
1660+
expect(mockEcsDescribeServices).toHaveBeenNthCalledWith(1, {
1661+
cluster: 'cluster-789',
1662+
services: ['service-456']
1663+
});
1664+
expect(mockEcsUpdateService).toHaveBeenNthCalledWith(1, {
1665+
cluster: 'cluster-789',
1666+
service: 'service-456',
1667+
taskDefinition: 'task:def:arn',
1668+
forceNewDeployment: false,
1669+
enableECSManagedTags: false,
1670+
propagateTags: 'SERVICE'
1671+
});
1672+
});
1673+
1674+
test('set propagateTags value from service if no input provided', async () => {
1675+
mockEcsDescribeServices.mockImplementation(
1676+
() => Promise.resolve({
1677+
failures: [],
1678+
services: [{
1679+
status: 'ACTIVE',
1680+
propagateTags: 'SERVICE',
1681+
}]
1682+
})
1683+
);
1684+
1685+
core.getInput = jest
1686+
.fn()
1687+
.mockReturnValueOnce('task-definition.json') // task-definition
1688+
.mockReturnValueOnce('service-456') // service
1689+
.mockReturnValueOnce('cluster-789') // cluster
1690+
.mockReturnValueOnce('false') // wait-for-service-stability
1691+
.mockReturnValueOnce('') // wait-for-minutes
1692+
.mockReturnValueOnce('') // force-new-deployment
1693+
.mockReturnValueOnce('') // desired-count
1694+
.mockReturnValueOnce('false') // enable-ecs-managed-tags
1695+
.mockReturnValueOnce(''); // propagate-tags
16541696

16551697
await run();
1698+
16561699
expect(core.setFailed).toHaveBeenCalledTimes(0);
16571700

16581701
expect(mockEcsRegisterTaskDef).toHaveBeenNthCalledWith(1, { family: 'task-def-family' });

0 commit comments

Comments
 (0)