Skip to content

Commit 5209a7c

Browse files
authored
feat: retry e2e tests at the action level (#3012)
1 parent 1252db2 commit 5209a7c

File tree

2 files changed

+77
-38
lines changed

2 files changed

+77
-38
lines changed

.github/actions/run_with_e2e_account/action.yml

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ inputs:
2424
default: false
2525
cdk-lib-version:
2626
required: true
27+
retry_attempts:
28+
description: Number of retry attempts for the main script
29+
required: false
30+
default: '3'
31+
retry_delay:
32+
description: Delay between retry attempts in seconds
33+
required: false
34+
default: '30'
2735
runs:
2836
using: composite
2937
steps:
@@ -76,9 +84,53 @@ runs:
7684
with:
7785
role-to-assume: ${{ steps.selectE2EAccount.outputs.e2e_execution_role }}
7886
aws-region: ${{ steps.selectE2ERegion.outputs.selected_aws_region }}
79-
- name: Run script
80-
shell: ${{ inputs.shell }}
81-
run: ${{ inputs.run }}
87+
- name: Run script with retry
88+
shell: bash
89+
run: |
90+
set -e
91+
92+
# Set default shell if not provided
93+
SHELL_CMD="${{ inputs.shell }}"
94+
if [ -z "$SHELL_CMD" ]; then
95+
SHELL_CMD="bash"
96+
fi
97+
98+
# Retry logic
99+
RETRY_ATTEMPTS=${{ inputs.retry_attempts }}
100+
RETRY_DELAY=${{ inputs.retry_delay }}
101+
ATTEMPT=1
102+
103+
while [ $ATTEMPT -le $RETRY_ATTEMPTS ]; do
104+
echo "Attempt $ATTEMPT of $RETRY_ATTEMPTS"
105+
106+
if [ "$SHELL_CMD" = "bash" ]; then
107+
if bash -c '${{ inputs.run }}'; then
108+
echo "Script succeeded on attempt $ATTEMPT"
109+
exit 0
110+
fi
111+
elif [ "$SHELL_CMD" = "pwsh" ]; then
112+
if pwsh -c '${{ inputs.run }}'; then
113+
echo "Script succeeded on attempt $ATTEMPT"
114+
exit 0
115+
fi
116+
else
117+
# Default to bash for other shells
118+
if bash -c '${{ inputs.run }}'; then
119+
echo "Script succeeded on attempt $ATTEMPT"
120+
exit 0
121+
fi
122+
fi
123+
124+
if [ $ATTEMPT -lt $RETRY_ATTEMPTS ]; then
125+
echo "Script failed on attempt $ATTEMPT. Retrying in $RETRY_DELAY seconds..."
126+
sleep $RETRY_DELAY
127+
else
128+
echo "Script failed after $RETRY_ATTEMPTS attempts"
129+
exit 1
130+
fi
131+
132+
ATTEMPT=$((ATTEMPT + 1))
133+
done
82134
env:
83135
AWS_REGION: ${{ steps.selectE2ERegion.outputs.selected_aws_region }}
84136
AMPLIFY_BACKEND_TESTS_E2E_EXECUTION_ROLE_ARN: ${{ steps.selectE2EAccount.outputs.e2e_execution_role }}

.github/workflows/health_checks.yml

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -489,22 +489,16 @@ jobs:
489489
contents: read
490490
steps:
491491
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # version 4.1.4
492-
- name: Run e2e deployment tests with retry
493-
uses: nick-fields/retry@v3
494-
with:
495-
timeout_minutes: ${{ matrix.os == 'windows-2025' && 35 || 25 }}
496-
max_attempts: 3
497-
retry_wait_seconds: 30
498-
shell: bash
499-
command: |
500-
# Setup node and restore cache
501-
echo "Setting up Node.js and restoring cache..."
492+
- name: Run e2e deployment tests
493+
run: |
494+
# Setup node and restore cache
495+
echo "Setting up Node.js and restoring cache..."
502496
503-
# Run the e2e deployment tests using the action
504-
echo "Running e2e deployment tests..."
497+
# Run the e2e deployment tests using the action
498+
echo "Running e2e deployment tests..."
505499
506-
# This will be handled by the composite action call below
507-
exit 0
500+
# This will be handled by the composite action call below
501+
exit 0
508502
- name: Execute e2e deployment tests
509503
uses: ./.github/actions/run_with_e2e_account
510504
with:
@@ -559,16 +553,10 @@ jobs:
559553
steps:
560554
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # version 4.1.4
561555
- name: Run e2e sandbox tests with retry
562-
uses: nick-fields/retry@v3
563-
with:
564-
timeout_minutes: ${{ matrix.os == 'windows-2025' && 35 || 25 }}
565-
max_attempts: 3
566-
retry_wait_seconds: 30
567-
shell: bash
568-
command: |
569-
# This step will be handled by the composite action below
570-
echo "Preparing to run e2e sandbox tests with retry..."
571-
exit 0
556+
run: |
557+
# This step will be handled by the composite action below
558+
echo "Preparing to run e2e sandbox tests with retry..."
559+
exit 0
572560
- name: Execute e2e sandbox tests
573561
uses: ./.github/actions/run_with_e2e_account
574562
with:
@@ -606,7 +594,12 @@ jobs:
606594
cdk-lib-version: ${{ needs.resolve_inputs.outputs.cdk_lib_version }}
607595
- run: cd packages/cli && npm link
608596
- name: Run e2e notices tests
609-
run: npm run test:dir packages/integration-tests/lib/test-e2e/notices.test.js
597+
uses: nick-fields/retry@v3
598+
with:
599+
timeout_minutes: ${{ matrix.os == 'windows-2025' && 8 || 5 }}
600+
max_attempts: 3
601+
retry_wait_seconds: 30
602+
command: npm run test:dir packages/integration-tests/lib/test-e2e/notices.test.js
610603
e2e_backend_output:
611604
if: needs.do_include_e2e.outputs.run_e2e == 'true'
612605
runs-on: ubuntu-latest
@@ -690,16 +683,10 @@ jobs:
690683
- name: Checkout aws-amplify/amplify-backend repo
691684
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
692685
- name: Run e2e package manager tests with retry
693-
uses: nick-fields/retry@v3
694-
with:
695-
timeout_minutes: ${{ matrix.os == 'windows-2025' && 40 || 25 }}
696-
max_attempts: 3
697-
retry_wait_seconds: 30
698-
shell: bash
699-
command: |
700-
# This step will be handled by the composite action below
701-
echo "Preparing to run e2e package manager tests with retry..."
702-
exit 0
686+
run: |
687+
# This step will be handled by the composite action below
688+
echo "Preparing to run e2e package manager tests with retry..."
689+
exit 0
703690
- name: Execute e2e package manager tests
704691
uses: ./.github/actions/run_with_e2e_account
705692
with:

0 commit comments

Comments
 (0)