Skip to content

Commit

Permalink
testutil/genchangelog: generate logs for latest rc release
Browse files Browse the repository at this point in the history
Generates changelog between last non-rc release and latest rc release, but never between two rc's.
  • Loading branch information
gsora committed Nov 8, 2023
1 parent d90dffc commit 492a45d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (v SemVer) String() string {
return fmt.Sprintf("v%d.%d.%d", v.major, v.minor, v.patch)
}

return fmt.Sprintf("v%d.%d-%s", v.major, v.minor, v.preRelease)
return fmt.Sprintf("v%d.%d.%d-%s", v.major, v.minor, v.patch, v.preRelease)

Check warning on line 96 in app/version/version.go

View check run for this annotation

Codecov / codecov/patch

app/version/version.go#L96

Added line #L96 was not covered by tests
}

// PreRelease returns true if v represents a tag for a pre-release.
Expand Down
49 changes: 37 additions & 12 deletions testutil/genchangelog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,16 +335,17 @@ func parsePRs(gitRange string) ([]pullRequest, error) {
if err != nil {
return nil, errors.Wrap(err, "git log")
}
out := strings.TrimSuffix(string(b), "†") // Trim last log separator
out = "[" + out + "]" // Wrap logs in json array
out = strings.ReplaceAll(out, "†\n", `,`) // Replace log separator with comma
out = strings.ReplaceAll(out, "\r", ``) // Drop carriage returns if any
out = strings.ReplaceAll(out, "\n", `\n`) // Escape new lines
out = strings.ReplaceAll(out, "\t", `\t`) // Escape tabs
out = strings.ReplaceAll(out, `\"`, `‰`) // Hide already escaped quotes
out = strings.ReplaceAll(out, `"`, `\"`) // Escape double quotes
out = strings.ReplaceAll(out, `‰`, `\"`) // Unhide already escaped quotes
out = strings.ReplaceAll(out, `…`, `"`) // Replace field separator
out := strings.TrimSuffix(string(b), "†") // Trim last log separator
out = "[" + out + "]" // Wrap logs in json array
out = strings.ReplaceAll(out, "†\n", `,`) // Replace log separator with comma
out = strings.ReplaceAll(out, "\r", ``) // Drop carriage returns if any
out = strings.ReplaceAll(out, "\n", `\n`) // Escape new lines
out = strings.ReplaceAll(out, "\t", `\t`) // Escape tabs
out = strings.ReplaceAll(out, `\"`, `‰`) // Hide already escaped quotes
out = strings.ReplaceAll(out, `"`, `\"`) // Escape double quotes
out = strings.ReplaceAll(out, `‰`, `\"`) // Unhide already escaped quotes
out = strings.ReplaceAll(out, `…`, `"`) // Replace field separator
out = strings.ReplaceAll(out, "`\\`", "`\\\\`") // Edge case in which backticks are used in issue/PR names

Check warning on line 348 in testutil/genchangelog/main.go

View check run for this annotation

Codecov / codecov/patch

testutil/genchangelog/main.go#L338-L348

Added lines #L338 - L348 were not covered by tests

var logs []log
if err := json.Unmarshal([]byte(out), &logs); err != nil {
Expand Down Expand Up @@ -448,10 +449,11 @@ func getLatestTags(n int) ([]string, error) {
return nil, errors.Wrap(err, "git tag", z.Str("out", string(out)))
}

rawTags := strings.Fields(string(out))

Check warning on line 452 in testutil/genchangelog/main.go

View check run for this annotation

Codecov / codecov/patch

testutil/genchangelog/main.go#L452

Added line #L452 was not covered by tests
var tags []string

// filter out rc releases
for _, tag := range strings.Fields(string(out)) {
for _, tag := range rawTags {

Check warning on line 456 in testutil/genchangelog/main.go

View check run for this annotation

Codecov / codecov/patch

testutil/genchangelog/main.go#L456

Added line #L456 was not covered by tests
versionInfo, err := version.Parse(tag)
if err != nil {
return nil, errors.Wrap(err, "can't parse tag version")
Expand All @@ -464,10 +466,33 @@ func getLatestTags(n int) ([]string, error) {
tags = append(tags, tag)
}

ret := tags[len(tags)-n:]

latestTag, err := version.Parse(rawTags[len(rawTags)-1])
if err != nil {
return nil, errors.Wrap(err, "can't parse latest raw tag version")
}

Check warning on line 474 in testutil/genchangelog/main.go

View check run for this annotation

Codecov / codecov/patch

testutil/genchangelog/main.go#L469-L474

Added lines #L469 - L474 were not covered by tests

filteredLatestTag, err := version.Parse(ret[len(ret)-1])
if err != nil {
return nil, errors.Wrap(err, "can't parse latest filtered tag version")
}

Check warning on line 479 in testutil/genchangelog/main.go

View check run for this annotation

Codecov / codecov/patch

testutil/genchangelog/main.go#L476-L479

Added lines #L476 - L479 were not covered by tests

// we only do this check in a pre-release: edge case in which
// we released e.g. v0.18.0-rc1, and we want diff between that and last release.
if latestTag.PreRelease() {
if version.Compare(latestTag, filteredLatestTag) == 1 {
newRet := ret[1:]

newRet = append(newRet, latestTag.String())
ret = newRet
}

Check warning on line 489 in testutil/genchangelog/main.go

View check run for this annotation

Codecov / codecov/patch

testutil/genchangelog/main.go#L483-L489

Added lines #L483 - L489 were not covered by tests
}

if len(tags) < n {
return nil, errors.New("not enough tags", z.Int("expected", n), z.Int("available", len(tags)))
}

// return the latest N tags
return tags[len(tags)-n:], nil
return ret, nil

Check warning on line 497 in testutil/genchangelog/main.go

View check run for this annotation

Codecov / codecov/patch

testutil/genchangelog/main.go#L497

Added line #L497 was not covered by tests
}

0 comments on commit 492a45d

Please sign in to comment.