From db59b2620d6e1f997e9ee674d06cd2a3e604039f Mon Sep 17 00:00:00 2001 From: Anton Chaporgin Date: Thu, 9 Jun 2022 10:33:36 +0300 Subject: [PATCH 1/7] add -e to bash to support multiline commands #43 #53 --- dist/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 098970d..0179f23 100644 --- a/dist/index.js +++ b/dist/index.js @@ -357,7 +357,10 @@ function getExecutable() { } var executable; switch (SHELL) { - case "bash": + case "bash": { + executable = SHELL + "-e"; + break; + } case "python": case "pwsh": { executable = SHELL; @@ -1101,4 +1104,4 @@ function buildProcessTree (parentPid, tree, pidsToProcess, spawnChildProcessesLi /***/ }) -/******/ }); \ No newline at end of file +/******/ }); From 4d604b17762f7d107dfa379f93e8d2d2c002cc59 Mon Sep 17 00:00:00 2001 From: Anton Chaporgin Date: Mon, 20 Jun 2022 11:25:59 +0300 Subject: [PATCH 2/7] tests --- .github/workflows/ci_cd.yml | 72 +++++++++++++++++++++++++++++++++++++ src/index.ts | 6 +++- 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 1d298f5..17b2d67 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -36,6 +36,78 @@ jobs: command: node ./.github/scripts/log-examples.js timeout_minutes: 1 + - name: multi-line 2 commands non existent first command + id: multi_line_2_commands_non_existent_first_command + uses: ./ + with: + max_attempts: 2 + command: | + i-do-not-exist && \ + echo "bar" + - uses: nick-invision/assert-action@v1 + with: + expected: 3 + actual: ${{ steps.multi_line_2_commands_non_existent_first_command.outputs.total_attempts }} + - uses: nick-invision/assert-action@v1 + with: + expected: 'i-do-not-exist' + actual: ${{ steps.multi_line_2_commands_non_existent_first_command.outputs.exit_error }} + comparison: contains + - uses: nick-invision/assert-action@v1 + with: + expected: 'i-exist' + actual: ${{ steps.multi_line_2_commands_non_existent_first_command.outputs.exit_error }} + comparison: notContains + + - name: multi-line 2 commands happy path test + id: multi_line_2_commands_happy_path + uses: ./ + with: + max_attempts: 2 + command: | + echo "foo" && \ + echo "bar" + - uses: nick-invision/assert-action@v1 + with: + expected: 1 + actual: ${{ steps.multi_line_2_commands_happy_path.outputs.total_attempts }} + + - name: Conventional multi-line non existent first command + id: conventional_multi_line_non_existent_first_command + uses: ./ + with: + max_attempts: 2 + command: | + i-do-not-exist + echo "i-exist" + - uses: nick-invision/assert-action@v1 + with: + expected: 3 + actual: ${{ steps.conventional_multi_line_non_existent_second_command.outputs.total_attempts }} + - uses: nick-invision/assert-action@v1 + with: + expected: 'i-do-not-exist' + actual: ${{ steps.conventional_multi_line_non_existent_first_command.outputs.exit_error }} + comparison: contains + - uses: nick-invision/assert-action@v1 + with: + expected: 'i-exist' + actual: ${{ steps.conventional_multi_line_non_existent_first_command.outputs.exit_error }} + comparison: notContains + + - name: Conventional multi-line happy path test + id: conventional_multi_line_happy_path + uses: ./ + with: + max_attempts: 2 + command: | + echo "foo" + echo "bar" + - uses: nick-invision/assert-action@v1 + with: + expected: 0 + actual: ${{ steps.conventional_multi_line_happy_path.outputs.total_attempts }} + - name: sad-path (retry_wait_seconds) id: sad_path_wait_sec uses: ./ diff --git a/src/index.ts b/src/index.ts index b2fa2ff..caa5d06 100644 --- a/src/index.ts +++ b/src/index.ts @@ -83,7 +83,11 @@ function getExecutable(): string { let executable: string; switch (SHELL) { - case "bash": + case "bash": { + // -e to not ignore errors, but exit with non-zero code. + executable = SHELL + "-e"; + break; + } case "python": case "pwsh": { executable = SHELL; From 2d8f74008ea214abd1a5dce7d49e5ddb1b4136ef Mon Sep 17 00:00:00 2001 From: Anton Chaporgin Date: Mon, 20 Jun 2022 11:28:31 +0300 Subject: [PATCH 3/7] self review --- .github/workflows/ci_cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 17b2d67..35bfc67 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -43,7 +43,7 @@ jobs: max_attempts: 2 command: | i-do-not-exist && \ - echo "bar" + echo "i-exist" - uses: nick-invision/assert-action@v1 with: expected: 3 From 6e8635d64a4ad76696ea0d61399aed31ebca317a Mon Sep 17 00:00:00 2001 From: Anton Chaporgin Date: Mon, 20 Jun 2022 12:01:02 +0300 Subject: [PATCH 4/7] tests checked with act --- .github/workflows/ci_cd.yml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 35bfc67..2152377 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -39,18 +39,21 @@ jobs: - name: multi-line 2 commands non existent first command id: multi_line_2_commands_non_existent_first_command uses: ./ + continue-on-error: true with: + timeout_seconds: 1 max_attempts: 2 command: | i-do-not-exist && \ echo "i-exist" - uses: nick-invision/assert-action@v1 with: - expected: 3 + expected: 2 actual: ${{ steps.multi_line_2_commands_non_existent_first_command.outputs.total_attempts }} - uses: nick-invision/assert-action@v1 with: - expected: 'i-do-not-exist' + # The 127 error code indicates “command not found”. + expected: 'error code 127' actual: ${{ steps.multi_line_2_commands_non_existent_first_command.outputs.exit_error }} comparison: contains - uses: nick-invision/assert-action@v1 @@ -63,6 +66,7 @@ jobs: id: multi_line_2_commands_happy_path uses: ./ with: + timeout_seconds: 1 max_attempts: 2 command: | echo "foo" && \ @@ -75,18 +79,21 @@ jobs: - name: Conventional multi-line non existent first command id: conventional_multi_line_non_existent_first_command uses: ./ + continue-on-error: true with: + timeout_seconds: 1 max_attempts: 2 command: | i-do-not-exist echo "i-exist" - uses: nick-invision/assert-action@v1 with: - expected: 3 + expected: 2 actual: ${{ steps.conventional_multi_line_non_existent_second_command.outputs.total_attempts }} - uses: nick-invision/assert-action@v1 with: - expected: 'i-do-not-exist' + # The 127 error code indicates “command not found”. + expected: 'error code 127' actual: ${{ steps.conventional_multi_line_non_existent_first_command.outputs.exit_error }} comparison: contains - uses: nick-invision/assert-action@v1 @@ -99,13 +106,14 @@ jobs: id: conventional_multi_line_happy_path uses: ./ with: + timeout_seconds: 1 max_attempts: 2 command: | echo "foo" echo "bar" - uses: nick-invision/assert-action@v1 with: - expected: 0 + expected: 1 actual: ${{ steps.conventional_multi_line_happy_path.outputs.total_attempts }} - name: sad-path (retry_wait_seconds) From 772a768088751496abc9cae60cd5a1a6ae665ff5 Mon Sep 17 00:00:00 2001 From: Anton Chaporgin Date: Mon, 20 Jun 2022 14:04:06 +0300 Subject: [PATCH 5/7] tests checked with act --- .github/workflows/ci_cd.yml | 28 +++++++++++++++++++++------- dist/index.js | 4 ++-- src/index.ts | 6 +++--- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 2152377..a762ff9 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -36,11 +36,12 @@ jobs: command: node ./.github/scripts/log-examples.js timeout_minutes: 1 - - name: multi-line 2 commands non existent first command + - name: Multi-line 2 commands non existent first command id: multi_line_2_commands_non_existent_first_command uses: ./ continue-on-error: true with: + shell: bash timeout_seconds: 1 max_attempts: 2 command: | @@ -52,20 +53,26 @@ jobs: actual: ${{ steps.multi_line_2_commands_non_existent_first_command.outputs.total_attempts }} - uses: nick-invision/assert-action@v1 with: - # The 127 error code indicates “command not found”. - expected: 'error code 127' + expected: 'Final attempt failed' actual: ${{ steps.multi_line_2_commands_non_existent_first_command.outputs.exit_error }} comparison: contains + - uses: nick-invision/assert-action@v1 + with: + # The 127 error code indicates “command not found”. + expected: '127' + actual: ${{ steps.multi_line_2_commands_non_existent_first_command.outputs.exit_code }} + comparison: contains - uses: nick-invision/assert-action@v1 with: expected: 'i-exist' actual: ${{ steps.multi_line_2_commands_non_existent_first_command.outputs.exit_error }} comparison: notContains - - name: multi-line 2 commands happy path test + - name: Multi-line 2 commands happy path test id: multi_line_2_commands_happy_path uses: ./ with: + shell: bash timeout_seconds: 1 max_attempts: 2 command: | @@ -81,6 +88,7 @@ jobs: uses: ./ continue-on-error: true with: + shell: bash timeout_seconds: 1 max_attempts: 2 command: | @@ -89,13 +97,18 @@ jobs: - uses: nick-invision/assert-action@v1 with: expected: 2 - actual: ${{ steps.conventional_multi_line_non_existent_second_command.outputs.total_attempts }} + actual: ${{ steps.conventional_multi_line_non_existent_first_command.outputs.total_attempts }} - uses: nick-invision/assert-action@v1 with: - # The 127 error code indicates “command not found”. - expected: 'error code 127' + expected: 'Final attempt failed' actual: ${{ steps.conventional_multi_line_non_existent_first_command.outputs.exit_error }} comparison: contains + - uses: nick-invision/assert-action@v1 + with: + # The 127 error code indicates “command not found”. + expected: '127' + actual: ${{ steps.conventional_multi_line_non_existent_first_command.outputs.exit_code }} + comparison: contains - uses: nick-invision/assert-action@v1 with: expected: 'i-exist' @@ -106,6 +119,7 @@ jobs: id: conventional_multi_line_happy_path uses: ./ with: + shell: bash timeout_seconds: 1 max_attempts: 2 command: | diff --git a/dist/index.js b/dist/index.js index aeabe2f..d00d2d3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -708,12 +708,12 @@ function getTimeout() { } function getExecutable() { if (!SHELL) { - return OS === 'win32' ? 'powershell' : 'bash'; + return OS === 'win32' ? 'powershell' : 'bash -e '; } var executable; switch (SHELL) { case "bash": { - executable = SHELL + "-e"; + executable = "bash -e "; break; } case "python": diff --git a/src/index.ts b/src/index.ts index caa5d06..2152f6a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -78,14 +78,14 @@ function getTimeout(): number { function getExecutable(): string { if (!SHELL) { - return OS === 'win32' ? 'powershell' : 'bash'; + return OS === 'win32' ? 'powershell' : 'bash -e'; } let executable: string; switch (SHELL) { case "bash": { // -e to not ignore errors, but exit with non-zero code. - executable = SHELL + "-e"; + executable = "bash -e"; break; } case "python": @@ -135,7 +135,7 @@ async function runCmd(attempt: number) { exit = 0; done = false; - debug(`Running command ${COMMAND} on ${OS} using shell ${executable}`) + debug(`Running command ${COMMAND} on ${OS} using shell "${executable}"`) var child = attempt > 1 && NEW_COMMAND_ON_RETRY ? exec(NEW_COMMAND_ON_RETRY, { 'shell': executable }) : exec(COMMAND, { 'shell': executable }); From 676683ec601c7a2bd9f55ec97d46be216018d94f Mon Sep 17 00:00:00 2001 From: Nick Fields <46869826+nick-fields@users.noreply.github.com> Date: Mon, 20 Jun 2022 09:25:15 -0400 Subject: [PATCH 6/7] patch: move multiline tests to separate job --- .github/workflows/ci_cd.yml | 108 ++++++++++++++++++++++++++++++++++++ dist/index.js | 9 +-- 2 files changed, 113 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index a762ff9..3cab878 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -407,6 +407,114 @@ jobs: expected: failure actual: ${{ steps.wrong_shell.outcome }} + ci_multiline_tests: + name: Run Tests (Multiline) + if: startsWith(github.ref, 'refs/heads') + runs-on: ubuntu-18.04 + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Node.js + uses: actions/setup-node@v1 + with: + node-version: 16 + - name: Install dependencies + run: npm ci + + - name: Multi-line 2 commands non existent first command + id: multi_line_2_commands_non_existent_first_command + uses: ./ + continue-on-error: true + with: + shell: bash + timeout_seconds: 1 + max_attempts: 2 + command: | + i-do-not-exist && \ + echo "i-exist" + - uses: nick-invision/assert-action@v1 + with: + expected: 2 + actual: ${{ steps.multi_line_2_commands_non_existent_first_command.outputs.total_attempts }} + - uses: nick-invision/assert-action@v1 + with: + expected: 'Final attempt failed' + actual: ${{ steps.multi_line_2_commands_non_existent_first_command.outputs.exit_error }} + comparison: contains + - uses: nick-invision/assert-action@v1 + with: + # The 127 error code indicates “command not found”. + expected: '127' + actual: ${{ steps.multi_line_2_commands_non_existent_first_command.outputs.exit_code }} + comparison: contains + - uses: nick-invision/assert-action@v1 + with: + expected: 'i-exist' + actual: ${{ steps.multi_line_2_commands_non_existent_first_command.outputs.exit_error }} + comparison: notContains + + - name: Multi-line 2 commands happy path test + id: multi_line_2_commands_happy_path + uses: ./ + with: + shell: bash + timeout_seconds: 1 + max_attempts: 2 + command: | + echo "foo" && \ + echo "bar" + - uses: nick-invision/assert-action@v1 + with: + expected: 1 + actual: ${{ steps.multi_line_2_commands_happy_path.outputs.total_attempts }} + + - name: Conventional multi-line non existent first command + id: conventional_multi_line_non_existent_first_command + uses: ./ + continue-on-error: true + with: + shell: bash + timeout_seconds: 1 + max_attempts: 2 + command: | + i-do-not-exist + echo "i-exist" + - uses: nick-invision/assert-action@v1 + with: + expected: 2 + actual: ${{ steps.conventional_multi_line_non_existent_first_command.outputs.total_attempts }} + - uses: nick-invision/assert-action@v1 + with: + expected: 'Final attempt failed' + actual: ${{ steps.conventional_multi_line_non_existent_first_command.outputs.exit_error }} + comparison: contains + - uses: nick-invision/assert-action@v1 + with: + # The 127 error code indicates “command not found”. + expected: '127' + actual: ${{ steps.conventional_multi_line_non_existent_first_command.outputs.exit_code }} + comparison: contains + - uses: nick-invision/assert-action@v1 + with: + expected: 'i-exist' + actual: ${{ steps.conventional_multi_line_non_existent_first_command.outputs.exit_error }} + comparison: notContains + + - name: Conventional multi-line happy path test + id: conventional_multi_line_happy_path + uses: ./ + with: + shell: bash + timeout_seconds: 1 + max_attempts: 2 + command: | + echo "foo" + echo "bar" + - uses: nick-invision/assert-action@v1 + with: + expected: 1 + actual: ${{ steps.conventional_multi_line_happy_path.outputs.total_attempts }} + ci_windows: name: Run Windows Tests if: startsWith(github.ref, 'refs/heads') diff --git a/dist/index.js b/dist/index.js index d00d2d3..598b498 100644 --- a/dist/index.js +++ b/dist/index.js @@ -708,12 +708,13 @@ function getTimeout() { } function getExecutable() { if (!SHELL) { - return OS === 'win32' ? 'powershell' : 'bash -e '; + return OS === 'win32' ? 'powershell' : 'bash -e'; } var executable; switch (SHELL) { case "bash": { - executable = "bash -e "; + // -e to not ignore errors, but exit with non-zero code. + executable = "bash -e"; break; } case "python": @@ -779,7 +780,7 @@ function runCmd(attempt) { executable = getExecutable(); exit = 0; done = false; - core_1.debug("Running command " + COMMAND + " on " + OS + " using shell " + executable); + core_1.debug("Running command " + COMMAND + " on " + OS + " using shell \"" + executable + "\""); child = attempt > 1 && NEW_COMMAND_ON_RETRY ? child_process_1.exec(NEW_COMMAND_ON_RETRY, { 'shell': executable }) : child_process_1.exec(COMMAND, { 'shell': executable }); @@ -2593,4 +2594,4 @@ function buildProcessTree (parentPid, tree, pidsToProcess, spawnChildProcessesLi /***/ }) -/******/ }); +/******/ }); \ No newline at end of file From 8e4fe2b1911220cc0a5a2ce4c1d54ea3a841671a Mon Sep 17 00:00:00 2001 From: Nick Fields <46869826+nick-fields@users.noreply.github.com> Date: Mon, 20 Jun 2022 09:26:36 -0400 Subject: [PATCH 7/7] patch: remove original multiline tests from ci workflow --- .github/workflows/ci_cd.yml | 94 ------------------------------------- 1 file changed, 94 deletions(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 3cab878..835033c 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -36,100 +36,6 @@ jobs: command: node ./.github/scripts/log-examples.js timeout_minutes: 1 - - name: Multi-line 2 commands non existent first command - id: multi_line_2_commands_non_existent_first_command - uses: ./ - continue-on-error: true - with: - shell: bash - timeout_seconds: 1 - max_attempts: 2 - command: | - i-do-not-exist && \ - echo "i-exist" - - uses: nick-invision/assert-action@v1 - with: - expected: 2 - actual: ${{ steps.multi_line_2_commands_non_existent_first_command.outputs.total_attempts }} - - uses: nick-invision/assert-action@v1 - with: - expected: 'Final attempt failed' - actual: ${{ steps.multi_line_2_commands_non_existent_first_command.outputs.exit_error }} - comparison: contains - - uses: nick-invision/assert-action@v1 - with: - # The 127 error code indicates “command not found”. - expected: '127' - actual: ${{ steps.multi_line_2_commands_non_existent_first_command.outputs.exit_code }} - comparison: contains - - uses: nick-invision/assert-action@v1 - with: - expected: 'i-exist' - actual: ${{ steps.multi_line_2_commands_non_existent_first_command.outputs.exit_error }} - comparison: notContains - - - name: Multi-line 2 commands happy path test - id: multi_line_2_commands_happy_path - uses: ./ - with: - shell: bash - timeout_seconds: 1 - max_attempts: 2 - command: | - echo "foo" && \ - echo "bar" - - uses: nick-invision/assert-action@v1 - with: - expected: 1 - actual: ${{ steps.multi_line_2_commands_happy_path.outputs.total_attempts }} - - - name: Conventional multi-line non existent first command - id: conventional_multi_line_non_existent_first_command - uses: ./ - continue-on-error: true - with: - shell: bash - timeout_seconds: 1 - max_attempts: 2 - command: | - i-do-not-exist - echo "i-exist" - - uses: nick-invision/assert-action@v1 - with: - expected: 2 - actual: ${{ steps.conventional_multi_line_non_existent_first_command.outputs.total_attempts }} - - uses: nick-invision/assert-action@v1 - with: - expected: 'Final attempt failed' - actual: ${{ steps.conventional_multi_line_non_existent_first_command.outputs.exit_error }} - comparison: contains - - uses: nick-invision/assert-action@v1 - with: - # The 127 error code indicates “command not found”. - expected: '127' - actual: ${{ steps.conventional_multi_line_non_existent_first_command.outputs.exit_code }} - comparison: contains - - uses: nick-invision/assert-action@v1 - with: - expected: 'i-exist' - actual: ${{ steps.conventional_multi_line_non_existent_first_command.outputs.exit_error }} - comparison: notContains - - - name: Conventional multi-line happy path test - id: conventional_multi_line_happy_path - uses: ./ - with: - shell: bash - timeout_seconds: 1 - max_attempts: 2 - command: | - echo "foo" - echo "bar" - - uses: nick-invision/assert-action@v1 - with: - expected: 1 - actual: ${{ steps.conventional_multi_line_happy_path.outputs.total_attempts }} - - name: sad-path (retry_wait_seconds) id: sad_path_wait_sec uses: ./