Skip to content

Commit ada1fc2

Browse files
committed
Remove AWS SDKv2
1 parent f73c82a commit ada1fc2

File tree

5 files changed

+81
-64
lines changed

5 files changed

+81
-64
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Will pass the following command to the container on the AWS ECS Fargate task:
107107
| tail-logs | If set to true, will try to extract the logConfiguration for the first container in the task definition. If `override-container` is passed, it will extract the logConfiguration from that container. Tailing logs is only possible if the provided container uses the `awslogs` logDriver. | `false` | true |
108108
| task-wait-until-stopped | Whether to wait for the task to stop before finishing the action. If set to false, the action will finish immediately after the task reaches the `RUNNING` state (fire and forget). | `false` | true |
109109
| task-start-max-wait-time | How long to wait for the task to start (i.e. reach the `RUNNING` state) in seconds. If the task does not start within this time, the pipeline will fail. | `false` | 120 |
110-
| task-stopped-max-wait-time | How long to wait for the task to stop (i.e. reach the `STOPPED` state) in seconds. The task will not be canceled after this time, the pipeline will just be marked as failed. | `false` | 300 |
110+
| task-stop-max-wait-time | How long to wait for the task to stop (i.e. reach the `STOPPED` state) in seconds. The task will not be canceled after this time, the pipeline will just be marked as failed. | `false` | 300 |
111111
| task-check-state-delay | How long to wait between each AWS API call to check the current state of the task in seconds. This is useful to avoid running into AWS rate limits. **However**, setting this too high might cause the Action to miss the time-window your task is in the "RUNNING" state (if you task is very short lived) and can cause the action to fail. | `false` | 6 |
112112
<!-- action-docs-inputs -->
113113

action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ inputs:
7474
required: false
7575
default: 120
7676

77-
task-stopped-max-wait-time:
77+
task-stop-max-wait-time:
7878
description: >-
7979
How long to wait for the task to stop (i.e. reach the `STOPPED` state) in seconds. The task will not be canceled
8080
after this time, the pipeline will just be marked as failed.

dist/index.js

