updateCalendarFile reads the releases index.md, updates the calendar table, and writes it back.
( repoRoot string, newVer version, channel string, )
| 278 | // updateCalendarFile reads the releases index.md, updates the |
| 279 | // calendar table, and writes it back. |
| 280 | func updateCalendarFile( |
| 281 | repoRoot string, |
| 282 | newVer version, |
| 283 | channel string, |
| 284 | ) error { |
| 285 | path := filepath.Join(repoRoot, releasesFile) |
| 286 | content, err := os.ReadFile(path) |
| 287 | if err != nil { |
| 288 | return xerrors.Errorf("reading %s: %w", releasesFile, err) |
| 289 | } |
| 290 | |
| 291 | rows, err := parseCalendarTable(string(content)) |
| 292 | if err != nil { |
| 293 | return xerrors.Errorf("parsing calendar: %w", err) |
| 294 | } |
| 295 | |
| 296 | rows = updateCalendar(rows, newVer, channel) |
| 297 | newTable := renderCalendarTable(rows) |
| 298 | |
| 299 | // Replace the content between markers. |
| 300 | s := string(content) |
| 301 | startIdx := strings.Index(s, calendarStartMarker) |
| 302 | endIdx := strings.Index(s, calendarEndMarker) |
| 303 | updated := s[:startIdx+len(calendarStartMarker)] + |
| 304 | "\n" + newTable + |
| 305 | s[endIdx:] |
| 306 | |
| 307 | //nolint:gosec // File permissions match the original. |
| 308 | return os.WriteFile(path, []byte(updated), 0o644) |
| 309 | } |
| 310 | |
| 311 | // updateAutoversionFile reads a markdown file and replaces |
| 312 | // version strings in lines following autoversion pragmas for |
no test coverage detected