Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overwrite changelog (rather than write to stdout) #3

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Config struct {
Cleanup bool
Branch string
ReleaseTime time.Time
OutputPath string
}

func (c *Config) Repo() (*git.Repository, error) {
Expand Down
17 changes: 15 additions & 2 deletions cmd/release/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"flag"
"fmt"
"os"
"path"
"time"

"github.com/OffchainLabs/unclog/changelog"
Expand All @@ -16,17 +18,25 @@ func parseArgs(args []string) (*changelog.Config, error) {
flags.StringVar(&c.ChangesDir, "changelog-dir", "changelog", "Path to the directory containing changelog fragments for each commit")
flags.StringVar(&c.Tag, "tag", "", "New release tag (must already exist in repo)")
flags.StringVar(&c.PreviousPath, "prev", "CHANGELOG.md", "Path to current changelog in the repo. This will be pulled from HEAD")
flags.StringVar(&c.OutputPath, "output", "", "Path to file where merged output will be written (relative to the -repo flag). Defaults to the value of the -prev flag")
flags.BoolVar(&c.Cleanup, "cleanup", false, "Remove the changelog fragment files after generating the changelog")
flags.Parse(args)
if c.RepoPath == "" {
return c, fmt.Errorf("repo is required")
wd, err := os.Getwd()
if err != nil {
return nil, fmt.Errorf("repo flag not set and can't get working directory from syscall, %w", err)
}
c.RepoPath = wd
}
if c.Tag == "" {
return c, fmt.Errorf("tag is required")
}
if c.PreviousPath == "" {
return c, fmt.Errorf("prev is required")
}
if c.OutputPath == "" {
c.OutputPath = c.PreviousPath
}
return c, nil
}

Expand All @@ -39,6 +49,9 @@ func Run(ctx context.Context, args []string) error {
if err != nil {
return err
}
fmt.Println(out)
clPath := path.Join(cfg.RepoPath, cfg.OutputPath)
if err := os.WriteFile(clPath, []byte(out), 0644); err != nil {
return err
}
return nil
}
Loading