Skip to content

Commit

Permalink
feat: produce monorepo release notes
Browse files Browse the repository at this point in the history
Signed-off-by: Marko Kungla <[email protected]>
  • Loading branch information
mkungla committed Feb 1, 2024
1 parent 50fcb42 commit 415d6c2
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 16 deletions.
1 change: 0 additions & 1 deletion happy-main.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ func (m *Main) run() {
err := m.cmd.callDoAction(m.sess)

if svcerr := m.engine.stop(m.sess); svcerr != nil {
fmt.Println("happy-main.go: 513")
m.sess.Log().Error("failed to stop engine", slog.String("err", svcerr.Error()))
}

Expand Down
8 changes: 8 additions & 0 deletions internal/cmd/hap/addons/releaser/changelog/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ type Changelog struct {
breaking []Entry
}

func (c *Changelog) Entries() []Entry {
return c.entries
}

func (c *Changelog) Breaking() []Entry {
return c.breaking
}

func (c *Changelog) Empty() bool {
return c.entries == nil && c.breaking == nil
}
Expand Down
16 changes: 14 additions & 2 deletions internal/cmd/hap/addons/releaser/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,20 @@ func newConfiguration(sess *happy.Session, path string, allowDirty bool) (*confi
if err != nil {
return nil, err
}
if gitinfo.dirty == "true" && !allowDirty {
return nil, fmt.Errorf("git repository is dirty - commit or stash changes before releasing")
if gitinfo.dirty == "true" {
if !allowDirty {
return nil, fmt.Errorf("git repository is dirty - commit or stash changes before releasing")
}
addCmd := exec.Command("git", "add", "-A")
addCmd.Dir = c.WD
if err := cli.RunCommand(sess, addCmd); err != nil {
return nil, err
}
commitCmd := exec.Command("git", "commit", "-sm", "wip: prepare release")
commitCmd.Dir = c.WD
if err := cli.RunCommand(sess, commitCmd); err != nil {
return nil, err
}
}

totalmodules := 0
Expand Down
114 changes: 113 additions & 1 deletion internal/cmd/hap/addons/releaser/releaser-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ func (r *releaser) Run(next string) error {
return err
}
sess.Log().Ok("releaser done")
return nil

return r.printChangelog()
}

func (r *releaser) session() (*happy.Session, error) {
Expand Down Expand Up @@ -131,6 +132,10 @@ func (r *releaser) loadModules() error {
return err
}

if len(pkgs) == 0 {
return fmt.Errorf("no modules found in %s", r.config.WD)
}

for _, pkg := range pkgs {
sess.Log().Info("loading release info for", slog.String("pkg", pkg.Modfile.Module.Mod.Path))
tagPrefix := strings.TrimPrefix(pkg.Dir+"/", r.config.WD+"/")
Expand Down Expand Up @@ -223,3 +228,110 @@ func (r *releaser) releaseModules() error {
}
return nil
}

type fullChangelog struct {
Root *packageChangelog
Subpkgs []*packageChangelog
}

type packageChangelog struct {
pkg *module.Package
Breaking []string
Changes []string
}

func (r *releaser) printChangelog() error {
r.mu.Lock()
defer r.mu.Unlock()

cl := &fullChangelog{}

for _, pkg := range r.packages {
if !pkg.NeedsRelease || (pkg.Changelog == nil || pkg.Changelog.Empty()) {
continue
}
clp := &packageChangelog{pkg: pkg}

for _, breaking := range pkg.Changelog.Breaking() {
breaking := fmt.Sprintf("* %s %s", breaking.ShortHash, breaking.Subject)
clp.Breaking = append(clp.Breaking, breaking)
}
for _, entry := range pkg.Changelog.Entries() {
change := fmt.Sprintf("* %s %s", entry.ShortHash, entry.Subject)
clp.Changes = append(clp.Changes, change)
}

if pkg.Dir == r.config.WD {
cl.Root = clp
} else {
cl.Subpkgs = append(cl.Subpkgs, clp)
}
}

fmt.Println("## Changelog")

fmt.Printf("`%s@%s`", cl.Root.pkg.Import, cl.Root.pkg.NextRelease)

if cl.Root == nil {
return nil
}
var breakingsection string
for _, breaking := range cl.Root.Breaking {
for _, scl := range cl.Subpkgs {
found := false
for _, bcl := range scl.Breaking {
if bcl == breaking {
found = true
}
}
if !found {
breakingsection += breaking + "\n"
}
}
}
if len(breakingsection) > 0 {
fmt.Println("### Breaking Changes")
fmt.Println(breakingsection)
}

var changessection string
for _, change := range cl.Root.Changes {
for _, scl := range cl.Subpkgs {
found := false
for _, bcl := range scl.Changes {
if bcl == change {
found = true
}
}
if !found {
changessection += change + "\n"
}
}
}
if len(changessection) > 0 {
fmt.Println("### Changes")
fmt.Println(changessection)
}
fmt.Println("")

for i, scl := range cl.Subpkgs {
if i == 0 {
fmt.Printf("### %s\n\n`%s@%s`\n", scl.pkg.NextRelease, scl.pkg.Import, scl.pkg.NextRelease)
}
for i, breaking := range scl.Breaking {
if i == 0 {
fmt.Println("**Breaking Changes**")
}
fmt.Println(breaking)
}
for i, change := range scl.Changes {
if i == 0 {
fmt.Println("**Changes**")
}
fmt.Println(change)
}
}

fmt.Println("")
return nil
}
3 changes: 0 additions & 3 deletions sdk/settings/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ func (p *Profile) Has(key string) bool {

func (p *Profile) Set(key string, val SettingField) (err error) {
if !p.Has(key) {
for s := range p.settings {
fmt.Println("SETTING: ", s)
}
return fmt.Errorf("setting not found %s", key)
}
p.mu.Lock()
Expand Down
4 changes: 2 additions & 2 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ func (sl *ServiceLoader) Load() <-chan struct{} {
return sl.loaderCh
}

timeout := sl.sess.Setting("app.service.loader.timeout").Value().Duration()
timeout := sl.sess.Setting("app.service_loader.timeout").Value().Duration()
if timeout <= 0 {
timeout = time.Duration(time.Second * 30)
sl.sess.Log().SystemDebug(
"service loader using default timeout",
slog.Duration("timeout", timeout),
slog.Duration("app.service.loader.timeout", timeout),
slog.Duration("app.service_loader.timeout", timeout),
)
}

Expand Down
7 changes: 0 additions & 7 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,6 @@ func (s *Session) isValid() bool {
func (s *Session) setProfile(profile *settings.Profile) {
s.mu.Lock()
defer s.mu.Unlock()
// p := profile.All()

// for _, setting := range p {
// if setting.Persistent() {
// fmt.Println("key:", setting.Key(), " val:", setting.Value().String())
// }
// }
s.profile = profile
}

Expand Down

0 comments on commit 415d6c2

Please sign in to comment.