Files
coder/scripts/releaser/v2/commit_test.go
T
Garrett Delfosse bfbacd64f4 refactor: consolidate release tooling into a single releaser command (#27034)
## 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.
2026-07-07 11:13:50 -04:00

353 lines
6.5 KiB
Go

package v2 //nolint:testpackage // Tests unexported release helpers.
import (
"testing"
"github.com/stretchr/testify/require"
)
func Test_humanizeTitle(t *testing.T) {
t.Parallel()
tests := []struct {
name string
title string
want string
}{
{
name: "feat_site_scope",
title: "feat(site): add bar",
want: "Dashboard: Add bar",
},
{
name: "fix_coderd_scope",
title: "fix(coderd): thing",
want: "Server: Thing",
},
{
name: "fix_agent_scope",
title: "fix(agent): reconnect",
want: "Agent: Reconnect",
},
{
name: "feat_cli_scope",
title: "feat(cli): new flag",
want: "CLI: New flag",
},
{
name: "fix_tailnet_scope",
title: "fix(tailnet): routing issue",
want: "Networking: Routing issue",
},
{
name: "feat_codersdk_scope",
title: "feat(codersdk): new method",
want: "SDK: New method",
},
{
name: "feat_docs_scope",
title: "feat(docs): add guide",
want: "Documentation: Add guide",
},
{
name: "fix_enterprise_coderd_scope",
title: "fix(enterprise/coderd): auth bug",
want: "Server: Auth bug",
},
{
name: "no_scope",
title: "feat: thing",
want: "Thing",
},
{
name: "non_conventional_title",
title: "Update README",
want: "Update README",
},
{
name: "breaking_with_bang_unchanged",
title: "feat!: thing",
want: "feat!: thing",
},
{
name: "breaking_with_scope_and_bang_unchanged",
title: "feat(site)!: remove old api",
want: "feat(site)!: remove old api",
},
{
name: "unknown_scope_returns_original",
title: "fix(unknownscope): something",
want: "fix(unknownscope): something",
},
{
name: "agent_agentssh_more_specific",
title: "fix(agent/agentssh): session bug",
want: "Agent SSH: Session bug",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
require.Equal(t, tt.want, humanizeTitle(tt.title))
})
}
}
func Test_categorizeCommit(t *testing.T) {
t.Parallel()
tests := []struct {
name string
title string
labels []string
want string
}{
{
name: "breaking_via_bang_in_title",
title: "feat!: remove old api",
want: "breaking",
},
{
name: "breaking_via_scoped_bang",
title: "fix(coderd)!: breaking change",
want: "breaking",
},
{
name: "breaking_via_label",
title: "feat(site): add thing",
labels: []string{"release/breaking"},
want: "breaking",
},
{
name: "security_label",
title: "fix(coderd): patch vuln",
labels: []string{"security"},
want: "security",
},
{
name: "experimental_label",
title: "feat(site): new feature",
labels: []string{"release/experimental"},
want: "experimental",
},
{
name: "feat_prefix",
title: "feat(site): add bar",
want: "feat",
},
{
name: "fix_prefix",
title: "fix(coderd): thing",
want: "fix",
},
{
name: "chore_prefix",
title: "chore: update deps",
want: "chore",
},
{
name: "docs_prefix",
title: "docs: update readme",
want: "docs",
},
{
name: "refactor_prefix",
title: "refactor(coderd): simplify",
want: "refactor",
},
{
name: "unknown_prefix",
title: "yolo: do something",
want: "other",
},
{
name: "no_prefix",
title: "Update README",
want: "other",
},
{
name: "breaking_label_takes_priority_over_feat",
title: "feat(coderd): new api",
labels: []string{"release/breaking"},
want: "breaking",
},
{
name: "security_takes_priority_over_experimental",
title: "fix(coderd): vuln",
labels: []string{"security", "release/experimental"},
want: "security",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
require.Equal(t, tt.want, categorizeCommit(tt.title, tt.labels))
})
}
}
func Test_commitSortPrefix(t *testing.T) {
t.Parallel()
tests := []struct {
name string
title string
want string
}{
{
name: "space_delimiter",
title: "feat something",
want: "feat",
},
{
name: "colon_delimiter",
title: "feat: something",
want: "feat",
},
{
name: "paren_delimiter",
title: "feat(site): something",
want: "feat",
},
{
name: "no_delimiter",
title: "single",
want: "single",
},
{
name: "empty_string",
title: "",
want: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
require.Equal(t, tt.want, commitSortPrefix(tt.title))
})
}
}
func Test_parsePRNumbers(t *testing.T) {
t.Parallel()
tests := []struct {
name string
title string
want []int
}{
{
name: "single_pr",
title: "feat(site): add bar (#123)",
want: []int{123},
},
{
name: "multiple_prs",
title: "fix (#42) then (#43)",
want: []int{42, 43},
},
{
name: "no_pr_numbers",
title: "feat(site): add bar",
want: nil,
},
{
name: "cherry_pick_only_matches_parens",
title: "chore: foo (cherry-pick #42) (#43)",
want: []int{43},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got := parsePRNumbers(tt.title)
require.Equal(t, tt.want, got)
})
}
}
func Test_stripPRRef(t *testing.T) {
t.Parallel()
tests := []struct {
name string
title string
want string
}{
{
name: "removes_trailing_pr_ref",
title: "Dashboard: Add bar (#123)",
want: "Dashboard: Add bar",
},
{
name: "no_pr_ref",
title: "Dashboard: Add bar",
want: "Dashboard: Add bar",
},
{
name: "multiple_pr_refs_strips_last",
title: "Foo (#42) (#43)",
want: "Foo (#42)",
},
{
name: "pr_ref_with_whitespace",
title: "Title (#999)",
want: "Title",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
require.Equal(t, tt.want, stripPRRef(tt.title))
})
}
}
func Test_isDependabot(t *testing.T) {
t.Parallel()
tests := []struct {
name string
title string
want bool
}{
{
name: "contains_dependabot",
title: "chore: bump dependabot/fetch-metadata (#456)",
want: true,
},
{
name: "chore_deps_prefix",
title: "chore(deps): bump golang.org/x/net",
want: true,
},
{
name: "normal_title",
title: "feat(site): add bar (#123)",
want: false,
},
{
name: "case_insensitive_dependabot",
title: "Bump Dependabot thing",
want: true,
},
{
name: "chore_deps_uppercase",
title: "Chore(Deps): update things",
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
require.Equal(t, tt.want, isDependabot(tt.title))
})
}
}