From 47a2a29c71f78ba291da426f31d3e5be0d5540ec Mon Sep 17 00:00:00 2001 From: Jerome Wolff Date: Mon, 4 Dec 2023 16:34:19 +0100 Subject: [PATCH] Add new input "task-stopped-wait-for-max-attempts" to allow usage for long-running tasks --- README.md | 4 +- action.yml | 14 +++++++ dist/index.js | 13 ++++-- index.js | 13 ++++-- package-lock.json | 102 +++++++++++++++++++++++++++++++++------------- package.json | 2 + 6 files changed, 111 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 591fd40..0c298b6 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,9 @@ Will pass the following command to the container on the AWS ECS Fargate task: | cluster | Which ECS cluster to start the task in. | `false` | | | override-container | Will use `containerOverrides` to run a custom command on the container. If provided, `override-container-command` must also be set. | `false` | | | override-container-command | The command to run on the container if `override-container` is passed. | `false` | | +| override-container-environment | Add or override existing environment variables if `override-container` is passed. Provide one per line in key=value format. | `false` | | | 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 | +| task-stopped-wait-for-max-attempts | How many times to check if the task is stopped before failing the action. The delay between each check is 6 seconds. | `false` | 100 | @@ -111,5 +113,5 @@ Will pass the following command to the container on the AWS ECS Fargate task: ## Runs -This action is a `node16` action. +This action is a `node20` action. diff --git a/action.yml b/action.yml index 9770d30..dfa8fcb 100644 --- a/action.yml +++ b/action.yml @@ -11,39 +11,47 @@ inputs: description: >- The name or the ARN of the task definition to use for the task. required: true + subnet-ids: description: >- The list of subnet IDs for the task to use. If multiple they should be passed as multiline argument with one subnet ID per line. required: true + security-group-ids: description: >- List of security group IDs for the task. If multiple they should be passed as multiline argument with one subnet ID per line. required: true + assign-public-ip: description: >- Assign public a IP to the task. Options: `['ENABLED', 'DISABLED']` required: false default: DISABLED + cluster: description: >- Which ECS cluster to start the task in. required: false + override-container: description: >- Will use `containerOverrides` to run a custom command on the container. If provided, `override-container-command` must also be set. required: false + override-container-command: description: >- The command to run on the container if `override-container` is passed. required: false + override-container-environment: description: >- Add or override existing environment variables if `override-container` is passed. Provide one per line in key=value format. required: false + tail-logs: description: >- If set to true, will try to extract the logConfiguration for the first container in the task definition. If @@ -52,6 +60,12 @@ inputs: required: false default: 'true' + task-stopped-wait-for-max-attempts: + description: >- + How many times to check if the task is stopped before failing the action. The delay between each check is 6 seconds. + required: false + default: 100 + outputs: task-arn: description: 'The full ARN for the task that was ran.' diff --git a/dist/index.js b/dist/index.js index 416da12..0ce8c7b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -50316,6 +50316,7 @@ const main = async () => { const overrideContainer = core.getInput('override-container', {required: false}); const overrideContainerCommand = core.getMultilineInput('override-container-command', {required: false}); const overrideContainerEnvironment = core.getMultilineInput('override-container-environment', {required: false}); + const taskStoppedWaitForMaxAttempts = parseInt(core.getInput('task-stopped-wait-for-max-attempts', {required: false})); // Build Task parameters const taskRequestParams = { @@ -50351,7 +50352,7 @@ const main = async () => { // Check if not the last item in array if (arr.length - 1 !== i) { // Prepend the current item to the next item and set current item to null - arr[i+1] = arr[i] + arr[i+1] + arr[i + 1] = arr[i] + arr[i + 1] arr[i] = null } } @@ -50364,10 +50365,10 @@ const main = async () => { overrides.command = parsedCommand } - if(overrideContainerEnvironment.length) { + if (overrideContainerEnvironment.length) { core.debug(`overrideContainer and overrideContainerEnvironment has been specified. Overriding.`); overrides.environment = overrideContainerEnvironment.map(x => { - const parts= x.split(/=(.*)/) + const parts = x.split(/=(.*)/) return { name: parts[0], value: parts[1] @@ -50450,7 +50451,11 @@ const main = async () => { // Wait for Task to finish core.debug(`Waiting for task to finish.`); - await ecs.waitFor('tasksStopped', {cluster, tasks: [taskArn]}).promise(); + await ecs.waitFor('tasksStopped', { + cluster, + tasks: [taskArn], + $waiter: {delay: 6, maxAttempts: taskStoppedWaitForMaxAttempts}} + ).promise(); // Close LogStream and store output if (logFilterStream !== null) { diff --git a/index.js b/index.js index 3172a12..74c9671 100644 --- a/index.js +++ b/index.js @@ -21,6 +21,7 @@ const main = async () => { const overrideContainer = core.getInput('override-container', {required: false}); const overrideContainerCommand = core.getMultilineInput('override-container-command', {required: false}); const overrideContainerEnvironment = core.getMultilineInput('override-container-environment', {required: false}); + const taskStoppedWaitForMaxAttempts = parseInt(core.getInput('task-stopped-wait-for-max-attempts', {required: false})); // Build Task parameters const taskRequestParams = { @@ -56,7 +57,7 @@ const main = async () => { // Check if not the last item in array if (arr.length - 1 !== i) { // Prepend the current item to the next item and set current item to null - arr[i+1] = arr[i] + arr[i+1] + arr[i + 1] = arr[i] + arr[i + 1] arr[i] = null } } @@ -69,10 +70,10 @@ const main = async () => { overrides.command = parsedCommand } - if(overrideContainerEnvironment.length) { + if (overrideContainerEnvironment.length) { core.debug(`overrideContainer and overrideContainerEnvironment has been specified. Overriding.`); overrides.environment = overrideContainerEnvironment.map(x => { - const parts= x.split(/=(.*)/) + const parts = x.split(/=(.*)/) return { name: parts[0], value: parts[1] @@ -155,7 +156,11 @@ const main = async () => { // Wait for Task to finish core.debug(`Waiting for task to finish.`); - await ecs.waitFor('tasksStopped', {cluster, tasks: [taskArn]}).promise(); + await ecs.waitFor('tasksStopped', { + cluster, + tasks: [taskArn], + $waiter: {delay: 6, maxAttempts: taskStoppedWaitForMaxAttempts}} + ).promise(); // Close LogStream and store output if (logFilterStream !== null) { diff --git a/package-lock.json b/package-lock.json index 678924d..f19e0f7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ }, "devDependencies": { "@vercel/ncc": "^0.34.0", + "action-docs": "^1.2.0", "eslint": "^8.26.0", "jest": "^29.2.2" } @@ -60,12 +61,12 @@ } }, "node_modules/@babel/code-frame": { - "version": "7.22.13", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.13.tgz", - "integrity": "sha512-XktuhWlJ5g+3TJXc5upd9Ks1HutSArik6jf2eAjYFyIOf4ej3RN+184cZbzDvbPnuTJIUhPKKJE3cIsYTiAT3w==", + "version": "7.23.5", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.23.5.tgz", + "integrity": "sha512-CgH3s1a96LipHCmSUmYFPwY7MNx8C3avkq7i4Wl3cfa662ldtUe4VM1TPXX70pfmrlWTb6jLqTYrZyT2ZTJBgA==", "dev": true, "dependencies": { - "@babel/highlight": "^7.22.13", + "@babel/highlight": "^7.23.4", "chalk": "^2.4.2" }, "engines": { @@ -183,12 +184,12 @@ } }, "node_modules/@babel/generator": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.0.tgz", - "integrity": "sha512-lN85QRR+5IbYrMWM6Y4pE/noaQtg4pNiqeNGX60eqOfo6gtEj6uw/JagelB8vVztSd7R6M5n1+PQkDbHbBRU4g==", + "version": "7.23.5", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.5.tgz", + "integrity": "sha512-BPssCHrBD+0YrxviOa3QzpqwhNIXKEtOa2jQrm4FlmkC2apYgRnQcmPWiGZDlGxiNtltnUFolMe8497Esry+jA==", "dev": true, "dependencies": { - "@babel/types": "^7.23.0", + "@babel/types": "^7.23.5", "@jridgewell/gen-mapping": "^0.3.2", "@jridgewell/trace-mapping": "^0.3.17", "jsesc": "^2.5.1" @@ -312,9 +313,9 @@ } }, "node_modules/@babel/helper-string-parser": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz", - "integrity": "sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw==", + "version": "7.23.4", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.23.4.tgz", + "integrity": "sha512-803gmbQdqwdf4olxrX4AJyFBV/RTr3rSmOj0rKwesmzlfhYNDEs+/iOcznzpNWlJlIlTJC2QfPFcHB6DlzdVLQ==", "dev": true, "engines": { "node": ">=6.9.0" @@ -353,9 +354,9 @@ } }, "node_modules/@babel/highlight": { - "version": "7.22.20", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.22.20.tgz", - "integrity": "sha512-dkdMCN3py0+ksCgYmGG8jKeGA/8Tk+gJwSYYlFGxG5lmhfKNoAy004YpLxpS1W2J8m/EK2Ew+yOs9pVRwO89mg==", + "version": "7.23.4", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.23.4.tgz", + "integrity": "sha512-acGdbYSfp2WheJoJm/EBBBLh/ID8KDc64ISZ9DYtBmC8/Q204PZJLHyzeB5qMzJ5trcOkybd78M4x2KWsUq++A==", "dev": true, "dependencies": { "@babel/helper-validator-identifier": "^7.22.20", @@ -438,9 +439,9 @@ } }, "node_modules/@babel/parser": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.0.tgz", - "integrity": "sha512-vvPKKdMemU85V9WE/l5wZEmImpCtLqbnTvqDS2U1fJ96KrxoW7KrXhNsNCblQlg8Ck4b85yxdTyelsMUgFUXiw==", + "version": "7.23.5", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.5.tgz", + "integrity": "sha512-hOOqoiNXrmGdFbhgCzu6GiURxUgM27Xwd/aPuu8RfHEZPBzL1Z54okAHAQjXfcQNwvrlkAmAp4SlRTZ45vlthQ==", "dev": true, "bin": { "parser": "bin/babel-parser.js" @@ -641,19 +642,19 @@ } }, "node_modules/@babel/traverse": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.0.tgz", - "integrity": "sha512-t/QaEvyIoIkwzpiZ7aoSKK8kObQYeF7T2v+dazAYCb8SXtp58zEVkWW7zAnju8FNKNdr4ScAOEDmMItbyOmEYw==", + "version": "7.23.5", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.5.tgz", + "integrity": "sha512-czx7Xy5a6sapWWRx61m1Ke1Ra4vczu1mCTtJam5zRTBOonfdJ+S/B6HYmGYu3fJtr8GGET3si6IhgWVBhJ/m8w==", "dev": true, "dependencies": { - "@babel/code-frame": "^7.22.13", - "@babel/generator": "^7.23.0", + "@babel/code-frame": "^7.23.5", + "@babel/generator": "^7.23.5", "@babel/helper-environment-visitor": "^7.22.20", "@babel/helper-function-name": "^7.23.0", "@babel/helper-hoist-variables": "^7.22.5", "@babel/helper-split-export-declaration": "^7.22.6", - "@babel/parser": "^7.23.0", - "@babel/types": "^7.23.0", + "@babel/parser": "^7.23.5", + "@babel/types": "^7.23.5", "debug": "^4.1.0", "globals": "^11.1.0" }, @@ -671,12 +672,12 @@ } }, "node_modules/@babel/types": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.0.tgz", - "integrity": "sha512-0oIyUfKoI3mSqMvsxBdclDwxXKXAUA8v/apZbc+iSyARYou1o8ZGDxbUYyLFoW2arqS2jDGqJuZvv1d/io1axg==", + "version": "7.23.5", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.5.tgz", + "integrity": "sha512-ON5kSOJwVO6xXVRTvOI0eOnWe7VdUcIpsovGo9U/Br4Ie4UVFQTboO2cYnDhAGU6Fp+UxSiT+pMft0SMHfuq6w==", "dev": true, "dependencies": { - "@babel/helper-string-parser": "^7.22.5", + "@babel/helper-string-parser": "^7.23.4", "@babel/helper-validator-identifier": "^7.22.20", "to-fast-properties": "^2.0.0" }, @@ -1403,6 +1404,22 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, + "node_modules/action-docs": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/action-docs/-/action-docs-1.2.0.tgz", + "integrity": "sha512-qSyslpGvLfrUSmYqFthlCcSbUCkDe4sr4Q3/imnUFwaH5gdD94WO+bjY4AfYJB2iBf+iNs0JYHU8UpCpnjSodg==", + "dev": true, + "dependencies": { + "chalk": "^4.1.0", + "figlet": "^1.5.0", + "js-yaml": "^4.0.0", + "replace-in-file": "^6.3.5", + "yargs": "^17.6.0" + }, + "bin": { + "action-docs": "lib/cli.js" + } + }, "node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -2317,6 +2334,18 @@ "bser": "2.1.1" } }, + "node_modules/figlet": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/figlet/-/figlet-1.7.0.tgz", + "integrity": "sha512-gO8l3wvqo0V7wEFLXPbkX83b7MVjRrk1oRLfYlZXol8nEpb/ON9pcKLI4qpBv5YtOTfrINtqb7b40iYY2FTWFg==", + "dev": true, + "bin": { + "figlet": "bin/index.js" + }, + "engines": { + "node": ">= 0.4.0" + } + }, "node_modules/file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", @@ -4164,6 +4193,23 @@ "integrity": "sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==", "dev": true }, + "node_modules/replace-in-file": { + "version": "6.3.5", + "resolved": "https://registry.npmjs.org/replace-in-file/-/replace-in-file-6.3.5.tgz", + "integrity": "sha512-arB9d3ENdKva2fxRnSjwBEXfK1npgyci7ZZuwysgAp7ORjHSyxz6oqIjTEv8R0Ydl4Ll7uOAZXL4vbkhGIizCg==", + "dev": true, + "dependencies": { + "chalk": "^4.1.2", + "glob": "^7.2.0", + "yargs": "^17.2.1" + }, + "bin": { + "replace-in-file": "bin/cli.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", diff --git a/package.json b/package.json index 87b970b..49f1689 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "lint": "eslint **.js", "build": "ncc build index.js -o dist", + "update-readme": "action-docs -u", "test": "eslint **.js && jest --coverage" }, "repository": { @@ -29,6 +30,7 @@ }, "devDependencies": { "@vercel/ncc": "^0.34.0", + "action-docs": "^1.2.0", "eslint": "^8.26.0", "jest": "^29.2.2" }