INNER CODE UNIT · Go

getCurrentVersion

cri-o/cri-o · scripts/version_bump.go:51

func getCurrentVersion(versionFile string) (string, error) {
	// Matches both the legacy "const Version" declaration and the "var
	// Version" declaration used so downstream builds can override the
	// value via -ldflags -X.
	versionPattern := `(?:const|var)\s+Version\s+=\s+"(.+)"`

	// Read the content of the version file
	content, err := os.ReadFile(versionFile)
	if err != nil {
		return "", err
	}

	// Find the version string using regex
	re := regexp.MustCompile(versionPattern)

	matches := re.FindStringSubmatch(string(content))
	if len(matches) < 2 {
		return "", fmt.Errorf("unable to find version in %q", versionFile)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…