From a4f82389be51777fb2bb6fb68e8cee138b3db345 Mon Sep 17 00:00:00 2001 From: kaanyagci Date: Mon, 12 Aug 2024 01:33:39 +0200 Subject: [PATCH] refactor: get the skaffold yaml version at compile time as failover Signed-off-by: kaanyagci --- Makefile | 2 +- internal/skaffold/skaffold.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 24c819a..baf30a0 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ create-out-directory: build: create-out-directory @echo "Building the binary..." - go build -o $(BINARY_PATH) main.go + go build -ldflags="-X 'skaffold.latestSkaffoldVersion=$(SKAFFOLD_YAML_VERSION)'" -o $(BINARY_PATH) main.go clean: @echo "Cleaning up..." diff --git a/internal/skaffold/skaffold.go b/internal/skaffold/skaffold.go index 9d0c745..7c24412 100644 --- a/internal/skaffold/skaffold.go +++ b/internal/skaffold/skaffold.go @@ -59,6 +59,8 @@ type GitHubFileContent struct { Encoding string `json:"encoding"` } +var latestSkaffoldVersion string + func getLatestSkaffoldYamlVersion() (string, error) { // GitHub API URL for the specific file url := "https://api.github.com/repos/GoogleContainerTools/skaffold/contents/docs-v2/content/en/docs/references/cli/_index.md" @@ -104,7 +106,7 @@ func InitializeSkaffold(skaffoldPath string) error { skaffoldYamlVersion, err := getLatestSkaffoldYamlVersion() if err != nil { log.Printf("Error while getting latest version from GitHub: %v", err) - return err + skaffoldYamlVersion = latestSkaffoldVersion } initialContent := SkaffoldConfig{ APIVersion: fmt.Sprintf("skaffold/%s", skaffoldYamlVersion),