@@ -96,7 +96,7 @@ async function run() {
9696
9797 // Get inputs
9898 const taskDefinitionFile = core.getInput('task-definition', {
99- required: true ,
99+ required: false ,
100100 });
101101 const cluster = core.getInput('cluster', { required: false });
102102 const count = core.getInput('count', { required: true });
@@ -123,32 +123,47 @@ async function run() {
123123 const taskExecutionRoleArn = core.getInput('task-execution-role-override', {
124124 required: false,
125125 });
126+ let taskDefRevisionArn = core.getInput('task-definition-revision-arn', {
127+ required: false,
128+ });
129+ const containerOverridesString = core.getInput('container-overrides', {
130+ required: false
131+ });
126132
127- // Register the task definition
128- core.debug('Registering the task definition');
129- const taskDefPath = path.isAbsolute(taskDefinitionFile)
130- ? taskDefinitionFile
131- : path.join(process.env.GITHUB_WORKSPACE, taskDefinitionFile);
132- const fileContents = fs.readFileSync(taskDefPath, 'utf8');
133- const taskDefContents = removeIgnoredAttributes(
134- cleanNullKeys(yaml.parse(fileContents))
135- );
136-
137- let registerResponse;
138- try {
139- registerResponse = await ecs
140- .registerTaskDefinition(taskDefContents)
141- .promise();
142- } catch (error) {
143- core.setFailed(
144- 'Failed to register task definition in ECS: ' + error.message
133+ // Register the task definition if necessary - or use the passed in ARN
134+ if (!taskDefinitionFile && !taskDefRevisionArn) {
135+ const msg = "Invalid parameters: One of task-definition-file or task-definition-arn must be set";
136+ core.setFailed(msg);
137+ throw new Error(msg);
138+ }
139+ if (taskDefinitionFile) {
140+ core.debug(`Registering the task definition from file ${taskDefinitionFile}`);
141+ const taskDefPath = path.isAbsolute(taskDefinitionFile)
142+ ? taskDefinitionFile
143+ : path.join(process.env.GITHUB_WORKSPACE, taskDefinitionFile);
144+ const fileContents = fs.readFileSync(taskDefPath, 'utf8');
145+ const taskDefContents = removeIgnoredAttributes(
146+ cleanNullKeys(yaml.parse(fileContents))
145147 );
146- core.debug('Task definition contents:');
147- core.debug(JSON.stringify(taskDefContents, undefined, 2));
148- throw error;
148+
149+ let registerResponse;
150+ try {
151+ registerResponse = await ecs
152+ .registerTaskDefinition(taskDefContents)
153+ .promise();
154+ } catch (error) {
155+ core.setFailed(
156+ 'Failed to register task definition in ECS: ' + error.message
157+ );
158+ core.debug('Task definition contents:');
159+ core.debug(JSON.stringify(taskDefContents, undefined, 2));
160+ throw error;
161+ }
162+ taskDefRevisionArn = registerResponse.taskDefinition.taskDefinitionArn;
163+ } else {
164+ core.debug(`Using the passed task definition ARN ${taskDefRevisionArn}`);
149165 }
150- const taskDefArn = registerResponse.taskDefinition.taskDefinitionArn;
151- core.setOutput('task-definition-arn', taskDefArn);
166+ core.setOutput('task-definition-arn', taskDefRevisionArn);
152167
153168 const clusterName = cluster ? cluster : 'default';
154169
@@ -157,7 +172,7 @@ async function run() {
157172 */
158173 const runTaskRequest = {
159174 cluster: clusterName,
160- taskDefinition: taskDefArn ,
175+ taskDefinition: taskDefRevisionArn ,
161176 count: count,
162177 startedBy: startedBy,
163178 };
@@ -217,6 +232,11 @@ async function run() {
217232 runTaskRequest.overrides.executionRoleArn = taskExecutionRoleArn;
218233 }
219234
235+ if (containerOverridesString) {
236+ runTaskRequest.overrides = runTaskRequest.overrides || {};
237+ runTaskRequest.overrides.containerOverrides = JSON.parse(containerOverridesString);
238+ }
239+
220240 core.debug(
221241 `Running task with ${JSON.stringify(runTaskRequest)}`
222242 );
0 commit comments