From 2907f16e6416c175ef42af4a721d09b61bbdd2b6 Mon Sep 17 00:00:00 2001 From: Jerome Wolff Date: Thu, 11 Jul 2024 21:07:47 +0200 Subject: [PATCH 1/4] Adding simple Test --- .github/workflows/test.yaml | 83 +++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..33096cc --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,83 @@ +--- +############### +## Run tests ## +############### + +# +# Documentation: +# https://help.github.com/en/articles/workflow-syntax-for-github-actions +# + +name: Test +on: + pull_request: + push: + branches: [ main ] + +########################## +# Prevent duplicate jobs # +########################## +concurrency: + group: ${{ github.repository }} + cancel-in-progress: false + +permissions: + id-token: write + contents: read + +############### +# Run the job # +############### +jobs: + self-test: + name: GHA Test + runs-on: ubuntu-latest + steps: + ############################ + # Checkout the source code # + ############################ + - name: Checkout + uses: actions/checkout@v4 + + ############################# + # Configure AWS credentials # + ############################# + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: arn:aws:iam::${{ vars.AWS_TESTING_ACCOUNT_ID }}:role/${{ vars.AWS_TESTING_ROLE }} + aws-region: ${{ vars.AWS_TESTING_REGION }} + mask-aws-account-id: false + + ###################### + # Test Action itself # + ###################### + - name: Test Action + uses: ./ + with: + # Pre created + cluster: github-gha + task-definition: arn:aws:ecs:${{ vars.AWS_TESTING_REGION }}:${{ vars.AWS_TESTING_ACCOUNT_ID }}:task-definition/github-gha-alpine + + assign-public-ip: 'ENABLED' + security-group-ids: | + sg-09a0ccb78d5be2a25 + subnet-ids: | + subnet-08bbfd6c53b0c1049 + subnet-0fef13a6bef01f61a + subnet-0a676289b4a27a7fa + + tail-logs: true + override-container: alpine + override-container-command: | + /bin/sh + -c + echo "Hello, World!" && \ + echo "$TEST_VAR" && \ + echo "Goodbye, World!" + override-container-environment: | + TEST_VAR=foobar123 + + task-wait-until-stopped: true + task-start-max-wait-time: 120 + task-stopped-max-wait-time: 300 From c5d7498c55dbca04a000f687a40bd395ba3b174b Mon Sep 17 00:00:00 2001 From: Jerome Wolff Date: Thu, 11 Jul 2024 21:46:15 +0200 Subject: [PATCH 2/4] add debugging and try catch --- dist/index.js | 37 ++++++++++++++++++++++--------------- index.js | 37 ++++++++++++++++++++++--------------- 2 files changed, 44 insertions(+), 30 deletions(-) diff --git a/dist/index.js b/dist/index.js index f6f990c..1984507 100644 --- a/dist/index.js +++ b/dist/index.js @@ -76520,12 +76520,16 @@ const main = async () => { core.setOutput('task-id', taskId); core.info(`Starting Task with ARN: ${taskArn}\n`); - // Wait for task to be in running state - core.debug(`Waiting for task to be in running state.`) - await waitUntilTasksRunning({ - client: ecs, - maxWaitTime: taskStartMaxWaitTime, - }, {cluster, tasks: [taskArn]}); + try { + core.debug(`Waiting for task to be in running state. Waiting for ${taskStartMaxWaitTime} seconds.`); + await waitUntilTasksRunning({ + client: ecs, + maxWaitTime: taskStartMaxWaitTime, + }, {cluster, tasks: [taskArn]}); + } catch (error) { + core.setFailed(`Task did not start successfully. Error: ${error.name}. State: ${error.state}.`); + return; + } // If taskWaitUntilStopped is false, we can bail out here because we can not tail logs or have any // information on the exitCodes or status of the task @@ -76587,15 +76591,18 @@ const main = async () => { } } - // Wait for Task to finish - core.debug(`Waiting for task to finish.`); - await waitUntilTasksStopped({ - client: ecs, - maxWaitTime: taskStoppedMaxWaitTime, - }, { - cluster, - tasks: [taskArn], - }); + try { + core.debug(`Waiting for task to finish. Waiting for ${taskStoppedMaxWaitTime} seconds.`); + await waitUntilTasksStopped({ + client: ecs, + maxWaitTime: taskStoppedMaxWaitTime, + }, { + cluster, + tasks: [taskArn], + }); + } catch (error) { + core.setFailed(`Task did not stop successfully. Error: ${error.name}. State: ${error.state}.`); + } // Close LogStream and store output if (logFilterStream !== null) { diff --git a/index.js b/index.js index e00ee5b..f7901dd 100644 --- a/index.js +++ b/index.js @@ -106,12 +106,16 @@ const main = async () => { core.setOutput('task-id', taskId); core.info(`Starting Task with ARN: ${taskArn}\n`); - // Wait for task to be in running state - core.debug(`Waiting for task to be in running state.`) - await waitUntilTasksRunning({ - client: ecs, - maxWaitTime: taskStartMaxWaitTime, - }, {cluster, tasks: [taskArn]}); + try { + core.debug(`Waiting for task to be in running state. Waiting for ${taskStartMaxWaitTime} seconds.`); + await waitUntilTasksRunning({ + client: ecs, + maxWaitTime: taskStartMaxWaitTime, + }, {cluster, tasks: [taskArn]}); + } catch (error) { + core.setFailed(`Task did not start successfully. Error: ${error.name}. State: ${error.state}.`); + return; + } // If taskWaitUntilStopped is false, we can bail out here because we can not tail logs or have any // information on the exitCodes or status of the task @@ -173,15 +177,18 @@ const main = async () => { } } - // Wait for Task to finish - core.debug(`Waiting for task to finish.`); - await waitUntilTasksStopped({ - client: ecs, - maxWaitTime: taskStoppedMaxWaitTime, - }, { - cluster, - tasks: [taskArn], - }); + try { + core.debug(`Waiting for task to finish. Waiting for ${taskStoppedMaxWaitTime} seconds.`); + await waitUntilTasksStopped({ + client: ecs, + maxWaitTime: taskStoppedMaxWaitTime, + }, { + cluster, + tasks: [taskArn], + }); + } catch (error) { + core.setFailed(`Task did not stop successfully. Error: ${error.name}. State: ${error.state}.`); + } // Close LogStream and store output if (logFilterStream !== null) { From 13eb53df0a912a1e1a0b0b1d595caba2bb033a5b Mon Sep 17 00:00:00 2001 From: Jerome Wolff Date: Thu, 11 Jul 2024 21:59:49 +0200 Subject: [PATCH 3/4] add debugging and try catch --- .github/workflows/test.yaml | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 33096cc..ee98f39 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -52,7 +52,7 @@ jobs: ###################### # Test Action itself # ###################### - - name: Test Action + - name: Test With Log Tail uses: ./ with: # Pre created @@ -74,10 +74,31 @@ jobs: -c echo "Hello, World!" && \ echo "$TEST_VAR" && \ - echo "Goodbye, World!" + x=0; while [ $x -le 10 ]; do echo "Sleeping..." && x=$(( $x + 1 )) && sleep 2; done override-container-environment: | TEST_VAR=foobar123 - task-wait-until-stopped: true - task-start-max-wait-time: 120 - task-stopped-max-wait-time: 300 + ###################### + # Test Action itself # + ###################### + - name: Test Failure Exit Code + uses: ./ + with: + # Pre created + cluster: github-gha + task-definition: arn:aws:ecs:${{ vars.AWS_TESTING_REGION }}:${{ vars.AWS_TESTING_ACCOUNT_ID }}:task-definition/github-gha-alpine + + assign-public-ip: 'ENABLED' + security-group-ids: | + sg-09a0ccb78d5be2a25 + subnet-ids: | + subnet-08bbfd6c53b0c1049 + subnet-0fef13a6bef01f61a + subnet-0a676289b4a27a7fa + + tail-logs: false + override-container: alpine + override-container-command: | + /bin/sh + -c + exit 1 From 608fb07669abbb9638912b33de723bfeee31ab39 Mon Sep 17 00:00:00 2001 From: Jerome Wolff Date: Thu, 11 Jul 2024 22:14:13 +0200 Subject: [PATCH 4/4] add debugging and try catch --- .github/workflows/test.yaml | 41 ++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index ee98f39..fd5e90c 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -30,7 +30,7 @@ permissions: ############### jobs: self-test: - name: GHA Test + name: Testing runs-on: ubuntu-latest steps: ############################ @@ -74,7 +74,7 @@ jobs: -c echo "Hello, World!" && \ echo "$TEST_VAR" && \ - x=0; while [ $x -le 10 ]; do echo "Sleeping..." && x=$(( $x + 1 )) && sleep 2; done + x=0; while [ $x -le 10 ]; do echo "Sleeping... $x" && x=$(( $x + 1 )) && sleep 2; done override-container-environment: | TEST_VAR=foobar123 @@ -82,6 +82,8 @@ jobs: # Test Action itself # ###################### - name: Test Failure Exit Code + id: expect-fail + continue-on-error: true uses: ./ with: # Pre created @@ -96,9 +98,42 @@ jobs: subnet-0fef13a6bef01f61a subnet-0a676289b4a27a7fa - tail-logs: false override-container: alpine override-container-command: | /bin/sh -c exit 1 + + ########################## + # Check expected failure # + ########################## + - name: Check previous for Failure + if: steps.expect-fail.outcome == 'success' + run: | + echo "Expected a failure. Outcome: ${{ steps.expect-fail.outcome }}" + exit 1 + + ###################### + # Test Action itself # + ###################### + - name: Test Fire and Forget + uses: ./ + with: + # Pre created + cluster: github-gha + task-definition: arn:aws:ecs:${{ vars.AWS_TESTING_REGION }}:${{ vars.AWS_TESTING_ACCOUNT_ID }}:task-definition/github-gha-alpine + + assign-public-ip: 'ENABLED' + security-group-ids: | + sg-09a0ccb78d5be2a25 + subnet-ids: | + subnet-08bbfd6c53b0c1049 + subnet-0fef13a6bef01f61a + subnet-0a676289b4a27a7fa + + task-wait-until-stopped: false + override-container: alpine + override-container-command: | + /bin/sh + -c + x=0; while [ $x -le 10 ]; do echo "Sleeping... $x" && x=$(( $x + 1 )) && sleep 10; done