This commit is contained in:
Thomas
2026-03-12 23:41:12 +01:00
parent 8049c505a0
commit 7c1a20465a
10 changed files with 1057 additions and 120 deletions
+79
View File
@@ -0,0 +1,79 @@
package main
import (
"context"
"fmt"
"os"
"github.com/urfave/cli/v3"
"git.thokra.dev/thokra/stamp/internal/config"
"git.thokra.dev/thokra/stamp/internal/releasepr"
)
func releasePRCmd() *cli.Command {
return &cli.Command{
Name: "release-pr",
Usage: "create or update a release pull request with pending version bumps",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "branch",
Usage: "release branch name (default: stamp/release)",
Value: releasepr.DefaultReleaseBranch,
},
&cli.StringFlag{
Name: "base",
Usage: "base branch the PR targets (default: from stamp.toml, fallback: main)",
},
&cli.StringFlag{
Name: "repo",
Usage: "repository slug owner/repo (defaults to STAMP_REPO env var)",
},
&cli.StringFlag{
Name: "snapshot",
Usage: "pre-release identifier (e.g. alpha, beta, rc) for snapshot releases",
},
&cli.BoolFlag{
Name: "dry-run",
Aliases: []string{"n"},
Usage: "print what would be done without pushing or opening a PR",
},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
repoRoot, err := findRepoRoot(".")
if err != nil {
return err
}
cfg, err := config.Load(repoRoot)
if err != nil {
return err
}
repoSlug := cmd.String("repo")
if repoSlug == "" {
repoSlug = os.Getenv("STAMP_REPO")
}
if repoSlug == "" {
repoSlug = os.Getenv("GITHUB_REPOSITORY")
}
if repoSlug == "" {
return fmt.Errorf("--repo or STAMP_REPO / GITHUB_REPOSITORY env var must be set")
}
baseBranch := cmd.String("base")
if baseBranch == "" {
baseBranch = cfg.BaseBranch()
}
return releasepr.Run(ctx, releasepr.Options{
RepoRoot: repoRoot,
RepoSlug: repoSlug,
BaseBranch: baseBranch,
ReleaseBranch: cmd.String("branch"),
SnapshotID: cmd.String("snapshot"),
DryRun: cmd.Bool("dry-run"),
})
},
}
}
+1 -16
View File
@@ -75,22 +75,7 @@ func versionCmd() *cli.Command {
}
if preID != "" {
// If the project is already on a pre-release version, just
// increment it. Otherwise promote the highest regular bump
// to its pre-release equivalent so we don't skip a version.
v, _ := semver.CurrentVersion(project.Version)
if v != nil && v.Prerelease() != "" {
highest = changeset.BumpPreRelease
} else {
switch highest {
case changeset.BumpMajor:
highest = changeset.BumpPreMajor
case changeset.BumpMinor:
highest = changeset.BumpPreMinor
default: // patch or anything lower
highest = changeset.BumpPrePatch
}
}
highest = semver.PreReleaseBump(project.Version, highest)
}
nextVer, err := semver.Bump(project.Version, highest, preID)
+1
View File
@@ -20,6 +20,7 @@ func main() {
publishCmd(),
commentCmd(),
previewCmd(),
releasePRCmd(),
},
}