MCPcopy Index your code
hub / github.com/coder/coder / updateRancherFile

Function updateRancherFile

scripts/releaser/docs.go:369–395  ·  view source on GitHub ↗

updateRancherFile updates the version strings in rancher.md.

(path, channel, newVer string)

Source from the content-addressed store, hash-verified

367
368// updateRancherFile updates the version strings in rancher.md.
369func updateRancherFile(path, channel, newVer string) error {
370 content, err := os.ReadFile(path)
371 if err != nil {
372 return xerrors.Errorf("reading %s: %w", path, err)
373 }
374
375 s := string(content)
376
377 switch channel {
378 case "mainline":
379 // Match: - **Mainline**: `X.Y.Z`
380 re := regexp.MustCompile(
381 `(\*\*Mainline\*\*: ` + "`)" + `\d+\.\d+\.\d+` + "(`)",
382 )
383 s = re.ReplaceAllString(s, "${1}"+newVer+"${2}")
384 case "stable":
385 re := regexp.MustCompile(
386 `(\*\*Stable\*\*: ` + "`)" + `\d+\.\d+\.\d+` + "(`)",
387 )
388 s = re.ReplaceAllString(s, "${1}"+newVer+"${2}")
389 default:
390 return nil
391 }
392
393 //nolint:gosec // File permissions match the original.
394 return os.WriteFile(path, []byte(s), 0o644)
395}
396
397// updateReleaseDocs updates all release-related docs files and
398// creates a PR with the changes.

Callers 1

updateReleaseDocsFunction · 0.85

Calls 4

MustCompileMethod · 0.80
ReadFileMethod · 0.65
WriteFileMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected