From 9a2a56f85665638f1af746ce82fd47c43f619a55 Mon Sep 17 00:00:00 2001 From: Phi Date: Thu, 14 Nov 2024 10:35:36 +0700 Subject: [PATCH] refactor: improve Go version extraction reliability in CI refactor: improve Go version extraction reliability in CI --- .github/workflows/update-version.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/update-version.yml b/.github/workflows/update-version.yml index 3ce10886..7c36a3c9 100644 --- a/.github/workflows/update-version.yml +++ b/.github/workflows/update-version.yml @@ -54,7 +54,21 @@ jobs: REPO="filecoin-project/lotus" LATEST_RELEASE=$(curl -s "https://api.github.com/repos/${REPO}/releases/latest" | jq -r .tag_name) GO_MOD_URL="https://raw.githubusercontent.com/${REPO}/${LATEST_RELEASE}/go.mod" - GO_VERSION=$(curl -s $GO_MOD_URL | grep -oP 'go \K[0-9]+\.[0-9]+(\.[0-9]+)?') + + # Download go.mod and check if successful + GO_MOD=$(curl -s $GO_MOD_URL) + if [ $? -ne 0 ]; then + echo "Error: Failed to download go.mod from $GO_MOD_URL" + exit 1 + fi + + GO_VERSION=$(echo "$GO_MOD" | awk '/^go / {print $2; exit}') + if [ -z "$GO_VERSION" ]; then + echo "Error: Could not find Go version in go.mod" + exit 1 + fi + + echo "Found Go version: $GO_VERSION" echo "current_go_version=$GO_VERSION" >> $GITHUB_OUTPUT - name: Update version.json