+31-30
Original file line numberDiff line numberDiff line change
@@ -56480,7 +56480,7 @@ const main = async () => {
5648056480
// Inputs: Waiters
5648156481
const taskWaitUntilStopped = core.getBooleanInput('task-wait-until-stopped', {required: false});
5648256482
const taskStartMaxWaitTime = parseInt(core.getInput('task-start-max-wait-time', {required: false}));
56483-
const taskStoppedMaxWaitTime = parseInt(core.getInput('task-stopped-max-wait-time', {required: false}));
56483+
const taskStopMaxWaitTime = parseInt(core.getInput('task-stop-max-wait-time', {required: false}));
5648456484
const taskCheckStateDelay = parseInt(core.getInput('task-check-state-delay', {required: false}));
5648556485

5648656486
// Build Task parameters
@@ -56558,31 +56558,11 @@ const main = async () => {
5655856558
core.setOutput('task-id', taskId);
5655956559
core.info(`Starting Task with ARN: ${taskArn}\n`);
5656056560

56561-
try {
56562-
core.debug(`Waiting for task to be in running state. Waiting for ${taskStartMaxWaitTime} seconds.`);
56563-
await waitUntilTasksRunning({
56564-
client: ecs,
56565-
maxWaitTime: taskStartMaxWaitTime,
56566-
maxDelay: taskCheckStateDelay,
56567-
minDelay: taskCheckStateDelay,
56568-
}, {cluster, tasks: [taskArn]});
56569-
} catch (error) {
56570-
core.setFailed(`Task did not start successfully. Error: ${error.name}. State: ${error.state}.`);
56571-
return;
56572-
}
56573-
56574-
// If taskWaitUntilStopped is false, we can bail out here because we can not tail logs or have any
56575-
// information on the exitCodes or status of the task
56576-
if (!taskWaitUntilStopped) {
56577-
core.info(`Task is running. Exiting without waiting for task to stop.`);
56578-
return;
56579-
}
56580-
56581-
// Get CWLogsClient
56561+
// Create CWLogsClient
5658256562
let CWLogClient = new CloudWatchLogsClient();
5658356563

56584-
// Only create logFilterStream if tailLogs is enabled, and we wait for the task to stop in the pipeline
56585-
if (tailLogs) {
56564+
// Only create StartLiveTailCommand if tailLogs is enabled, and we wait for the task to stop in the pipeline
56565+
if (tailLogs && taskWaitUntilStopped) {
5658656566
core.debug(`Logging enabled. Getting logConfiguration from TaskDefinition.`)
5658756567
let taskDef = await ecs.describeTaskDefinition({taskDefinition: taskDefinition});
5658856568
taskDef = taskDef.taskDefinition
@@ -56611,13 +56591,15 @@ const main = async () => {
5661156591
const logGroupIdentifier = `arn:aws:logs:${logRegion}:${accountId}:log-group:${logGroup}`;
5661256592
core.debug(`LogGroupARN for '${container.name}' is: '${logGroupIdentifier}'.`);
5661356593

56594+
// We will use the full logStreamName as a prefix filter. This way the SDK will not crash
56595+
// if the logStream does not exist yet.
5661456596
const logStreamName = [container.logConfiguration.options['awslogs-stream-prefix'], container.name, taskId].join('/')
5661556597

5661656598
// Start Live Tail
5661756599
try {
5661856600
const response = await CWLogClient.send(new StartLiveTailCommand({
5661956601
logGroupIdentifiers: [logGroupIdentifier],
56620-
logStreamNames: [logStreamName]
56602+
logStreamNamePrefixes: [logStreamName]
5662156603
}));
5662256604

5662356605
await handleCWResponseAsync(response);
@@ -56632,18 +56614,38 @@ const main = async () => {
5663256614
}
5663356615

5663456616
try {
56635-
core.debug(`Waiting for task to finish. Waiting for ${taskStoppedMaxWaitTime} seconds.`);
56617+
core.debug(`Waiting for task to be in running state. Waiting for ${taskStartMaxWaitTime} seconds.`);
56618+
await waitUntilTasksRunning({
56619+
client: ecs,
56620+
maxWaitTime: taskStartMaxWaitTime,
56621+
maxDelay: taskCheckStateDelay,
56622+
minDelay: taskCheckStateDelay,
56623+
}, {cluster, tasks: [taskArn]});
56624+
} catch (error) {
56625+
core.setFailed(`Task did not start successfully. Error: ${error.message}.`);
56626+
process.exit(1);
56627+
}
56628+
56629+
// If taskWaitUntilStopped is false, we can bail out here because we can not tail logs or have any
56630+
// information on the exitCodes or status of the task
56631+
if (!taskWaitUntilStopped) {
56632+
core.info(`Task is running. Exiting without waiting for task to stop.`);
56633+
process.exit(0);
56634+
}
56635+
56636+
try {
56637+
core.debug(`Waiting for task to finish. Waiting for ${taskStopMaxWaitTime} seconds.`);
5663656638
await waitUntilTasksStopped({
5663756639
client: ecs,
56638-
maxWaitTime: taskStoppedMaxWaitTime,
56640+
maxWaitTime: taskStopMaxWaitTime,
5663956641
maxDelay: taskCheckStateDelay,
5664056642
minDelay: taskCheckStateDelay,
5664156643
}, {
5664256644
cluster,
5664356645
tasks: [taskArn],
5664456646
});
5664556647
} catch (error) {
56646-
core.setFailed(`Task did not stop successfully. Error: ${error.name}. State: ${error.state}.`);
56648+
core.setFailed(`Task did not stop successfully. Error: ${error.message}.`);
5664756649
}
5664856650

5664956651
// Close LogStream and store output
@@ -56688,10 +56690,9 @@ async function handleCWResponseAsync(response) {
5668856690
}
5668956691
} catch (err) {
5669056692
// If we close the connection, we will get an error with message 'aborted' which we can ignore as it will
56691-
// just show as an error in the logs.
56693+
// just show as an error in the GHA logs.
5669256694
if (err.message === 'aborted') {
5669356695
core.debug("CWLiveTailSession aborted.");
56694-
5669556696
return;
5669656697
}
5669756698

index.js

+31-30
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const main = async () => {
3232
// Inputs: Waiters
3333
const taskWaitUntilStopped = core.getBooleanInput('task-wait-until-stopped', {required: false});
3434
const taskStartMaxWaitTime = parseInt(core.getInput('task-start-max-wait-time', {required: false}));
35-
const taskStoppedMaxWaitTime = parseInt(core.getInput('task-stopped-max-wait-time', {required: false}));
35+
const taskStopMaxWaitTime = parseInt(core.getInput('task-stop-max-wait-time', {required: false}));
3636
const taskCheckStateDelay = parseInt(core.getInput('task-check-state-delay', {required: false}));
3737

3838
// Build Task parameters
@@ -110,31 +110,11 @@ const main = async () => {
110110
core.setOutput('task-id', taskId);
111111
core.info(`Starting Task with ARN: ${taskArn}\n`);
112112

113-
try {
114-
core.debug(`Waiting for task to be in running state. Waiting for ${taskStartMaxWaitTime} seconds.`);
115-
await waitUntilTasksRunning({
116-
client: ecs,
117-
maxWaitTime: taskStartMaxWaitTime,
118-
maxDelay: taskCheckStateDelay,
119-
minDelay: taskCheckStateDelay,
120-
}, {cluster, tasks: [taskArn]});
121-
} catch (error) {
122-
core.setFailed(`Task did not start successfully. Error: ${error.name}. State: ${error.state}.`);
123-
return;
124-
}
125-
126-
// If taskWaitUntilStopped is false, we can bail out here because we can not tail logs or have any
127-
// information on the exitCodes or status of the task
128-
if (!taskWaitUntilStopped) {
129-
core.info(`Task is running. Exiting without waiting for task to stop.`);
130-
return;
131-
}
132-
133-
// Get CWLogsClient
113+
// Create CWLogsClient
134114
let CWLogClient = new CloudWatchLogsClient();
135115

136-
// Only create logFilterStream if tailLogs is enabled, and we wait for the task to stop in the pipeline
137-
if (tailLogs) {
116+
// Only create StartLiveTailCommand if tailLogs is enabled, and we wait for the task to stop in the pipeline
117+
if (tailLogs && taskWaitUntilStopped) {
138118
core.debug(`Logging enabled. Getting logConfiguration from TaskDefinition.`)
139119
let taskDef = await ecs.describeTaskDefinition({taskDefinition: taskDefinition});
140120
taskDef = taskDef.taskDefinition
@@ -163,13 +143,15 @@ const main = async () => {
163143
const logGroupIdentifier = `arn:aws:logs:${logRegion}:${accountId}:log-group:${logGroup}`;
164144
core.debug(`LogGroupARN for '${container.name}' is: '${logGroupIdentifier}'.`);
165145

146+
// We will use the full logStreamName as a prefix filter. This way the SDK will not crash
147+
// if the logStream does not exist yet.
166148
const logStreamName = [container.logConfiguration.options['awslogs-stream-prefix'], container.name, taskId].join('/')
167149

168150
// Start Live Tail
169151
try {
170152
const response = await CWLogClient.send(new StartLiveTailCommand({
171153
logGroupIdentifiers: [logGroupIdentifier],
172-
logStreamNames: [logStreamName]
154+
logStreamNamePrefixes: [logStreamName]
173155
}));
174156

175157
await handleCWResponseAsync(response);
@@ -184,18 +166,38 @@ const main = async () => {
184166
}
185167

186168
try {
187-
core.debug(`Waiting for task to finish. Waiting for ${taskStoppedMaxWaitTime} seconds.`);
169+
core.debug(`Waiting for task to be in running state. Waiting for ${taskStartMaxWaitTime} seconds.`);
170+
await waitUntilTasksRunning({
171+
client: ecs,
172+
maxWaitTime: taskStartMaxWaitTime,
173+
maxDelay: taskCheckStateDelay,
174+
minDelay: taskCheckStateDelay,
175+
}, {cluster, tasks: [taskArn]});
176+
} catch (error) {
177+
core.setFailed(`Task did not start successfully. Error: ${error.message}.`);
178+
process.exit(1);
179+
}
180+
181+
// If taskWaitUntilStopped is false, we can bail out here because we can not tail logs or have any
182+
// information on the exitCodes or status of the task
183+
if (!taskWaitUntilStopped) {
184+
core.info(`Task is running. Exiting without waiting for task to stop.`);
185+
process.exit(0);
186+
}
187+
188+
try {
189+
core.debug(`Waiting for task to finish. Waiting for ${taskStopMaxWaitTime} seconds.`);
188190
await waitUntilTasksStopped({
189191
client: ecs,
190-
maxWaitTime: taskStoppedMaxWaitTime,
192+
maxWaitTime: taskStopMaxWaitTime,
191193
maxDelay: taskCheckStateDelay,
192194
minDelay: taskCheckStateDelay,
193195
}, {
194196
cluster,
195197
tasks: [taskArn],
196198
});
197199
} catch (error) {
198-
core.setFailed(`Task did not stop successfully. Error: ${error.name}. State: ${error.state}.`);
200+
core.setFailed(`Task did not stop successfully. Error: ${error.message}.`);
199201
}
200202

201203
// Close LogStream and store output
@@ -240,10 +242,9 @@ async function handleCWResponseAsync(response) {
240242
}
241243
} catch (err) {
242244
// If we close the connection, we will get an error with message 'aborted' which we can ignore as it will
243-
// just show as an error in the logs.
245+
// just show as an error in the GHA logs.
244246
if (err.message === 'aborted') {
245247
core.debug("CWLiveTailSession aborted.");
246-
247248
return;
248249
}
249250

package-lock.json

+17-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)