Skip to content

Commit 2b7155d

Browse files
committed
set enableECSManagedTags in updateEcsService and runTask when input is exist
1 parent 4640cea commit 2b7155d

File tree

3 files changed

+145
-17
lines changed

3 files changed

+145
-17
lines changed

dist/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,18 @@ async function tasksExitCode(ecs, clusterName, taskArns) {
139139
}
140140

141141
// Deploy to a service that uses the 'ECS' deployment controller
142-
async function updateEcsService(ecs, clusterName, service, taskDefArn, waitForService, waitForMinutes, forceNewDeployment, desiredCount, enableECSManagedTagsInput, propagateTags) {
142+
async function updateEcsService(ecs, clusterName, service, taskDefArn, waitForService, waitForMinutes, forceNewDeployment, desiredCount, enableECSManagedTags, propagateTags) {
143143
core.debug('Updating the service');
144144

145145
let params = {
146146
cluster: clusterName,
147147
service: service,
148148
taskDefinition: taskDefArn,
149149
forceNewDeployment: forceNewDeployment,
150+
enableECSManagedTags: enableECSManagedTags,
150151
propagateTags: propagateTags
151152
};
152153

153-
if (enableECSManagedTagsInput !== "") {
154-
params.enableECSManagedTags = enableECSManagedTagsInput.toLowerCase() === 'true';
155-
}
156-
157154
// Add the desiredCount property only if it is defined and a number.
158155
if (!isNaN(desiredCount) && desiredCount !== undefined) {
159156
params.desiredCount = desiredCount;
@@ -408,7 +405,10 @@ async function run() {
408405
const forceNewDeployment = forceNewDeployInput.toLowerCase() === 'true';
409406
const desiredCount = parseInt((core.getInput('desired-count', {required: false})));
410407
const enableECSManagedTagsInput = core.getInput('enable-ecs-managed-tags', { required: false }) || '';
411-
const enableECSManagedTags = enableECSManagedTagsInput.toLowerCase() === 'true';
408+
let enableECSManagedTags = null;
409+
if (enableECSManagedTagsInput !== '') {
410+
enableECSManagedTags = enableECSManagedTagsInput.toLowerCase() === 'true';
411+
}
412412
const propagateTags = core.getInput('propagate-tags', { required: false }) || 'NONE';
413413

414414
// Register the task definition
@@ -461,7 +461,7 @@ async function run() {
461461
if (!serviceResponse.deploymentController || !serviceResponse.deploymentController.type || serviceResponse.deploymentController.type === 'ECS') {
462462
// Service uses the 'ECS' deployment controller, so we can call UpdateService
463463
core.debug('Updating service...');
464-
await updateEcsService(ecs, clusterName, service, taskDefArn, waitForService, waitForMinutes, forceNewDeployment, desiredCount, enableECSManagedTagsInput, propagateTags);
464+
await updateEcsService(ecs, clusterName, service, taskDefArn, waitForService, waitForMinutes, forceNewDeployment, desiredCount, enableECSManagedTags, propagateTags);
465465

466466
} else if (serviceResponse.deploymentController.type === 'CODE_DEPLOY') {
467467
// Service uses CodeDeploy, so we should start a CodeDeploy deployment

index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,18 @@ async function tasksExitCode(ecs, clusterName, taskArns) {
133133
}
134134

135135
// Deploy to a service that uses the 'ECS' deployment controller
136-
async function updateEcsService(ecs, clusterName, service, taskDefArn, waitForService, waitForMinutes, forceNewDeployment, desiredCount, enableECSManagedTagsInput, propagateTags) {
136+
async function updateEcsService(ecs, clusterName, service, taskDefArn, waitForService, waitForMinutes, forceNewDeployment, desiredCount, enableECSManagedTags, propagateTags) {
137137
core.debug('Updating the service');
138138

139139
let params = {
140140
cluster: clusterName,
141141
service: service,
142142
taskDefinition: taskDefArn,
143143
forceNewDeployment: forceNewDeployment,
144+
enableECSManagedTags: enableECSManagedTags,
144145
propagateTags: propagateTags
145146
};
146147

147-
if (enableECSManagedTagsInput !== "") {
148-
params.enableECSManagedTags = enableECSManagedTagsInput.toLowerCase() === 'true';
149-
}
150-
151148
// Add the desiredCount property only if it is defined and a number.
152149
if (!isNaN(desiredCount) && desiredCount !== undefined) {
153150
params.desiredCount = desiredCount;
@@ -402,7 +399,10 @@ async function run() {
402399
const forceNewDeployment = forceNewDeployInput.toLowerCase() === 'true';
403400
const desiredCount = parseInt((core.getInput('desired-count', {required: false})));
404401
const enableECSManagedTagsInput = core.getInput('enable-ecs-managed-tags', { required: false }) || '';
405-
const enableECSManagedTags = enableECSManagedTagsInput.toLowerCase() === 'true';
402+
let enableECSManagedTags = null;
403+
if (enableECSManagedTagsInput !== '') {
404+
enableECSManagedTags = enableECSManagedTagsInput.toLowerCase() === 'true';
405+
}
406406
const propagateTags = core.getInput('propagate-tags', { required: false }) || 'NONE';
407407

408408
// Register the task definition
@@ -455,7 +455,7 @@ async function run() {
455455
if (!serviceResponse.deploymentController || !serviceResponse.deploymentController.type || serviceResponse.deploymentController.type === 'ECS') {
456456
// Service uses the 'ECS' deployment controller, so we can call UpdateService
457457
core.debug('Updating service...');
458-
await updateEcsService(ecs, clusterName, service, taskDefArn, waitForService, waitForMinutes, forceNewDeployment, desiredCount, enableECSManagedTagsInput, propagateTags);
458+
await updateEcsService(ecs, clusterName, service, taskDefArn, waitForService, waitForMinutes, forceNewDeployment, desiredCount, enableECSManagedTags, propagateTags);
459459

460460
} else if (serviceResponse.deploymentController.type === 'CODE_DEPLOY') {
461461
// Service uses CodeDeploy, so we should start a CodeDeploy deployment

index.test.js

Lines changed: 131 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ describe('Deploy to ECS', () => {
186186
service: 'service-456',
187187
taskDefinition: 'task:def:arn',
188188
forceNewDeployment: false,
189+
enableECSManagedTags: null,
189190
propagateTags: 'NONE'
190191
});
191192
expect(waitUntilServicesStable).toHaveBeenCalledTimes(0);
@@ -218,6 +219,7 @@ describe('Deploy to ECS', () => {
218219
service: 'service-456',
219220
taskDefinition: 'task:def:arn',
220221
forceNewDeployment: false,
222+
enableECSManagedTags: null,
221223
propagateTags: 'NONE'
222224
});
223225
expect(waitUntilServicesStable).toHaveBeenCalledTimes(0);
@@ -952,6 +954,7 @@ describe('Deploy to ECS', () => {
952954
service: 'service-456',
953955
taskDefinition: 'task:def:arn',
954956
forceNewDeployment: false,
957+
enableECSManagedTags: null,
955958
propagateTags: 'NONE'
956959
});
957960
expect(waitUntilServicesStable).toHaveBeenNthCalledWith(
@@ -992,6 +995,7 @@ describe('Deploy to ECS', () => {
992995
service: 'service-456',
993996
taskDefinition: 'task:def:arn',
994997
forceNewDeployment: false,
998+
enableECSManagedTags: null,
995999
propagateTags: 'NONE'
9961000
});
9971001
expect(waitUntilServicesStable).toHaveBeenNthCalledWith(
@@ -1032,6 +1036,7 @@ describe('Deploy to ECS', () => {
10321036
service: 'service-456',
10331037
taskDefinition: 'task:def:arn',
10341038
forceNewDeployment: false,
1039+
enableECSManagedTags: null,
10351040
propagateTags: 'NONE'
10361041
});
10371042
expect(waitUntilServicesStable).toHaveBeenNthCalledWith(
@@ -1074,6 +1079,7 @@ describe('Deploy to ECS', () => {
10741079
service: 'service-456',
10751080
taskDefinition: 'task:def:arn',
10761081
forceNewDeployment: true,
1082+
enableECSManagedTags: null,
10771083
propagateTags: 'NONE'
10781084
});
10791085
});
@@ -1099,6 +1105,7 @@ describe('Deploy to ECS', () => {
10991105
service: 'service-456',
11001106
taskDefinition: 'task:def:arn',
11011107
forceNewDeployment: false,
1108+
enableECSManagedTags: null,
11021109
propagateTags: 'NONE'
11031110
});
11041111
});
@@ -1145,7 +1152,7 @@ describe('Deploy to ECS', () => {
11451152
taskDefinition: 'task:def:arn',
11461153
overrides: {"containerOverrides": []},
11471154
networkConfiguration: null,
1148-
enableECSManagedTags: false,
1155+
enableECSManagedTags: null,
11491156
tags: []
11501157
});
11511158

@@ -1269,6 +1276,7 @@ describe('Deploy to ECS', () => {
12691276
service: 'service-456',
12701277
taskDefinition: 'task:def:arn',
12711278
forceNewDeployment: false,
1279+
enableECSManagedTags: null,
12721280
propagateTags: 'NONE',
12731281
});
12741282
expect(mockRunTask).toHaveBeenCalledWith({
@@ -1279,7 +1287,7 @@ describe('Deploy to ECS', () => {
12791287
launchType: 'EC2',
12801288
overrides: { containerOverrides: [{ name: 'someapp', command: 'somecmd' }] },
12811289
networkConfiguration: { awsvpcConfiguration: { subnets: ['a', 'b'], securityGroups: ['c', 'd'], assignPublicIp: "DISABLED" } },
1282-
enableECSManagedTags: false,
1290+
enableECSManagedTags: null,
12831291
tags: []
12841292
});
12851293
expect(core.setOutput).toHaveBeenNthCalledWith(2, 'run-task-arn', ["arn:aws:ecs:fake-region:account_id:task/arn"]);
@@ -1340,6 +1348,62 @@ describe('Deploy to ECS', () => {
13401348
launchType: 'EC2',
13411349
overrides: { containerOverrides: [] },
13421350
networkConfiguration: null,
1351+
enableECSManagedTags: null,
1352+
tags: []
1353+
});
1354+
});
1355+
1356+
test('run task with setting true to enableECSManagedTags', async () => {
1357+
core.getInput = jest
1358+
.fn()
1359+
.mockReturnValueOnce('task-definition.json') // task-definition
1360+
.mockReturnValueOnce('') // service
1361+
.mockReturnValueOnce('somecluster') // cluster
1362+
.mockReturnValueOnce('') // wait-for-service-stability
1363+
.mockReturnValueOnce('') // wait-for-minutes
1364+
.mockReturnValueOnce('') // force-new-deployment
1365+
.mockReturnValueOnce('') // desired-count
1366+
.mockReturnValueOnce('true') // enable-ecs-managed-tags
1367+
.mockReturnValueOnce('') // propagate-tags
1368+
.mockReturnValueOnce('true'); // run-task
1369+
1370+
await run();
1371+
expect(mockRunTask).toHaveBeenCalledWith({
1372+
startedBy: 'GitHub-Actions',
1373+
cluster: 'somecluster',
1374+
taskDefinition: 'task:def:arn',
1375+
capacityProviderStrategy: null,
1376+
launchType: 'FARGATE',
1377+
overrides: { containerOverrides: [] },
1378+
networkConfiguration: null,
1379+
enableECSManagedTags: true,
1380+
tags: []
1381+
});
1382+
});
1383+
1384+
test('run task with setting false to enableECSManagedTags', async () => {
1385+
core.getInput = jest
1386+
.fn()
1387+
.mockReturnValueOnce('task-definition.json') // task-definition
1388+
.mockReturnValueOnce('') // service
1389+
.mockReturnValueOnce('somecluster') // cluster
1390+
.mockReturnValueOnce('') // wait-for-service-stability
1391+
.mockReturnValueOnce('') // wait-for-minutes
1392+
.mockReturnValueOnce('') // force-new-deployment
1393+
.mockReturnValueOnce('') // desired-count
1394+
.mockReturnValueOnce('false') // enable-ecs-managed-tags
1395+
.mockReturnValueOnce('') // propagate-tags
1396+
.mockReturnValueOnce('true'); // run-task
1397+
1398+
await run();
1399+
expect(mockRunTask).toHaveBeenCalledWith({
1400+
startedBy: 'GitHub-Actions',
1401+
cluster: 'somecluster',
1402+
taskDefinition: 'task:def:arn',
1403+
capacityProviderStrategy: null,
1404+
launchType: 'FARGATE',
1405+
overrides: { containerOverrides: [] },
1406+
networkConfiguration: null,
13431407
enableECSManagedTags: false,
13441408
tags: []
13451409
});
@@ -1511,7 +1575,39 @@ describe('Deploy to ECS', () => {
15111575
expect(core.setFailed).toHaveBeenNthCalledWith(2, 'Could not parse');
15121576
});
15131577

1514-
test('propagate service tags from service and enable ecs managed tags', async () => {
1578+
test('propagate service tags from service', async () => {
1579+
core.getInput = jest
1580+
.fn()
1581+
.mockReturnValueOnce('task-definition.json') // task-definition
1582+
.mockReturnValueOnce('service-456') // service
1583+
.mockReturnValueOnce('cluster-789') // cluster
1584+
.mockReturnValueOnce('false') // wait-for-service-stability
1585+
.mockReturnValueOnce('') // wait-for-minutes
1586+
.mockReturnValueOnce('') // force-new-deployment
1587+
.mockReturnValueOnce('') // desired-count
1588+
.mockReturnValueOnce('') // enable-ecs-managed-tags
1589+
.mockReturnValueOnce('SERVICE'); // propagate-tags
1590+
1591+
await run();
1592+
expect(core.setFailed).toHaveBeenCalledTimes(0);
1593+
1594+
expect(mockEcsRegisterTaskDef).toHaveBeenNthCalledWith(1, { family: 'task-def-family' });
1595+
expect(core.setOutput).toHaveBeenNthCalledWith(1, 'task-definition-arn', 'task:def:arn');
1596+
expect(mockEcsDescribeServices).toHaveBeenNthCalledWith(1, {
1597+
cluster: 'cluster-789',
1598+
services: ['service-456']
1599+
});
1600+
expect(mockEcsUpdateService).toHaveBeenNthCalledWith(1, {
1601+
cluster: 'cluster-789',
1602+
service: 'service-456',
1603+
taskDefinition: 'task:def:arn',
1604+
forceNewDeployment: false,
1605+
enableECSManagedTags: null,
1606+
propagateTags: 'SERVICE'
1607+
});
1608+
});
1609+
1610+
test('update service with setting true to enableECSManagedTags', async () => {
15151611
core.getInput = jest
15161612
.fn()
15171613
.mockReturnValueOnce('task-definition.json') // task-definition
@@ -1542,4 +1638,36 @@ describe('Deploy to ECS', () => {
15421638
propagateTags: 'SERVICE'
15431639
});
15441640
});
1641+
1642+
test('update service with setting false to enableECSManagedTags', async () => {
1643+
core.getInput = jest
1644+
.fn()
1645+
.mockReturnValueOnce('task-definition.json') // task-definition
1646+
.mockReturnValueOnce('service-456') // service
1647+
.mockReturnValueOnce('cluster-789') // cluster
1648+
.mockReturnValueOnce('false') // wait-for-service-stability
1649+
.mockReturnValueOnce('') // wait-for-minutes
1650+
.mockReturnValueOnce('') // force-new-deployment
1651+
.mockReturnValueOnce('') // desired-count
1652+
.mockReturnValueOnce('false') // enable-ecs-managed-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+
});
15451673
});

0 commit comments

Comments
 (0)