feat: initial stamp implementation
- stamp add: create .stamp/*.md changeset files (interactive + --no-interactive) - stamp status: show pending stamps and projected next versions (plain + --json) - stamp version: consume stamps, bump semver, update CHANGELOGs, commit - stamp publish: create git tags, GitHub/Gitea releases, upload artifacts - stamp comment: post/update idempotent PR comments via GitHub/Gitea API - Supports monorepos via stamp.toml [[projects]] blocks - Changeset files support YAML (---) and TOML (+++) frontmatter - Semver + pre-release support (alpha, beta, rc) - Examples and workflow documentation Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
130
internal/semver/semver_test.go
Normal file
130
internal/semver/semver_test.go
Normal file
@@ -0,0 +1,130 @@
|
||||
package semver_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/thokra/stamp/internal/changeset"
|
||||
"github.com/thokra/stamp/internal/semver"
|
||||
)
|
||||
|
||||
func TestBump_Major(t *testing.T) {
|
||||
got, err := semver.Bump("1.2.3", changeset.BumpMajor, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != "2.0.0" {
|
||||
t.Errorf("expected 2.0.0, got %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBump_Minor(t *testing.T) {
|
||||
got, err := semver.Bump("1.2.3", changeset.BumpMinor, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != "1.3.0" {
|
||||
t.Errorf("expected 1.3.0, got %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBump_Patch(t *testing.T) {
|
||||
got, err := semver.Bump("1.2.3", changeset.BumpPatch, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != "1.2.4" {
|
||||
t.Errorf("expected 1.2.4, got %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBump_PreMajor(t *testing.T) {
|
||||
got, err := semver.Bump("1.2.3", changeset.BumpPreMajor, "alpha")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != "2.0.0-alpha.0" {
|
||||
t.Errorf("expected 2.0.0-alpha.0, got %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBump_PreMinor(t *testing.T) {
|
||||
got, err := semver.Bump("1.2.3", changeset.BumpPreMinor, "beta")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != "1.3.0-beta.0" {
|
||||
t.Errorf("expected 1.3.0-beta.0, got %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBump_PrePatch(t *testing.T) {
|
||||
got, err := semver.Bump("1.2.3", changeset.BumpPrePatch, "rc")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != "1.2.4-rc.0" {
|
||||
t.Errorf("expected 1.2.4-rc.0, got %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBump_PreRelease_Increment(t *testing.T) {
|
||||
got, err := semver.Bump("1.2.4-rc.0", changeset.BumpPreRelease, "rc")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != "1.2.4-rc.1" {
|
||||
t.Errorf("expected 1.2.4-rc.1, got %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBump_PreRelease_NewFromStable(t *testing.T) {
|
||||
got, err := semver.Bump("1.2.3", changeset.BumpPreRelease, "alpha")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != "1.2.4-alpha.0" {
|
||||
t.Errorf("expected 1.2.4-alpha.0, got %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBump_InvalidVersion(t *testing.T) {
|
||||
_, err := semver.Bump("not-a-version", changeset.BumpPatch, "")
|
||||
if err == nil {
|
||||
t.Fatal("expected error for invalid version")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHighestBump(t *testing.T) {
|
||||
tests := []struct {
|
||||
bumps []changeset.BumpType
|
||||
expected changeset.BumpType
|
||||
}{
|
||||
{[]changeset.BumpType{changeset.BumpPatch, changeset.BumpMinor}, changeset.BumpMinor},
|
||||
{[]changeset.BumpType{changeset.BumpMinor, changeset.BumpMajor}, changeset.BumpMajor},
|
||||
{[]changeset.BumpType{changeset.BumpPreRelease}, changeset.BumpPreRelease},
|
||||
{[]changeset.BumpType{changeset.BumpPreRelease, changeset.BumpPatch}, changeset.BumpPatch},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
got := semver.HighestBump(tt.bumps)
|
||||
if got != tt.expected {
|
||||
t.Errorf("HighestBump(%v) = %s, want %s", tt.bumps, got, tt.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestProjectBumps(t *testing.T) {
|
||||
changesets := []*changeset.Changeset{
|
||||
{Slug: "a", Bumps: map[string]changeset.BumpType{"app": changeset.BumpMinor, "lib": changeset.BumpPatch}},
|
||||
{Slug: "b", Bumps: map[string]changeset.BumpType{"app": changeset.BumpPatch}},
|
||||
}
|
||||
|
||||
bumps := semver.ProjectBumps(changesets)
|
||||
|
||||
if len(bumps["app"]) != 2 {
|
||||
t.Errorf("expected 2 bumps for app, got %d", len(bumps["app"]))
|
||||
}
|
||||
if len(bumps["lib"]) != 1 {
|
||||
t.Errorf("expected 1 bump for lib, got %d", len(bumps["lib"]))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user