Skip to content

fix: when no input enableECSManagedTagsInput, not include it to request params #669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,21 @@ async function tasksExitCode(ecs, clusterName, taskArns) {
}

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

let params = {
cluster: clusterName,
service: service,
taskDefinition: taskDefArn,
forceNewDeployment: forceNewDeployment,
enableECSManagedTags: enableECSManagedTags,
propagateTags: propagateTags
};

if (enableECSManagedTagsInput !== "") {
params.enableECSManagedTags = enableECSManagedTagsInput.toLowerCase() === 'true';
}

// Add the desiredCount property only if it is defined and a number.
if (!isNaN(desiredCount) && desiredCount !== undefined) {
params.desiredCount = desiredCount;
Expand Down Expand Up @@ -404,7 +407,7 @@ async function run() {
const forceNewDeployInput = core.getInput('force-new-deployment', { required: false }) || 'false';
const forceNewDeployment = forceNewDeployInput.toLowerCase() === 'true';
const desiredCount = parseInt((core.getInput('desired-count', {required: false})));
const enableECSManagedTagsInput = core.getInput('enable-ecs-managed-tags', { required: false }) || 'false';
const enableECSManagedTagsInput = core.getInput('enable-ecs-managed-tags', { required: false }) || '';
const enableECSManagedTags = enableECSManagedTagsInput.toLowerCase() === 'true';
const propagateTags = core.getInput('propagate-tags', { required: false }) || 'NONE';

Expand Down Expand Up @@ -458,7 +461,7 @@ async function run() {
if (!serviceResponse.deploymentController || !serviceResponse.deploymentController.type || serviceResponse.deploymentController.type === 'ECS') {
// Service uses the 'ECS' deployment controller, so we can call UpdateService
core.debug('Updating service...');
await updateEcsService(ecs, clusterName, service, taskDefArn, waitForService, waitForMinutes, forceNewDeployment, desiredCount, enableECSManagedTags, propagateTags);
await updateEcsService(ecs, clusterName, service, taskDefArn, waitForService, waitForMinutes, forceNewDeployment, desiredCount, enableECSManagedTagsInput, propagateTags);

} else if (serviceResponse.deploymentController.type === 'CODE_DEPLOY') {
// Service uses CodeDeploy, so we should start a CodeDeploy deployment
Expand Down
11 changes: 7 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,21 @@ async function tasksExitCode(ecs, clusterName, taskArns) {
}

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

let params = {
cluster: clusterName,
service: service,
taskDefinition: taskDefArn,
forceNewDeployment: forceNewDeployment,
enableECSManagedTags: enableECSManagedTags,
propagateTags: propagateTags
};

if (enableECSManagedTagsInput !== "") {
params.enableECSManagedTags = enableECSManagedTagsInput.toLowerCase() === 'true';
}

// Add the desiredCount property only if it is defined and a number.
if (!isNaN(desiredCount) && desiredCount !== undefined) {
params.desiredCount = desiredCount;
Expand Down Expand Up @@ -398,7 +401,7 @@ async function run() {
const forceNewDeployInput = core.getInput('force-new-deployment', { required: false }) || 'false';
const forceNewDeployment = forceNewDeployInput.toLowerCase() === 'true';
const desiredCount = parseInt((core.getInput('desired-count', {required: false})));
const enableECSManagedTagsInput = core.getInput('enable-ecs-managed-tags', { required: false }) || 'false';
const enableECSManagedTagsInput = core.getInput('enable-ecs-managed-tags', { required: false }) || '';
const enableECSManagedTags = enableECSManagedTagsInput.toLowerCase() === 'true';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still being used in runTask - can we include the changes for the enable ecs managed tags behavior in runTask as well to keep the behavior consistent?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact we can just move

  enableECSManagedTags = ""
  if (enableECSManagedTagsInput !== "") {
   enableECSManagedTags = enableECSManagedTagsInput.toLowerCase() === 'true';
  }

here and set the param in updateEcsService and runTask only if it's not set to ""

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when enableECSManagedTags = “”, ecs.updateService(params) get an error "SerializationException: Unexpected token received from parser"
so enableECSManagedTags is set to null by default

I actually checked with the following code in my aws

const ecs = new ECS();
  
let params = {
    cluster: "cluster-name",
    service: "servicepname",
    taskDefinition: "arn:aws:ecs:us-east-1:000000000:task-definition/some-task:1",
    enableECSManagedTags: "", // parse error
    // enableECSManagedTags: null, // ok
    desiredCount: 1,
};

await ecs.updateService(params);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great find!

const propagateTags = core.getInput('propagate-tags', { required: false }) || 'NONE';

Expand Down Expand Up @@ -452,7 +455,7 @@ async function run() {
if (!serviceResponse.deploymentController || !serviceResponse.deploymentController.type || serviceResponse.deploymentController.type === 'ECS') {
// Service uses the 'ECS' deployment controller, so we can call UpdateService
core.debug('Updating service...');
await updateEcsService(ecs, clusterName, service, taskDefArn, waitForService, waitForMinutes, forceNewDeployment, desiredCount, enableECSManagedTags, propagateTags);
await updateEcsService(ecs, clusterName, service, taskDefArn, waitForService, waitForMinutes, forceNewDeployment, desiredCount, enableECSManagedTagsInput, propagateTags);

} else if (serviceResponse.deploymentController.type === 'CODE_DEPLOY') {
// Service uses CodeDeploy, so we should start a CodeDeploy deployment
Expand Down
10 changes: 1 addition & 9 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ describe('Deploy to ECS', () => {
service: 'service-456',
taskDefinition: 'task:def:arn',
forceNewDeployment: false,
enableECSManagedTags: false,
propagateTags: 'NONE'
});
expect(waitUntilServicesStable).toHaveBeenCalledTimes(0);
Expand Down Expand Up @@ -216,7 +215,6 @@ describe('Deploy to ECS', () => {
service: 'service-456',
taskDefinition: 'task:def:arn',
forceNewDeployment: false,
enableECSManagedTags: false,
propagateTags: 'NONE'
});
expect(waitUntilServicesStable).toHaveBeenCalledTimes(0);
Expand Down Expand Up @@ -951,7 +949,6 @@ describe('Deploy to ECS', () => {
service: 'service-456',
taskDefinition: 'task:def:arn',
forceNewDeployment: false,
enableECSManagedTags: false,
propagateTags: 'NONE'
});
expect(waitUntilServicesStable).toHaveBeenNthCalledWith(
Expand Down Expand Up @@ -992,7 +989,6 @@ describe('Deploy to ECS', () => {
service: 'service-456',
taskDefinition: 'task:def:arn',
forceNewDeployment: false,
enableECSManagedTags: false,
propagateTags: 'NONE'
});
expect(waitUntilServicesStable).toHaveBeenNthCalledWith(
Expand Down Expand Up @@ -1033,7 +1029,6 @@ describe('Deploy to ECS', () => {
service: 'service-456',
taskDefinition: 'task:def:arn',
forceNewDeployment: false,
enableECSManagedTags: false,
propagateTags: 'NONE'
});
expect(waitUntilServicesStable).toHaveBeenNthCalledWith(
Expand Down Expand Up @@ -1076,7 +1071,6 @@ describe('Deploy to ECS', () => {
service: 'service-456',
taskDefinition: 'task:def:arn',
forceNewDeployment: true,
enableECSManagedTags: false,
propagateTags: 'NONE'
});
});
Expand All @@ -1102,7 +1096,6 @@ describe('Deploy to ECS', () => {
service: 'service-456',
taskDefinition: 'task:def:arn',
forceNewDeployment: false,
enableECSManagedTags: false,
propagateTags: 'NONE'
});
});
Expand Down Expand Up @@ -1273,7 +1266,6 @@ describe('Deploy to ECS', () => {
service: 'service-456',
taskDefinition: 'task:def:arn',
forceNewDeployment: false,
enableECSManagedTags: false,
propagateTags: 'NONE',
});
expect(mockRunTask).toHaveBeenCalledWith({
Expand Down Expand Up @@ -1547,4 +1539,4 @@ describe('Deploy to ECS', () => {
propagateTags: 'SERVICE'
});
});
});
});
Loading