Skip to content

Commit

Permalink
chnages made from comments and spacing fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
shesaave authored and amazreech committed Aug 1, 2024
1 parent 9071bd0 commit 2564353
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 40 deletions.
33 changes: 13 additions & 20 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ async function run() {
const ecs = new ECS({
customUserAgent: 'amazon-ecs-render-task-definition-for-github-actions'
});

// Get inputs
const taskDefinition = core.getInput('task-definition', { required: false });
const taskDefinitionFile = core.getInput('task-definition', { required: false });
const containerName = core.getInput('container-name', { required: true });
const imageURI = core.getInput('image', { required: true });
const environmentVariables = core.getInput('environment-variables', { required: false });
Expand All @@ -27,7 +26,7 @@ async function run() {
const logConfigurationOptions = core.getInput("log-configuration-options", { required: false });
const dockerLabels = core.getInput('docker-labels', { required: false });
const command = core.getInput('command', { required: false });

//New inputs to fetch task definition
const taskDefinitionArn = core.getInput('task-definition-arn', { required: false }) || undefined;
const taskDefinitionFamily = core.getInput('task-definition-family', { required: false }) || undefined;
Expand All @@ -38,46 +37,42 @@ async function run() {
let describeTaskDefResponse;
let params;

if(taskDefinition){
if(taskDefinitionFile){
core.warning("Task definition file will be used.");
taskDefPath = path.isAbsolute(taskDefinition) ?
taskDefinition :
path.join(process.env.GITHUB_WORKSPACE, taskDefinition);
taskDefPath = path.isAbsolute(taskDefinitionFile) ?
taskDefinitionFile :
path.join(process.env.GITHUB_WORKSPACE, taskDefinitionFile);
if (!fs.existsSync(taskDefPath)) {
throw new Error(`Task definition file does not exist: ${taskDefinition}`);
throw new Error(`Task definition file does not exist: ${taskDefinitionFile}`);
}
taskDefContents = require(taskDefPath);
}

else if(taskDefinitionArn || taskDefinitionFamily || taskDefinitionRevision){
} else if(taskDefinitionArn || taskDefinitionFamily || taskDefinitionRevision){
if(taskDefinitionArn){
core.warning("The task definition arn will be used to fetch task definition");
params = {taskDefinition: taskDefinitionArn};
}else if(taskDefinitionFamily && taskDefinitionRevision && !taskDefinitionArn){
} else if(taskDefinitionFamily && taskDefinitionRevision){
core.warning("The latest revision of the task definition family will be provided");
params = {taskDefinition: `${taskDefinitionFamily}: ${taskDefinitionRevision}` };
}else if(taskDefinitionFamily && !taskDefinitionRevision && !taskDefinitionArn){
} else if(taskDefinitionFamily){
core.warning("The latest revision of the task definition family will be provided");
params = {taskDefinition: taskDefinitionFamily};
}
else if(taskDefinitionRevision && !taskDefinitionFamily && !taskDefinitionArn){
} else if(taskDefinitionRevision){
core.setFailed("You can't fetch task definition with just revision: Either use task definition, arn or family");
} else{
throw new Error('Either task definition ARN, family, or family and revision must be provided');
}

try{
describeTaskDefResponse = await ecs.describeTaskDefinition(params).promise().then(data =>{
return data.taskDefinition;
});
taskDefContents = require(describeTaskDefResponse.taskDefinition);
}catch (error) {
} catch (error) {
core.setFailed("Failed to describe task definition in ECS: " + error.message);
core.debug("Task definition contents:");
core.debug(JSON.stringify(taskDefContents, undefined, 4));
throw(error);
}
}else{
} else{
throw new Error("Either task definition, task definition arn or task definition family must be provided");
}

Expand Down Expand Up @@ -202,11 +197,9 @@ async function run() {
fs.writeFileSync(updatedTaskDefFile.name, newTaskDefContents);
core.setOutput('task-definition', updatedTaskDefFile.name);
}

catch (error) {
core.setFailed(error.message);
}

}

module.exports = run;
Expand Down
33 changes: 13 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ async function run() {
const ecs = new ECS({
customUserAgent: 'amazon-ecs-render-task-definition-for-github-actions'
});

// Get inputs
const taskDefinition = core.getInput('task-definition', { required: false });
const taskDefinitionFile = core.getInput('task-definition', { required: false });
const containerName = core.getInput('container-name', { required: true });
const imageURI = core.getInput('image', { required: true });
const environmentVariables = core.getInput('environment-variables', { required: false });
Expand All @@ -21,7 +20,7 @@ async function run() {
const logConfigurationOptions = core.getInput("log-configuration-options", { required: false });
const dockerLabels = core.getInput('docker-labels', { required: false });
const command = core.getInput('command', { required: false });

//New inputs to fetch task definition
const taskDefinitionArn = core.getInput('task-definition-arn', { required: false }) || undefined;
const taskDefinitionFamily = core.getInput('task-definition-family', { required: false }) || undefined;
Expand All @@ -32,46 +31,42 @@ async function run() {
let describeTaskDefResponse;
let params;

if(taskDefinition){
if(taskDefinitionFile){
core.warning("Task definition file will be used.");
taskDefPath = path.isAbsolute(taskDefinition) ?
taskDefinition :
path.join(process.env.GITHUB_WORKSPACE, taskDefinition);
taskDefPath = path.isAbsolute(taskDefinitionFile) ?
taskDefinitionFile :
path.join(process.env.GITHUB_WORKSPACE, taskDefinitionFile);
if (!fs.existsSync(taskDefPath)) {
throw new Error(`Task definition file does not exist: ${taskDefinition}`);
throw new Error(`Task definition file does not exist: ${taskDefinitionFile}`);
}
taskDefContents = require(taskDefPath);
}

else if(taskDefinitionArn || taskDefinitionFamily || taskDefinitionRevision){
} else if(taskDefinitionArn || taskDefinitionFamily || taskDefinitionRevision){
if(taskDefinitionArn){
core.warning("The task definition arn will be used to fetch task definition");
params = {taskDefinition: taskDefinitionArn};
}else if(taskDefinitionFamily && taskDefinitionRevision && !taskDefinitionArn){
} else if(taskDefinitionFamily && taskDefinitionRevision){
core.warning("The latest revision of the task definition family will be provided");
params = {taskDefinition: `${taskDefinitionFamily}: ${taskDefinitionRevision}` };
}else if(taskDefinitionFamily && !taskDefinitionRevision && !taskDefinitionArn){
} else if(taskDefinitionFamily){
core.warning("The latest revision of the task definition family will be provided");
params = {taskDefinition: taskDefinitionFamily};
}
else if(taskDefinitionRevision && !taskDefinitionFamily && !taskDefinitionArn){
} else if(taskDefinitionRevision){
core.setFailed("You can't fetch task definition with just revision: Either use task definition, arn or family");
} else{
throw new Error('Either task definition ARN, family, or family and revision must be provided');
}

try{
describeTaskDefResponse = await ecs.describeTaskDefinition(params).promise().then(data =>{
return data.taskDefinition;
});
taskDefContents = require(describeTaskDefResponse.taskDefinition);
}catch (error) {
} catch (error) {
core.setFailed("Failed to describe task definition in ECS: " + error.message);
core.debug("Task definition contents:");
core.debug(JSON.stringify(taskDefContents, undefined, 4));
throw(error);
}
}else{
} else{
throw new Error("Either task definition, task definition arn or task definition family must be provided");
}

Expand Down Expand Up @@ -196,11 +191,9 @@ async function run() {
fs.writeFileSync(updatedTaskDefFile.name, newTaskDefContents);
core.setOutput('task-definition', updatedTaskDefFile.name);
}

catch (error) {
core.setFailed(error.message);
}

}

module.exports = run;
Expand Down

0 comments on commit 2564353

Please sign in to comment.