From 844931595da7ce62df99a028217d6cd387cd8f32 Mon Sep 17 00:00:00 2001 From: jichangjun Date: Tue, 3 Dec 2024 18:58:27 +0800 Subject: [PATCH] fix: do retry when git config failed --- .../linters/go/golangci_lint/golangci_lint.go | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/internal/linters/go/golangci_lint/golangci_lint.go b/internal/linters/go/golangci_lint/golangci_lint.go index 630e04da..e37fad62 100644 --- a/internal/linters/go/golangci_lint/golangci_lint.go +++ b/internal/linters/go/golangci_lint/golangci_lint.go @@ -120,13 +120,27 @@ func (g *gitConfigModifier) Modify(cfg *config.Linter) (*config.Linter, error) { args := []string{ fmt.Sprintf(` - # delete the old git config - %s - currentConfig=$(%s) - if ! echo "$currentConfig" | grep -q "${ACCESS_TOKEN}" || [ -z "$currentConfig" ]; then - # add the new git config - %s - fi + configure_git() { + # delete the old git config + %s || return 1 + currentConfig=$(%s) || return 1 + if ! echo "$currentConfig" | grep -q "${ACCESS_TOKEN}" || [ -z "$currentConfig" ]; then + # add the new git config + %s || return 1 + fi + return 0 + } + + max_retries=3 + retry_delay=1 + + for ((i=1; i<=max_retries; i++)); do + if configure_git; then + break + else + sleep $retry_delay + fi + done `, deleteOldConfigCmd, currentConfigCmd,