Skip to content

Commit

Permalink
adds env-files input to the github action
Browse files Browse the repository at this point in the history
  • Loading branch information
bmbferreira committed Mar 1, 2023
1 parent ae0d5aa commit ae11a37
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
20 changes: 17 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand All @@ -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
Expand Down
20 changes: 17 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand All @@ -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
Expand Down
15 changes: 14 additions & 1 deletion index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand All @@ -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"
}
]
},
{
Expand Down Expand Up @@ -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"
}
]
},
{
Expand Down

0 comments on commit ae11a37

Please sign in to comment.