mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
## What Consolidates the two separate release programs into a single command at `scripts/releaser`: - `scripts/releaser/v1/` — the former interactive releaser (package `v1`). - `scripts/releaser/v2/` — the former `scripts/release-action` CI tool (package `v2`). - `scripts/releaser/main.go` — new entrypoint. Runs the **v2** tooling by default and the **v1** interactive wizard with `--legacy`. ## CLI shape Three documented subcommands, each backed by v2 `prepare-release` with the release type baked in: - `releaser rc` — tag a release candidate - `releaser branch` — cut a new release branch and tag its first RC - `releaser release` — tag a stable release or patch The former release-action verbs (`calculate-version`, `prepare-release`, `generate-notes`, `publish`) are retained as **hidden** top-level commands with identical flags and stdout, so `tag-and-release.yaml` migrates with a path-only change (`scripts/release-action` -> `scripts/releaser`). `--legacy` runs the v1 wizard and is mutually exclusive with the subcommands. `scripts/release.sh` now launches `releaser --legacy`. All file moves are rename-detected by git, so the per-file diff is just the package declaration. ## Testing - `go build ./scripts/...`, `go vet ./scripts/releaser/...`, `go test ./scripts/releaser/...` - `golangci-lint run ./scripts/releaser/...`, `make lint/emdash`, `shellcheck`, `actionlint` - Smoke: `releaser --help` shows only rc/branch/release; hidden verbs still run; `releaser rc --ref main --dry-run` emits the same JSON contract; `--legacy rc` errors cleanly. <details> <summary>Implementation plan</summary> # Plan: Consolidate release tooling into a single `scripts/releaser` command ## Goal Merge the two separate release programs into one binary at `scripts/releaser`: - `scripts/releaser/v1/` — the current interactive releaser (package `v1`). - `scripts/releaser/v2/` — the current CI `scripts/release-action` (package `v2`). - `scripts/releaser/main.go` — new entrypoint (package `main`). - Uses v2 by default, v1 with `--legacy`. - Exposes 3 subcommands: `rc`, `branch` (cut release branch), `release`. ## Design decision (Option A, chosen) The workflow needs `prepare-release`, `generate-notes`, and `publish` invokable separately (a build happens between prepare and publish). The latter two are version-driven and type-agnostic, so they do not map cleanly onto `rc`/`branch`/`release`. - Visible subcommands `rc`, `branch`, `release` run v2 `prepare-release` with the type baked in and print the same JSON. - Hidden verbs `calculate-version`, `prepare-release`, `generate-notes`, `publish` keep byte-identical flags/stdout, so the workflow change is path-only. Lowest risk; honors "3 subcommands" from a UX perspective. ## `--legacy` semantics - `releaser --legacy` runs the v1 interactive wizard (preserves today's behavior; the wizard auto-detects RC vs release from the branch). - `--legacy` is mutually exclusive with the subcommands (clear error if combined), because v1 auto-detects type and cannot cut a branch. ## Work items 1. Create `v1` and `v2` packages via `git mv`, renaming `package main`. Move the `owner`/`repo` consts into each package. Add `v1.Run(inv, dryRun)` (old wizard `main()` body) and v2 command builders (`CICommands`, `TypeCommand`) so internals stay unexported. 2. New `scripts/releaser/main.go`: top-level `releaser` with `--legacy`, the 3 subcommands, and the hidden compat verbs; delegates to `v1.Run` for legacy. 3. Update references: `tag-and-release.yaml` (3 command paths + header comment) and `scripts/release.sh` (`--legacy`). 4. Verify: build, vet, test, `go run` smoke tests, fmt, lint. 5. Open a single PR from a feature branch. ## Risks / notes - stdout contract for rc/branch/release and the hidden verbs must stay identical (workflow parses stdout); logs go to stderr. - Patch releases from pre-existing `release/X.Y` branches run those branches' own (old) workflow + `scripts/release-action`, so they stay self-consistent. New releases cut from branches containing this change get the new workflow + `scripts/releaser`. No forwarding stub needed since code and workflow ship together. </details> --- This PR was created by Coder Agents on behalf of @f0ssel.
241 lines
5.6 KiB
Go
241 lines
5.6 KiB
Go
package v1 //nolint:testpackage // Tests unexported release helpers.
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestParseVersion(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
input string
|
|
ok bool
|
|
want version
|
|
}{
|
|
{"v2.32.0", true, version{2, 32, 0, ""}},
|
|
{"v1.0.0", true, version{1, 0, 0, ""}},
|
|
{"v2.32.0-rc.0", true, version{2, 32, 0, "rc.0"}},
|
|
{"v2.32.0-rc.1", true, version{2, 32, 0, "rc.1"}},
|
|
{"v2.32.1-beta.3", true, version{2, 32, 1, "beta.3"}},
|
|
{"2.32.0", false, version{}},
|
|
{"v2.32", false, version{}},
|
|
{"vx.y.z", false, version{}},
|
|
{"", false, version{}},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.input, func(t *testing.T) {
|
|
t.Parallel()
|
|
got, ok := parseVersion(tt.input)
|
|
if ok != tt.ok {
|
|
t.Fatalf("parseVersion(%q) ok = %v, want %v", tt.input, ok, tt.ok)
|
|
}
|
|
if ok && got != tt.want {
|
|
t.Fatalf("parseVersion(%q) = %+v, want %+v", tt.input, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestVersionString(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
v version
|
|
want string
|
|
}{
|
|
{version{2, 32, 0, ""}, "v2.32.0"},
|
|
{version{2, 32, 0, "rc.0"}, "v2.32.0-rc.0"},
|
|
{version{1, 0, 0, "beta.1"}, "v1.0.0-beta.1"},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.want, func(t *testing.T) {
|
|
t.Parallel()
|
|
if got := tt.v.String(); got != tt.want {
|
|
t.Fatalf("String() = %q, want %q", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestVersionIsRC(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
v version
|
|
want bool
|
|
}{
|
|
{version{2, 32, 0, "rc.0"}, true},
|
|
{version{2, 32, 0, "rc.1"}, true},
|
|
{version{2, 32, 0, ""}, false},
|
|
{version{2, 32, 0, "beta.1"}, false},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.v.String(), func(t *testing.T) {
|
|
t.Parallel()
|
|
if got := tt.v.IsRC(); got != tt.want {
|
|
t.Fatalf("IsRC() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestVersionRCNumber(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
v version
|
|
want int
|
|
}{
|
|
{version{2, 32, 0, "rc.0"}, 0},
|
|
{version{2, 32, 0, "rc.5"}, 5},
|
|
{version{2, 32, 0, ""}, -1},
|
|
{version{2, 32, 0, "beta.1"}, -1},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.v.String(), func(t *testing.T) {
|
|
t.Parallel()
|
|
if got := tt.v.rcNumber(); got != tt.want {
|
|
t.Fatalf("rcNumber() = %d, want %d", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestVersionGreaterThan(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
a, b version
|
|
want bool
|
|
}{
|
|
// Standard comparisons.
|
|
{version{2, 32, 1, ""}, version{2, 32, 0, ""}, true},
|
|
{version{2, 32, 0, ""}, version{2, 32, 1, ""}, false},
|
|
{version{2, 33, 0, ""}, version{2, 32, 0, ""}, true},
|
|
{version{3, 0, 0, ""}, version{2, 99, 99, ""}, true},
|
|
|
|
// Release > RC with same base version.
|
|
{version{2, 32, 0, ""}, version{2, 32, 0, "rc.0"}, true},
|
|
{version{2, 32, 0, "rc.0"}, version{2, 32, 0, ""}, false},
|
|
|
|
// RC ordering.
|
|
{version{2, 32, 0, "rc.1"}, version{2, 32, 0, "rc.0"}, true},
|
|
{version{2, 32, 0, "rc.0"}, version{2, 32, 0, "rc.1"}, false},
|
|
{version{2, 32, 0, "rc.10"}, version{2, 32, 0, "rc.9"}, true},
|
|
{version{2, 32, 0, "rc.9"}, version{2, 32, 0, "rc.10"}, false},
|
|
|
|
// Equal.
|
|
{version{2, 32, 0, ""}, version{2, 32, 0, ""}, false},
|
|
{version{2, 32, 0, "rc.0"}, version{2, 32, 0, "rc.0"}, false},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.a.String()+"_gt_"+tt.b.String(), func(t *testing.T) {
|
|
t.Parallel()
|
|
if got := tt.a.GreaterThan(tt.b); got != tt.want {
|
|
t.Fatalf("%s.GreaterThan(%s) = %v, want %v", tt.a, tt.b, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestVersionEqual(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
a, b version
|
|
want bool
|
|
}{
|
|
{version{2, 32, 0, ""}, version{2, 32, 0, ""}, true},
|
|
{version{2, 32, 0, "rc.0"}, version{2, 32, 0, "rc.0"}, true},
|
|
{version{2, 32, 0, ""}, version{2, 32, 0, "rc.0"}, false},
|
|
{version{2, 32, 0, "rc.0"}, version{2, 32, 0, "rc.1"}, false},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.a.String()+"_eq_"+tt.b.String(), func(t *testing.T) {
|
|
t.Parallel()
|
|
if got := tt.a.Equal(tt.b); got != tt.want {
|
|
t.Fatalf("%s.Equal(%s) = %v, want %v", tt.a, tt.b, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestSortVersionsDesc(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
input []version
|
|
want []version
|
|
}{
|
|
{
|
|
// This is the exact scenario that triggered the bug:
|
|
// git's --sort=-v:refname places v2.32.0-rc.0 before
|
|
// v2.32.0, but semver says v2.32.0 > v2.32.0-rc.0.
|
|
name: "release_sorts_before_rc",
|
|
input: []version{
|
|
{2, 32, 0, "rc.0"},
|
|
{2, 32, 0, ""},
|
|
{2, 31, 2, ""},
|
|
},
|
|
want: []version{
|
|
{2, 32, 0, ""},
|
|
{2, 32, 0, "rc.0"},
|
|
{2, 31, 2, ""},
|
|
},
|
|
},
|
|
{
|
|
name: "multiple_rcs_and_releases",
|
|
input: []version{
|
|
{2, 33, 0, "rc.1"},
|
|
{2, 33, 0, "rc.0"},
|
|
{2, 32, 0, "rc.0"},
|
|
{2, 32, 0, ""},
|
|
{2, 32, 1, ""},
|
|
{2, 31, 0, ""},
|
|
},
|
|
want: []version{
|
|
{2, 33, 0, "rc.1"},
|
|
{2, 33, 0, "rc.0"},
|
|
{2, 32, 1, ""},
|
|
{2, 32, 0, ""},
|
|
{2, 32, 0, "rc.0"},
|
|
{2, 31, 0, ""},
|
|
},
|
|
},
|
|
{
|
|
name: "already_sorted",
|
|
input: []version{{3, 0, 0, ""}, {2, 0, 0, ""}, {1, 0, 0, ""}},
|
|
want: []version{{3, 0, 0, ""}, {2, 0, 0, ""}, {1, 0, 0, ""}},
|
|
},
|
|
{
|
|
name: "empty",
|
|
input: []version{},
|
|
want: []version{},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
got := make([]version, len(tt.input))
|
|
copy(got, tt.input)
|
|
sortVersionsDesc(got)
|
|
if len(got) != len(tt.want) {
|
|
t.Fatalf("sortVersionsDesc() returned %d elements, want %d", len(got), len(tt.want))
|
|
}
|
|
for i := range got {
|
|
if !got[i].Equal(tt.want[i]) {
|
|
t.Fatalf("sortVersionsDesc()[%d] = %s, want %s\n full result: %v", i, got[i], tt.want[i], got)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|