mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
be2e641162
This adds full RC release support to the release scripts and GitHub Actions workflow. Previously, the tooling only supported stable and mainline releases with strict vMAJOR.MINOR.PATCH semver tags. Changes: - scripts/releaser/version.go: Add Pre field to version struct for prerelease suffixes (e.g. "rc.0"), update regex, parsing, String(), comparison methods, and add IsRC()/rcNumber() helpers. - scripts/releaser/release.go: Detect RC branches (release/X.Y-rc.N), suggest RC version numbers, auto-set "rc" channel (skipping stable/mainline prompt), add RC advisory to release notes, skip docs update for RC releases. - .github/workflows/release.yaml: Add "rc" channel option, fix branch derivation for RC tags (v2.32.0-rc.0 -> release/2.32-rc.0 instead of broken release/2.32.0-rc), skip homebrew/winget/package publishing for RC releases. - scripts/release/publish.sh: Add --rc flag, pass --prerelease to gh release create for RC releases. - scripts/releaser/version_test.go: Add comprehensive unit tests for version parsing, string formatting, IsRC, rcNumber, GreaterThan, and Equal with RC versions. <!-- If you have used AI to produce some or all of this PR, please ensure you have read our [AI Contribution guidelines](https://coder.com/docs/about/contributing/AI_CONTRIBUTING) before submitting. -->
124 lines
2.8 KiB
Go
124 lines
2.8 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// version holds a parsed semver version with optional prerelease
|
|
// suffix (e.g. "rc.0").
|
|
type version struct {
|
|
Major int
|
|
Minor int
|
|
Patch int
|
|
Pre string // e.g. "rc.0", "" for stable releases.
|
|
}
|
|
|
|
var semverRe = regexp.MustCompile(`^v(\d+)\.(\d+)\.(\d+)(-(.+))?$`)
|
|
|
|
func parseVersion(s string) (version, bool) {
|
|
m := semverRe.FindStringSubmatch(s)
|
|
if m == nil {
|
|
return version{}, false
|
|
}
|
|
maj, _ := strconv.Atoi(m[1])
|
|
mnr, _ := strconv.Atoi(m[2])
|
|
pat, _ := strconv.Atoi(m[3])
|
|
return version{Major: maj, Minor: mnr, Patch: pat, Pre: m[5]}, true
|
|
}
|
|
|
|
func (v version) String() string {
|
|
if v.Pre != "" {
|
|
return fmt.Sprintf("v%d.%d.%d-%s", v.Major, v.Minor, v.Patch, v.Pre)
|
|
}
|
|
return fmt.Sprintf("v%d.%d.%d", v.Major, v.Minor, v.Patch)
|
|
}
|
|
|
|
// IsRC returns true when the version has a prerelease suffix starting
|
|
// with "rc." (e.g. "rc.0", "rc.1").
|
|
func (v version) IsRC() bool {
|
|
return strings.HasPrefix(v.Pre, "rc.")
|
|
}
|
|
|
|
// rcNumber returns the numeric RC identifier (e.g. 0 for "rc.0").
|
|
// It returns -1 when the version is not an RC.
|
|
func (v version) rcNumber() int {
|
|
if !v.IsRC() {
|
|
return -1
|
|
}
|
|
n, err := strconv.Atoi(strings.TrimPrefix(v.Pre, "rc."))
|
|
if err != nil {
|
|
return -1
|
|
}
|
|
return n
|
|
}
|
|
|
|
func (v version) GreaterThan(b version) bool {
|
|
if v.Major != b.Major {
|
|
return v.Major > b.Major
|
|
}
|
|
if v.Minor != b.Minor {
|
|
return v.Minor > b.Minor
|
|
}
|
|
if v.Patch != b.Patch {
|
|
return v.Patch > b.Patch
|
|
}
|
|
// A release without prerelease suffix is greater than one
|
|
// with a prerelease suffix (v2.32.0 > v2.32.0-rc.0).
|
|
if v.Pre == "" && b.Pre != "" {
|
|
return true
|
|
}
|
|
if v.Pre != "" && b.Pre == "" {
|
|
return false
|
|
}
|
|
// Both have prerelease: compare numerically for RC versions.
|
|
if v.IsRC() && b.IsRC() {
|
|
return v.rcNumber() > b.rcNumber()
|
|
}
|
|
// Fallback for non-RC prerelease strings.
|
|
return v.Pre > b.Pre
|
|
}
|
|
|
|
func (v version) Equal(b version) bool {
|
|
return v.Major == b.Major && v.Minor == b.Minor && v.Patch == b.Patch && v.Pre == b.Pre
|
|
}
|
|
|
|
// allSemverTags returns all semver tags sorted descending.
|
|
func allSemverTags() ([]version, error) {
|
|
out, err := gitOutput("tag", "--sort=-v:refname")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if out == "" {
|
|
return nil, nil
|
|
}
|
|
var tags []version
|
|
for _, line := range strings.Split(out, "\n") {
|
|
if v, ok := parseVersion(strings.TrimSpace(line)); ok {
|
|
tags = append(tags, v)
|
|
}
|
|
}
|
|
return tags, nil
|
|
}
|
|
|
|
// mergedSemverTags returns semver tags reachable from HEAD, sorted
|
|
// descending.
|
|
func mergedSemverTags() ([]version, error) {
|
|
out, err := gitOutput("tag", "--merged", "HEAD", "--sort=-v:refname")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if out == "" {
|
|
return nil, nil
|
|
}
|
|
var tags []version
|
|
for _, line := range strings.Split(out, "\n") {
|
|
if v, ok := parseVersion(strings.TrimSpace(line)); ok {
|
|
tags = append(tags, v)
|
|
}
|
|
}
|
|
return tags, nil
|
|
}
|