@@ -96,7 +96,7 @@ async function run() {
96
96
97
97
// Get inputs
98
98
const taskDefinitionFile = core.getInput('task-definition', {
99
- required: true ,
99
+ required: false ,
100
100
});
101
101
const cluster = core.getInput('cluster', { required: false });
102
102
const count = core.getInput('count', { required: true });
@@ -123,32 +123,47 @@ async function run() {
123
123
const taskExecutionRoleArn = core.getInput('task-execution-role-override', {
124
124
required: false,
125
125
});
126
+ let taskDefRevisionArn = core.getInput('task-definition-revision-arn', {
127
+ required: false,
128
+ });
129
+ const containerOverridesString = core.getInput('container-overrides', {
130
+ required: false
131
+ });
126
132
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))
145
147
);
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}`);
149
165
}
150
- const taskDefArn = registerResponse.taskDefinition.taskDefinitionArn;
151
- core.setOutput('task-definition-arn', taskDefArn);
166
+ core.setOutput('task-definition-arn', taskDefRevisionArn);
152
167
153
168
const clusterName = cluster ? cluster : 'default';
154
169
@@ -157,7 +172,7 @@ async function run() {
157
172
*/
158
173
const runTaskRequest = {
159
174
cluster: clusterName,
160
- taskDefinition: taskDefArn ,
175
+ taskDefinition: taskDefRevisionArn ,
161
176
count: count,
162
177
startedBy: startedBy,
163
178
};
@@ -217,6 +232,11 @@ async function run() {
217
232
runTaskRequest.overrides.executionRoleArn = taskExecutionRoleArn;
218
233
}
219
234
235
+ if (containerOverridesString) {
236
+ runTaskRequest.overrides = runTaskRequest.overrides || {};
237
+ runTaskRequest.overrides.containerOverrides = JSON.parse(containerOverridesString);
238
+ }
239
+
220
240
core.debug(
221
241
`Running task with ${JSON.stringify(runTaskRequest)}`
222
242
);
0 commit comments