Skip to content

Commit 6a428f3

Browse files
committed
chore(misc): gha improve retry logic and
Signed-off-by: Fluent Crafter <205769460+fluentcrafter@users.noreply.github.com>
1 parent 9af852a commit 6a428f3

2 files changed

Lines changed: 43 additions & 15 deletions

File tree

.github/actions/run-e2e-tests/action.yml

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ runs:
114114
path: ${{ github.workspace }}/${{ inputs.working-directory }}/tmp/artifacts
115115
merge-multiple: true
116116

117-
- name: Load Docker images from artifacts or pull develop for unchanged services
117+
- name: Load Docker images from artifacts
118118
shell: bash
119119
working-directory: ${{ inputs.working-directory }}
120120
env:
@@ -192,20 +192,12 @@ runs:
192192
working-directory: ${{ inputs.working-directory }}
193193
run: |
194194
set -euo pipefail
195-
timeout 10m bash -c '
196-
max=10
197-
attempt=0
198-
until make start-env-with-tracing-v2-ci CLEAN_PREVIOUS_ENV=false; do
199-
attempt=$((attempt + 1))
200-
if [ "$attempt" -ge "$max" ]; then
201-
echo "All $max attempts failed"
202-
exit 1
203-
fi
204-
echo "Attempt $attempt failed — cleaning up and retrying in 30 s..."
205-
make clean-environment || true
206-
sleep 30
207-
done
208-
'
195+
make retry \
196+
TARGET="start-env-with-tracing-v2-ci CLEAN_PREVIOUS_ENV=false" \
197+
RETRY_LIMIT=10 \
198+
RETRY_TIMEOUT=10m \
199+
RETRY_BACKOFF=30s \
200+
RETRY_CLEANUP_TARGET=clean-environment
209201
210202
- name: List docker containers/images
211203
if: ${{ always() && inputs.e2e-tests-containers-list == 'true' }}

Makefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,42 @@ staterecovery-replay-from-block:
109109
docker compose -f docker/compose-tracing-v2-staterecovery-extension.yml down zkbesu-shomei-sr shomei-sr
110110
L1_ROLLUP_CONTRACT_ADDRESS=$(L1_ROLLUP_CONTRACT_ADDRESS) STATERECOVERY_OVERRIDE_START_BLOCK_NUMBER=$(STATERECOVERY_OVERRIDE_START_BLOCK_NUMBER) docker compose -f docker/compose-tracing-v2-staterecovery-extension.yml up zkbesu-shomei-sr shomei-sr -d
111111

112+
# Retries TARGET up to RETRY_LIMIT times, aborting each attempt after
113+
# RETRY_TIMEOUT. Uses perl's alarm+exec instead of GNU coreutils `timeout`,
114+
# which isn't installed by default on macOS. Optionally runs
115+
# RETRY_CLEANUP_TARGET between failed attempts (e.g. to reset docker state).
116+
retry: RETRY_LIMIT:=5
117+
retry: RETRY_TIMEOUT:=10m
118+
retry: RETRY_BACKOFF:=10s
119+
retry:
120+
@if [ -z "$(TARGET)" ]; then \
121+
echo "Usage: make retry TARGET=<target> [RETRY_LIMIT=n] [RETRY_TIMEOUT=Xm] [RETRY_BACKOFF=Xs] [RETRY_CLEANUP_TARGET=<target>]"; \
122+
exit 1; \
123+
fi; \
124+
to_seconds() { \
125+
case "$$1" in \
126+
*h) echo $$(( $${1%h} * 3600 )) ;; \
127+
*m) echo $$(( $${1%m} * 60 )) ;; \
128+
*s) echo $${1%s} ;; \
129+
*) echo "$$1" ;; \
130+
esac; \
131+
}; \
132+
timeout_secs=$$(to_seconds $(RETRY_TIMEOUT)); \
133+
backoff_secs=$$(to_seconds $(RETRY_BACKOFF)); \
134+
attempt=1; \
135+
until perl -e 'alarm shift; exec @ARGV' $$timeout_secs $(MAKE) $(TARGET); do \
136+
if [ $$attempt -ge $(RETRY_LIMIT) ]; then \
137+
echo "Retry limit ($(RETRY_LIMIT)) reached for target: $(TARGET)"; \
138+
exit 1; \
139+
fi; \
140+
echo "Attempt $$attempt of '$(TARGET)' failed. Retrying in $(RETRY_BACKOFF)..."; \
141+
if [ -n "$(RETRY_CLEANUP_TARGET)" ]; then \
142+
$(MAKE) $(RETRY_CLEANUP_TARGET) || true; \
143+
fi; \
144+
attempt=$$((attempt + 1)); \
145+
sleep $$backoff_secs; \
146+
done
147+
112148
stop_pid:
113149
if [ -f $(PID_FILE) ]; then \
114150
kill `cat $(PID_FILE)`; \

0 commit comments

Comments
 (0)