INNER CODE UNIT · Go

updateVersion

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

func updateVersion(versionFile, newVersion string) error {
	// Capture the "const"/"var" keyword and surrounding whitespace so the
	// replacement doesn't clobber a "var Version" declaration back into a
	// "const" one.
	versionPattern := `(const|var)(\s+Version\s+=\s+)".+"`

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

	// Replace the version string with the new version using regex
	re := regexp.MustCompile(versionPattern)
	newContent := re.ReplaceAll(content, fmt.Appendf(nil, `${1}${2}%q`, newVersion))

	// Write the updated content back to the version file
	if err := os.WriteFile(versionFile, newContent, 0o644); err != nil {

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…