Port CI commands (changelog, version, publish, init) and SDK commands into a standalone module for CI/CD pipeline tooling. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package ci
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
|
|
"forge.lthn.ai/core/go/pkg/cli"
|
|
"forge.lthn.ai/core/go/pkg/i18n"
|
|
"forge.lthn.ai/core/go/pkg/release"
|
|
)
|
|
|
|
func runChangelog(fromRef, toRef string) error {
|
|
cwd, err := os.Getwd()
|
|
if err != nil {
|
|
return cli.Err("%s: %w", i18n.T("i18n.fail.get", "working directory"), err)
|
|
}
|
|
|
|
// Auto-detect refs if not provided
|
|
if fromRef == "" || toRef == "" {
|
|
tag, err := latestTag(cwd)
|
|
if err == nil {
|
|
if fromRef == "" {
|
|
fromRef = tag
|
|
}
|
|
if toRef == "" {
|
|
toRef = "HEAD"
|
|
}
|
|
} else {
|
|
// No tags, use initial commit? Or just HEAD?
|
|
cli.Text(i18n.T("cmd.ci.changelog.no_tags"))
|
|
return nil
|
|
}
|
|
}
|
|
|
|
cli.Print("%s %s..%s\n\n", releaseDimStyle.Render(i18n.T("cmd.ci.changelog.generating")), fromRef, toRef)
|
|
|
|
// Generate changelog
|
|
changelog, err := release.Generate(cwd, fromRef, toRef)
|
|
if err != nil {
|
|
return cli.Err("%s: %w", i18n.T("i18n.fail.generate", "changelog"), err)
|
|
}
|
|
|
|
cli.Text(changelog)
|
|
|
|
return nil
|
|
}
|
|
|
|
func latestTag(dir string) (string, error) {
|
|
cmd := exec.Command("git", "describe", "--tags", "--abbrev=0")
|
|
cmd.Dir = dir
|
|
out, err := cmd.Output()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return strings.TrimSpace(string(out)), nil
|
|
}
|