From 7580448167d03e2937b76555b79aa6b8a90d369a Mon Sep 17 00:00:00 2001 From: Sherlyn Saavedra Date: Wed, 31 Jul 2024 14:36:20 -0400 Subject: [PATCH] chnages made from comments and spacing fixing --- dist/index.js | 33 +++++++++++++-------------------- index.js | 33 +++++++++++++-------------------- 2 files changed, 26 insertions(+), 40 deletions(-) diff --git a/dist/index.js b/dist/index.js index 6dbfce06..ab03079a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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 }); @@ -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; @@ -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"); } @@ -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; diff --git a/index.js b/index.js index 29d759e2..eb8ba341 100644 --- a/index.js +++ b/index.js @@ -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 }); @@ -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; @@ -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"); } @@ -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;