INNER CODE UNIT · Go

updateFiles

projectcontour/contour · hack/actions/bump-go-version/main.go:139

func updateFiles(version, hash string) {
	ver := strings.TrimPrefix(version, "go")
	buildImageRegexp := regexp.MustCompile(`(BUILD_BASE_IMAGE\s*\?=\s*golang:)[0-9.]+(@sha256:[a-f0-9]{64})?`)
	goVersionRegexp := regexp.MustCompile(`(GO_VERSION:\s*)[0-9.]+`)

	for _, file := range filesToPatch {
		content, err := os.ReadFile(file)
		if err != nil {
			log.WithError(err).WithField("file", file).Fatal("Failed to read file")
		}

		updated := buildImageRegexp.ReplaceAllString(string(content), fmt.Sprintf("${1}%s@%s", ver, hash))
		updated = goVersionRegexp.ReplaceAllString(updated, "${1}"+ver)

		if updated != string(content) {
			if err := os.WriteFile(file, []byte(updated), 0o600); err != nil { //nolint:gosec // G703: Path traversal via taint analysis
				log.WithError(err).WithField("file", file).Fatal("Failed to write file")
			}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…