updateRancherFile updates the version strings in rancher.md.
(path, channel, newVer string)
| 367 | |
| 368 | // updateRancherFile updates the version strings in rancher.md. |
| 369 | func 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. |
no test coverage detected