Skip to content

Commit

Permalink
Merge pull request #1008 from lorengordon/feat/adds-retry-macro
Browse files Browse the repository at this point in the history
  • Loading branch information
lorengordon authored Jul 2, 2024
2 parents dab5e94 + 7f1d20e commit cba5253
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ unexport download_hashicorp_release
match_pattern_in_file = $(or $(shell grep $(2) $(1) 2> /dev/null | grep -oE $(3) 2> /dev/null),$(error Could not match pattern from file: file=$(1), line=$(2), pattern=$(3)))
unexport match_pattern_in_file

# Macro to retry a command
# $(call retry,<max attempts>,<command>)
define retry
i=0; set +e; until [[ $$i -ge $(1) ]]; do sleep $$i; echo "$(2)"; ($(2)) && exit 0; ret=$$?; ((i++)); echo "Attempt ($$i) failed, trying until ($(1)) times"; done ; exit $$ret
endef
unexport retry

guard/env/%:
@ _="$(or $($*),$(error Make/environment variable '$*' not present))"

Expand Down

0 comments on commit cba5253

Please sign in to comment.