diff --git a/.github/workflows/data.yml b/.github/workflows/data.yml index 04c4c70f..0d165560 100644 --- a/.github/workflows/data.yml +++ b/.github/workflows/data.yml @@ -33,27 +33,30 @@ jobs: git config --global user.name "github-actions[bot]" sudo timedatectl set-timezone "Asia/Shanghai" - - name: Delay - run: | - echo "Delaying for 1 minutes..." - sleep 60 - - name: Get Data run: | REPO="${{ github.server_url }}/${{ github.repository }}" PRERELEASE="true" TAG="" - if [ "${PRERELEASE}" = "true" ]; then - TAG="$(curl -skL --connect-timeout 10 "${REPO}/tags" | grep "/refs/tags/.*\.zip" | sed -E 's/.*\/refs\/tags\/(.*)\.zip.*$/\1/' | sort -rV | head -1)" - else - TAG="$(curl -skL --connect-timeout 10 -w "%{url_effective}" -o /dev/null "${REPO}/releases/latest" | awk -F'/' '{print $NF}')" - fi - [ "${TAG:0:1}" = "v" ] && TAG="${TAG:1}" - rm -f rr-${TAG}.img.zip - STATUS=$(curl -kL --connect-timeout 10 -w "%{http_code}" "${REPO}/releases/download/${TAG}/rr-${TAG}.img.zip" -o "rr-${TAG}.img.zip") - if [ $? -ne 0 ] || [ ${STATUS:-0} -ne 200 ]; then - echo "Download failed" + for i in {1..3}; do + if [ "${PRERELEASE}" = "true" ]; then + TAG="$(curl -skL --connect-timeout 10 "${REPO}/tags" | grep "/refs/tags/.*\.zip" | sed -E 's/.*\/refs\/tags\/(.*)\.zip.*$/\1/' | sort -rV | head -1)" + else + TAG="$(curl -skL --connect-timeout 10 -w "%{url_effective}" -o /dev/null "${REPO}/releases/latest" | awk -F'/' '{print $NF}')" + fi + [ "${TAG:0:1}" = "v" ] && TAG="${TAG:1}" + rm -f rr-${TAG}.img.zip + STATUS=$(curl -kL --connect-timeout 10 -w "%{http_code}" "${REPO}/releases/download/${TAG}/rr-${TAG}.img.zip" -o "rr-${TAG}.img.zip") + if [ $? -eq 0 ] && [ ${STATUS:-0} -eq 200 ]; then + break + else + echo "Download failed, retry $i/3" + sleep 60 + fi + done + if [ ! -f "rr-${TAG}.img.zip" ] || [ ${STATUS:-0} -ne 200 ]; then + echo "Download failed after 3 attempts" exit 1 fi