The release calendar in `docs/reference/releases.md` still lists 2.29 as an Extended Support Release after the v2.40.0 release, and lists 2.40 as plain `Mainline` instead of `Mainline (ESR)`. `releasetui` (`scripts/releaser/docs.go`) only moves rows along the Mainline, Stable, Security Support, and Not Supported chain. It never reads `scripts/release_channels/esr_versions.txt`, so rows marked `Extended Support Release` never change, and new ESRs never get the `(ESR)` suffix. #32843 updated that file to replace 2.29 with 2.40 before #32858 regenerated the calendar, but the calendar ignored the change. - `updateCalendar` now loads the active ESR set from `esr_versions.txt`, the same file the backport workflow and `scripts/update-release-calendar.sh` use, and re-derives the ESR statuses on every run. - Fixes the current calendar: 2.29 becomes `Not Supported` and 2.40 becomes `Mainline (ESR)`. - Adds a regression test that replays the v2.40.0 release against the calendar from before #32858. Refs #32843, #32858 <details> <summary>Implementation notes</summary> - On each run, `updateCalendar` removes any ESR markers to get each row's base status, applies the normal channel transitions, and then re-applies the markers from `esr_versions.txt`. An active ESR shows `Extended Support Release` once it leaves the standard channels and `<Channel> (ESR)` while it is still in one. A retired ESR goes back to `Not Supported`. - ESR markers are applied before `trimOldestNotSupported`, so an active ESR such as 2.34 is never trimmed. Retired ESRs are trimmed like any other unsupported row. - Patch releases also re-apply the markers, so the calendar corrects itself after any change to `esr_versions.txt`. - The broad `strings.Contains(r.Status, "Stable")` match for the old `Stable + ESR` format is replaced with an exact match, because ESR suffixes are now removed before the transitions run. - The hand-edited calendar keeps 2.29 as a `Not Supported` row so readers can see that it reached end of life. The next minor release trims it automatically. </details> --- > [!NOTE] > Generated by Coder Agents on behalf of @Lisa-Fiander.
577 lines
16 KiB
Go
577 lines
16 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"regexp"
|
|
"strings"
|
|
"time"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
"github.com/coder/coder/v2/cli/cliui"
|
|
"github.com/coder/pretty"
|
|
"github.com/coder/serpent"
|
|
)
|
|
|
|
const (
|
|
calendarStartMarker = "<!-- RELEASE_CALENDAR_START -->"
|
|
calendarEndMarker = "<!-- RELEASE_CALENDAR_END -->"
|
|
|
|
releasesFile = "docs/reference/releases.md"
|
|
esrVersionsFile = "scripts/release_channels/esr_versions.txt"
|
|
kubernetesFile = "docs/install/server/kubernetes/index.md"
|
|
rancherFile = "docs/install/server/rancher.md"
|
|
changelogURLFmt = "https://coder.com/changelog/coder-%d-%d"
|
|
releaseTagURLFmt = "https://github.com/coder/coder/releases/tag/%s"
|
|
)
|
|
|
|
// calendarRow represents one row in the release calendar table.
|
|
type calendarRow struct {
|
|
// ReleaseName is the display name, e.g. "2.30" or
|
|
// "[2.30](https://...)".
|
|
ReleaseName string
|
|
// Major and Minor parsed from the release name.
|
|
Major int
|
|
Minor int
|
|
// ReleaseDate as displayed, e.g. "February 03, 2026".
|
|
ReleaseDate string
|
|
// Status like "Mainline", "Stable", "Not Supported", etc.
|
|
Status string
|
|
// LatestRelease as displayed, e.g.
|
|
// "[v2.30.0](https://...)".
|
|
LatestRelease string
|
|
}
|
|
|
|
var autoversionPragmaRe = regexp.MustCompile(
|
|
`<!-- ?autoversion\(([^)]+)\): ?"([^"]+)" ?-->`,
|
|
)
|
|
|
|
// parseCalendarTable extracts calendar rows from the markdown
|
|
// between the start and end markers. Returns the rows and the
|
|
// column widths for re-rendering.
|
|
func parseCalendarTable(content string) ([]calendarRow, error) {
|
|
startIdx := strings.Index(content, calendarStartMarker)
|
|
endIdx := strings.Index(content, calendarEndMarker)
|
|
if startIdx == -1 || endIdx == -1 {
|
|
return nil, xerrors.New("calendar markers not found")
|
|
}
|
|
|
|
tableContent := content[startIdx+len(calendarStartMarker) : endIdx]
|
|
lines := strings.Split(strings.TrimSpace(tableContent), "\n")
|
|
|
|
var rows []calendarRow
|
|
for _, line := range lines {
|
|
line = strings.TrimSpace(line)
|
|
if line == "" {
|
|
continue
|
|
}
|
|
// Skip header and separator lines.
|
|
if strings.HasPrefix(line, "| Release") ||
|
|
strings.HasPrefix(line, "|---") ||
|
|
strings.HasPrefix(line, "|-") {
|
|
continue
|
|
}
|
|
if !strings.HasPrefix(line, "|") {
|
|
continue
|
|
}
|
|
|
|
cols := strings.Split(line, "|")
|
|
// Split on "|" gives empty first and last elements.
|
|
if len(cols) < 5 {
|
|
continue
|
|
}
|
|
name := strings.TrimSpace(cols[1])
|
|
date := strings.TrimSpace(cols[2])
|
|
status := strings.TrimSpace(cols[3])
|
|
latest := strings.TrimSpace(cols[4])
|
|
|
|
major, minor := parseReleaseName(name)
|
|
rows = append(rows, calendarRow{
|
|
ReleaseName: name,
|
|
Major: major,
|
|
Minor: minor,
|
|
ReleaseDate: date,
|
|
Status: status,
|
|
LatestRelease: latest,
|
|
})
|
|
}
|
|
|
|
if len(rows) == 0 {
|
|
return nil, xerrors.New("no calendar rows found")
|
|
}
|
|
return rows, nil
|
|
}
|
|
|
|
// parseReleaseName extracts major.minor from a release name
|
|
// like "2.30" or "[2.30](https://...)".
|
|
func parseReleaseName(name string) (major, minor int) {
|
|
// Strip markdown link if present.
|
|
re := regexp.MustCompile(`\[(\d+\.\d+)\]`)
|
|
if m := re.FindStringSubmatch(name); len(m) > 1 {
|
|
name = m[1]
|
|
}
|
|
_, _ = fmt.Sscanf(name, "%d.%d", &major, &minor)
|
|
return major, minor
|
|
}
|
|
|
|
// renderCalendarTable renders the calendar rows as a markdown
|
|
// table.
|
|
func renderCalendarTable(rows []calendarRow) string {
|
|
// Compute column widths.
|
|
nameW, dateW, statusW, latestW := 12, 12, 6, 14
|
|
for _, r := range rows {
|
|
if len(r.ReleaseName) > nameW {
|
|
nameW = len(r.ReleaseName)
|
|
}
|
|
if len(r.ReleaseDate) > dateW {
|
|
dateW = len(r.ReleaseDate)
|
|
}
|
|
if len(r.Status) > statusW {
|
|
statusW = len(r.Status)
|
|
}
|
|
if len(r.LatestRelease) > latestW {
|
|
latestW = len(r.LatestRelease)
|
|
}
|
|
}
|
|
|
|
var b strings.Builder
|
|
// Header.
|
|
_, _ = fmt.Fprintf(&b, "| %-*s | %-*s | %-*s | %-*s |\n",
|
|
nameW, "Release name",
|
|
dateW, "Release Date",
|
|
statusW, "Status",
|
|
latestW, "Latest Release")
|
|
// Separator.
|
|
_, _ = fmt.Fprintf(&b, "|%s|%s|%s|%s|\n",
|
|
strings.Repeat("-", nameW+2),
|
|
strings.Repeat("-", dateW+2),
|
|
strings.Repeat("-", statusW+2),
|
|
strings.Repeat("-", latestW+2))
|
|
// Data rows.
|
|
for _, r := range rows {
|
|
_, _ = fmt.Fprintf(&b, "| %-*s | %-*s | %-*s | %-*s |\n",
|
|
nameW, r.ReleaseName,
|
|
dateW, r.ReleaseDate,
|
|
statusW, r.Status,
|
|
latestW, r.LatestRelease)
|
|
}
|
|
return b.String()
|
|
}
|
|
|
|
// updateCalendar modifies the calendar rows based on the new
|
|
// release version and channel.
|
|
func updateCalendar(
|
|
rows []calendarRow,
|
|
newVer version,
|
|
channel string,
|
|
esrVersions map[string]bool,
|
|
) []calendarRow {
|
|
// Work on base channel statuses so ESR markers from a previous run
|
|
// do not block transitions. They are re-applied from esrVersions
|
|
// at the end.
|
|
for i, r := range rows {
|
|
rows[i].Status = baseStatus(r.Status)
|
|
}
|
|
|
|
// For any release, update the "Latest Release" for the
|
|
// matching major.minor row.
|
|
for i, r := range rows {
|
|
if r.Major == newVer.Major && r.Minor == newVer.Minor {
|
|
rows[i].LatestRelease = fmt.Sprintf(
|
|
"[%s](%s)",
|
|
newVer.String(),
|
|
fmt.Sprintf(releaseTagURLFmt, newVer.String()),
|
|
)
|
|
// If this row was "Not Released", update it.
|
|
if r.Status == "Not Released" {
|
|
rows[i].Status = "Mainline"
|
|
rows[i].ReleaseDate = time.Now().Format("January 02, 2006")
|
|
rows[i].ReleaseName = fmt.Sprintf(
|
|
"[%d.%d](%s)",
|
|
newVer.Major, newVer.Minor,
|
|
fmt.Sprintf(changelogURLFmt, newVer.Major, newVer.Minor),
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Patch releases only update Latest Release, done above. New
|
|
// mainline releases (patch == 0) also apply status transitions.
|
|
if newVer.Patch == 0 && channel == "mainline" {
|
|
for i, r := range rows {
|
|
switch {
|
|
case r.Major == newVer.Major && r.Minor == newVer.Minor:
|
|
// Already handled above.
|
|
continue
|
|
case r.Status == "Mainline":
|
|
rows[i].Status = "Stable"
|
|
case r.Status == "Stable":
|
|
rows[i].Status = "Security Support"
|
|
case r.Status == "Security Support":
|
|
rows[i].Status = "Not Supported"
|
|
}
|
|
}
|
|
|
|
// Add "Not Released" row for the next minor.
|
|
nextMinor := newVer.Minor + 1
|
|
hasNext := false
|
|
for _, r := range rows {
|
|
if r.Major == newVer.Major && r.Minor == nextMinor {
|
|
hasNext = true
|
|
break
|
|
}
|
|
}
|
|
if !hasNext {
|
|
rows = append(rows, calendarRow{
|
|
ReleaseName: fmt.Sprintf("%d.%d", newVer.Major, nextMinor),
|
|
Major: newVer.Major,
|
|
Minor: nextMinor,
|
|
ReleaseDate: "",
|
|
Status: "Not Released",
|
|
LatestRelease: "N/A",
|
|
})
|
|
}
|
|
}
|
|
|
|
// Mark active ESRs. An ESR outside the standard channels shows as
|
|
// "Extended Support Release"; one still in a channel gets an
|
|
// "(ESR)" suffix, e.g. "Mainline (ESR)". ESRs that left the active
|
|
// set keep their base status, usually "Not Supported".
|
|
for i, r := range rows {
|
|
if !esrVersions[fmt.Sprintf("%d.%d", r.Major, r.Minor)] {
|
|
continue
|
|
}
|
|
switch r.Status {
|
|
case "Not Supported":
|
|
rows[i].Status = "Extended Support Release"
|
|
case "Not Released":
|
|
default:
|
|
rows[i].Status = r.Status + " (ESR)"
|
|
}
|
|
}
|
|
|
|
if newVer.Patch == 0 && channel == "mainline" {
|
|
// Trim oldest "Not Supported" rows to keep roughly
|
|
// the same number of rows. We allow up to the
|
|
// current count + 1 (for the new "Not Released"
|
|
// row), then trim. Active ESRs are already marked,
|
|
// so only unsupported rows, including retired ESRs,
|
|
// are trimmed.
|
|
rows = trimOldestNotSupported(rows)
|
|
}
|
|
|
|
return rows
|
|
}
|
|
|
|
// baseStatus returns the release channel status without ESR markers.
|
|
// An ESR outside the standard channels maps to "Not Supported", which
|
|
// is its status once it leaves the active ESR set.
|
|
func baseStatus(status string) string {
|
|
if status == "Extended Support Release" {
|
|
return "Not Supported"
|
|
}
|
|
return strings.TrimSuffix(status, " (ESR)")
|
|
}
|
|
|
|
// readESRVersions returns the active ESR major.minor versions from
|
|
// scripts/release_channels/esr_versions.txt, the same source the
|
|
// backport workflow and scripts/update-release-calendar.sh use.
|
|
func readESRVersions(repoRoot string) (map[string]bool, error) {
|
|
content, err := os.ReadFile(filepath.Join(repoRoot, esrVersionsFile))
|
|
if err != nil {
|
|
return nil, xerrors.Errorf("reading %s: %w", esrVersionsFile, err)
|
|
}
|
|
versions := make(map[string]bool)
|
|
for _, line := range strings.Split(string(content), "\n") {
|
|
line = strings.TrimSpace(line)
|
|
if line == "" || strings.HasPrefix(line, "#") {
|
|
continue
|
|
}
|
|
versions[line] = true
|
|
}
|
|
return versions, nil
|
|
}
|
|
|
|
// trimOldestNotSupported removes "Not Supported" rows from the
|
|
// start until we have at most 8 rows total, keeping at least
|
|
// one "Not Supported" row if any exist.
|
|
func trimOldestNotSupported(rows []calendarRow) []calendarRow {
|
|
const maxRows = 8
|
|
for len(rows) > maxRows {
|
|
// Find the first "Not Supported" row.
|
|
found := -1
|
|
for i, r := range rows {
|
|
if r.Status == "Not Supported" {
|
|
found = i
|
|
break
|
|
}
|
|
}
|
|
if found == -1 {
|
|
break
|
|
}
|
|
// Count how many "Not Supported" rows we have.
|
|
nsCount := 0
|
|
for _, r := range rows {
|
|
if r.Status == "Not Supported" {
|
|
nsCount++
|
|
}
|
|
}
|
|
// Keep at least one.
|
|
if nsCount <= 1 {
|
|
break
|
|
}
|
|
rows = append(rows[:found], rows[found+1:]...)
|
|
}
|
|
return rows
|
|
}
|
|
|
|
// updateCalendarFile reads the releases index.md, updates the
|
|
// calendar table, and writes it back.
|
|
func updateCalendarFile(
|
|
repoRoot string,
|
|
newVer version,
|
|
channel string,
|
|
) error {
|
|
path := filepath.Join(repoRoot, releasesFile)
|
|
content, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return xerrors.Errorf("reading %s: %w", releasesFile, err)
|
|
}
|
|
|
|
rows, err := parseCalendarTable(string(content))
|
|
if err != nil {
|
|
return xerrors.Errorf("parsing calendar: %w", err)
|
|
}
|
|
|
|
esrVersions, err := readESRVersions(repoRoot)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
rows = updateCalendar(rows, newVer, channel, esrVersions)
|
|
newTable := renderCalendarTable(rows)
|
|
|
|
// Replace the content between markers.
|
|
s := string(content)
|
|
startIdx := strings.Index(s, calendarStartMarker)
|
|
endIdx := strings.Index(s, calendarEndMarker)
|
|
updated := s[:startIdx+len(calendarStartMarker)] +
|
|
"\n" + newTable +
|
|
s[endIdx:]
|
|
|
|
//nolint:gosec // File permissions match the original.
|
|
return os.WriteFile(path, []byte(updated), 0o644)
|
|
}
|
|
|
|
// updateAutoversionFile reads a markdown file and replaces
|
|
// version strings in lines following autoversion pragmas for
|
|
// the given channel.
|
|
func updateAutoversionFile(path, channel, newVer string) error {
|
|
content, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return xerrors.Errorf("reading %s: %w", path, err)
|
|
}
|
|
|
|
lines := strings.Split(string(content), "\n")
|
|
changed := false
|
|
|
|
for i, line := range lines {
|
|
m := autoversionPragmaRe.FindStringSubmatch(line)
|
|
if len(m) < 3 {
|
|
continue
|
|
}
|
|
pragmaChannel := m[1]
|
|
pattern := m[2]
|
|
|
|
if pragmaChannel != channel {
|
|
continue
|
|
}
|
|
|
|
// Build regex from the pattern by replacing
|
|
// [version] with a capture group.
|
|
escaped := regexp.QuoteMeta(pattern)
|
|
reStr := strings.ReplaceAll(
|
|
escaped,
|
|
regexp.QuoteMeta("[version]"),
|
|
`(\d+\.\d+\.\d+)`,
|
|
)
|
|
re, err := regexp.Compile(reStr)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
|
|
// Search the next few lines for a match.
|
|
for j := i + 1; j < len(lines) && j <= i+5; j++ {
|
|
if loc := re.FindStringSubmatchIndex(lines[j]); loc != nil {
|
|
// loc[2]:loc[3] is the version capture
|
|
// group.
|
|
lines[j] = lines[j][:loc[2]] + newVer + lines[j][loc[3]:]
|
|
changed = true
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
if !changed {
|
|
return nil
|
|
}
|
|
|
|
//nolint:gosec // File permissions match the original.
|
|
return os.WriteFile(path, []byte(strings.Join(lines, "\n")), 0o644)
|
|
}
|
|
|
|
// updateRancherFile updates the version strings in rancher.md.
|
|
func updateRancherFile(path, channel, newVer string) error {
|
|
content, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return xerrors.Errorf("reading %s: %w", path, err)
|
|
}
|
|
|
|
s := string(content)
|
|
|
|
switch channel {
|
|
case "mainline":
|
|
// Match: - **Mainline**: `X.Y.Z`
|
|
re := regexp.MustCompile(
|
|
`(\*\*Mainline\*\*: ` + "`)" + `\d+\.\d+\.\d+` + "(`)",
|
|
)
|
|
s = re.ReplaceAllString(s, "${1}"+newVer+"${2}")
|
|
case "stable":
|
|
re := regexp.MustCompile(
|
|
`(\*\*Stable\*\*: ` + "`)" + `\d+\.\d+\.\d+` + "(`)",
|
|
)
|
|
s = re.ReplaceAllString(s, "${1}"+newVer+"${2}")
|
|
default:
|
|
return nil
|
|
}
|
|
|
|
//nolint:gosec // File permissions match the original.
|
|
return os.WriteFile(path, []byte(s), 0o644)
|
|
}
|
|
|
|
// updateReleaseDocs updates all release-related docs files and
|
|
// creates a PR with the changes.
|
|
//
|
|
//nolint:revive // dryRun flag is needed to control PR creation behavior.
|
|
func updateReleaseDocs(
|
|
inv *serpent.Invocation,
|
|
newVer version,
|
|
channel string,
|
|
dryRun bool,
|
|
) error {
|
|
w := inv.Stderr
|
|
|
|
// Find the repo root (where .git is).
|
|
repoRoot, err := gitOutput("rev-parse", "--show-toplevel")
|
|
if err != nil {
|
|
return xerrors.Errorf("finding repo root: %w", err)
|
|
}
|
|
|
|
verStr := fmt.Sprintf("%d.%d.%d", newVer.Major, newVer.Minor, newVer.Patch)
|
|
vTag := "v" + verStr
|
|
branchName := fmt.Sprintf("docs/update-release-%s", vTag)
|
|
|
|
infof(w, "Updating release docs for %s (channel: %s)...", vTag, channel)
|
|
fmt.Fprintln(w)
|
|
|
|
if dryRun {
|
|
_, _ = fmt.Fprintf(w, "[DRYRUN] would update %s\n", releasesFile)
|
|
_, _ = fmt.Fprintf(w, "[DRYRUN] would update %s\n", kubernetesFile)
|
|
_, _ = fmt.Fprintf(w, "[DRYRUN] would update %s\n", rancherFile)
|
|
_, _ = fmt.Fprintf(w, "[DRYRUN] would create branch %s\n", branchName)
|
|
_, _ = fmt.Fprintf(w, "[DRYRUN] would create PR: chore(docs): update release docs for %s\n", vTag)
|
|
return nil
|
|
}
|
|
|
|
// Create a new branch from main.
|
|
if err := gitRun("checkout", "-b", branchName, "origin/main"); err != nil {
|
|
return xerrors.Errorf("creating branch: %w", err)
|
|
}
|
|
|
|
// Update the files.
|
|
if err := updateCalendarFile(repoRoot, newVer, channel); err != nil {
|
|
return xerrors.Errorf("updating calendar: %w", err)
|
|
}
|
|
successf(w, "Updated %s", releasesFile)
|
|
|
|
k8sPath := filepath.Join(repoRoot, kubernetesFile)
|
|
if err := updateAutoversionFile(k8sPath, channel, verStr); err != nil {
|
|
return xerrors.Errorf("updating kubernetes.md: %w", err)
|
|
}
|
|
successf(w, "Updated %s", kubernetesFile)
|
|
|
|
rancherPath := filepath.Join(repoRoot, rancherFile)
|
|
if err := updateRancherFile(rancherPath, channel, verStr); err != nil {
|
|
return xerrors.Errorf("updating rancher.md: %w", err)
|
|
}
|
|
successf(w, "Updated %s", rancherFile)
|
|
|
|
// Stage and commit.
|
|
if err := gitRun("add",
|
|
filepath.Join(repoRoot, releasesFile),
|
|
k8sPath,
|
|
rancherPath,
|
|
); err != nil {
|
|
return xerrors.Errorf("staging files: %w", err)
|
|
}
|
|
|
|
commitMsg := fmt.Sprintf("chore(docs): update release docs for %s", vTag)
|
|
if err := gitRun("commit", "-m", commitMsg); err != nil {
|
|
return xerrors.Errorf("committing: %w", err)
|
|
}
|
|
|
|
// Push and create PR.
|
|
if err := gitRun("push", "origin", branchName); err != nil {
|
|
return xerrors.Errorf("pushing branch: %w", err)
|
|
}
|
|
|
|
prTitle := commitMsg
|
|
prBody := fmt.Sprintf("Automated docs update for %s release.\n\nCreated by `releasetui`.", vTag)
|
|
|
|
out, err := ghOutput("pr", "create",
|
|
"--repo", owner+"/"+repo,
|
|
"--title", prTitle,
|
|
"--body", prBody,
|
|
"--base", "main",
|
|
"--head", branchName,
|
|
)
|
|
if err != nil {
|
|
return xerrors.Errorf("creating PR: %w", err)
|
|
}
|
|
|
|
prURL := strings.TrimSpace(out)
|
|
successf(w, "Created PR: %s", prURL)
|
|
fmt.Fprintln(w)
|
|
infof(w, "Review and merge the PR to complete the docs update.")
|
|
|
|
return nil
|
|
}
|
|
|
|
// promptAndUpdateDocs asks the user if they want to create a
|
|
// docs update PR and does so if confirmed.
|
|
func promptAndUpdateDocs(
|
|
inv *serpent.Invocation,
|
|
newVer version,
|
|
channel string,
|
|
dryRun bool,
|
|
) {
|
|
w := inv.Stderr
|
|
_, _ = fmt.Fprintln(w)
|
|
_, _ = fmt.Fprintln(w, pretty.Sprint(cliui.BoldFmt(),
|
|
"Next step: create a PR updating release docs "+
|
|
"(calendar, helm versions, rancher)."))
|
|
_, _ = fmt.Fprintln(w)
|
|
|
|
if err := confirmWithDefault(inv, "Create docs update PR?", cliui.ConfirmYes); err != nil {
|
|
infof(w, "Skipped docs update. You can update them manually.")
|
|
return
|
|
}
|
|
|
|
if err := updateReleaseDocs(inv, newVer, channel, dryRun); err != nil {
|
|
warnf(w, "Failed to create docs PR: %v", err)
|
|
warnf(w, "You'll need to update release docs manually.")
|
|
}
|
|
}
|