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

Add support for subpath releases #51

Merged
merged 1 commit into from
May 4, 2024
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
9 changes: 7 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ type highlightCategory struct {
type release struct {
ProjectName string `toml:"project_name"`
GithubRepo string `toml:"github_repo"`
SubPath string `toml:"sub_path"`
Commit string `toml:"commit"`
Previous string `toml:"previous"`
PreRelease bool `toml:"pre_release"`
Expand Down Expand Up @@ -247,6 +248,10 @@ This tool should run from the root of the project repository for a new release.
}
logrus.Infof("Welcome to the %s release tool...", r.ProjectName)

if r.SubPath != "" {
gitSubpaths = append(gitSubpaths, r.SubPath)
}

mailmapPath, err := filepath.Abs(".mailmap")
if err != nil {
return fmt.Errorf("failed to resolve mailmap: %w", err)
Expand Down Expand Up @@ -289,13 +294,13 @@ This tool should run from the root of the project repository for a new release.
})

logrus.Infof("creating new release %s with %d new changes...", tag, len(changes))
current, err := parseDependencies(r.Commit)
current, err := parseDependencies(r.Commit, r.SubPath)
if err != nil {
return err
}
overrideDependencies(current, r.OverrideDeps)

previous, err := parseDependencies(r.Previous)
previous, err := parseDependencies(r.Previous, r.SubPath)
if err != nil {
return err
}
Expand Down
18 changes: 17 additions & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,22 @@ func parseTag(path string) string {
return strings.TrimSuffix(filepath.Base(path), ".toml")
}

func parseDependencies(commit string) ([]dependency, error) {
func parseDependencies(commit, subpath string) ([]dependency, error) {
rd, err := fileFromRev(commit, vendorConf)
if err == nil {
return parseVendorConfDependencies(rd)
}
// Look for go module at subpath if provided
if subpath != "" {
rd, err = fileFromRev(commit, filepath.Join(subpath, modulesTxt))
if err == nil {
return parseModulesTxtDependencies(rd)
}
rd, err = fileFromRev(commit, filepath.Join(subpath, goMod))
if err == nil {
return parseGoModDependencies(rd)
}
}
rd, err = fileFromRev(commit, modulesTxt)
if err == nil {
return parseModulesTxtDependencies(rd)
Expand Down Expand Up @@ -451,13 +462,18 @@ func fileFromRev(rev, file string) (io.Reader, error) {
}

var gitConfigs = map[string]string{}
var gitSubpaths = []string{}

func git(args ...string) ([]byte, error) {
var gitArgs []string
for k, v := range gitConfigs {
gitArgs = append(gitArgs, "-c", fmt.Sprintf("%s=%s", k, v))
}
gitArgs = append(gitArgs, args...)
if len(gitSubpaths) > 0 && len(args) > 0 && args[0] == "log" {
gitArgs = append(gitArgs, "--show-pulls", "--")
gitArgs = append(gitArgs, gitSubpaths...)
}
o, err := exec.Command("git", gitArgs...).CombinedOutput()
if err != nil {
return nil, fmt.Errorf("%s: %s", err, o)
Expand Down
Loading