From ae11a3781f609135555d09d52280324acc2dbd96 Mon Sep 17 00:00:00 2001 From: Bruno Ferreira Date: Tue, 28 Feb 2023 23:58:25 +0000 Subject: [PATCH] adds env-files input to the github action --- action.yml | 3 +++ dist/index.js | 20 +++++++++++++++++--- index.js | 20 +++++++++++++++++--- index.test.js | 15 ++++++++++++++- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/action.yml b/action.yml index e1a613c9..e22577a7 100644 --- a/action.yml +++ b/action.yml @@ -16,6 +16,9 @@ inputs: environment-variables: description: 'Variables to add to the container. Each variable is of the form KEY=value, you can specify multiple variables with multi-line YAML strings.' required: false + env-files: + description: 'S3 object arns to set env variables onto the container. You can specify multiple files with multi-line YAML strings.' + required: false outputs: task-definition: description: 'The path to the rendered task definition file' diff --git a/dist/index.js b/dist/index.js index b2f8fedd..d94ebaff 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1396,7 +1396,7 @@ async function run() { const imageURI = core.getInput('image', { required: true }); const environmentVariables = core.getInput('environment-variables', { required: false }); - + const envFiles = core.getInput('env-files', { required: false }); // Parse the task definition const taskDefPath = path.isAbsolute(taskDefinitionFile) ? taskDefinitionFile : @@ -1418,13 +1418,27 @@ async function run() { } containerDef.image = imageURI; - if (environmentVariables) { + if (envFiles) { + containerDef.environmentFiles = []; + envFiles.split('\n').forEach(function (line) { + // Trim whitespace + const trimmedLine = line.trim(); + // Skip if empty + if (trimmedLine.length === 0) { return; } + // Build object + const variable = { + value: trimmedLine, + type: "s3", + }; + containerDef.environmentFiles.push(variable); + }) + } + if (environmentVariables) { // If environment array is missing, create it if (!Array.isArray(containerDef.environment)) { containerDef.environment = []; } - // Get pairs by splitting on newlines environmentVariables.split('\n').forEach(function (line) { // Trim whitespace diff --git a/index.js b/index.js index 99bb717d..20d3b699 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,7 @@ async function run() { const imageURI = core.getInput('image', { required: true }); const environmentVariables = core.getInput('environment-variables', { required: false }); - + const envFiles = core.getInput('env-files', { required: false }); // Parse the task definition const taskDefPath = path.isAbsolute(taskDefinitionFile) ? taskDefinitionFile : @@ -33,13 +33,27 @@ async function run() { } containerDef.image = imageURI; - if (environmentVariables) { + if (envFiles) { + containerDef.environmentFiles = []; + envFiles.split('\n').forEach(function (line) { + // Trim whitespace + const trimmedLine = line.trim(); + // Skip if empty + if (trimmedLine.length === 0) { return; } + // Build object + const variable = { + value: trimmedLine, + type: "s3", + }; + containerDef.environmentFiles.push(variable); + }) + } + if (environmentVariables) { // If environment array is missing, create it if (!Array.isArray(containerDef.environment)) { containerDef.environment = []; } - // Get pairs by splitting on newlines environmentVariables.split('\n').forEach(function (line) { // Trim whitespace diff --git a/index.test.js b/index.test.js index 56c23296..2b38b084 100644 --- a/index.test.js +++ b/index.test.js @@ -27,7 +27,8 @@ describe('Render task definition', () => { .mockReturnValueOnce('task-definition.json') // task-definition .mockReturnValueOnce('web') // container-name .mockReturnValueOnce('nginx:latest') // image - .mockReturnValueOnce('FOO=bar\nHELLO=world'); // environment-variables + .mockReturnValueOnce('FOO=bar\nHELLO=world') // environment-variables + .mockReturnValueOnce('arn:aws:s3:::s3_bucket_name/envfile_object_name.env'); // env-files process.env = Object.assign(process.env, { GITHUB_WORKSPACE: __dirname }); process.env = Object.assign(process.env, { RUNNER_TEMP: '/home/runner/work/_temp' }); @@ -53,6 +54,12 @@ describe('Render task definition', () => { name: "DONT-TOUCH", value: "me" } + ], + environmentFiles: [ + { + value: "arn:aws:s3:::s3_bucket_name/envfile_object_name.env", + type: "s3" + } ] }, { @@ -92,6 +99,12 @@ describe('Render task definition', () => { name: "HELLO", value: "world" } + ], + environmentFiles: [ + { + value: "arn:aws:s3:::s3_bucket_name/envfile_object_name.env", + type: "s3" + } ] }, {