Skip to content
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
3 changes: 2 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ jobs:
- name: Set GORELEASER_PREVIOUS_TAG # Workaround, GoReleaser uses 'git-describe' to determine a previous tag. Our tags are created in release branches.
run: |
set -xue
echo "GORELEASER_PREVIOUS_TAG=$(go run hack/get-previous-release/get-previous-version-for-release-notes.go ${{ github.ref_name }})" >> $GITHUB_ENV
GORELEASER_PREVIOUS_TAG=$(go run hack/get-previous-release/get-previous-version-for-release-notes.go ${{ github.ref_name }}) || exit 1
echo "GORELEASER_PREVIOUS_TAG=$GORELEASER_PREVIOUS_TAG" >> $GITHUB_ENV

- name: Set environment variables for ldflags
id: set_ldflag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"
"os/exec"
"regexp"
"strconv"
"strings"
)

Expand Down Expand Up @@ -54,56 +53,45 @@ func extractPatchAndRC(tag string) (string, string, error) {

func findPreviousTag(proposedTag string, tags []string) (string, error) {
var previousTag string
proposedMajor := semver.Major(proposedTag)
proposedMinor := semver.MajorMinor(proposedTag)

proposedPatch, proposedRC, err := extractPatchAndRC(proposedTag)
if err != nil {
return "", err
}

// If the current tag is a .0 patch release or a 1 release candidate, adjust to the previous minor release series.
if (proposedPatch == "0" && proposedRC == "0") || proposedRC == "1" {
proposedMinorInt, err := strconv.Atoi(strings.TrimPrefix(proposedMinor, proposedMajor+"."))
if err != nil {
return "", fmt.Errorf("invalid minor version: %v", err)
}
if proposedMinorInt > 0 {
proposedMinor = fmt.Sprintf("%s.%d", proposedMajor, proposedMinorInt-1)
for _, tag := range tags {
// If this tag is newer than the proposed tag, skip it.
if semver.Compare(tag, proposedTag) > 0 {
continue
}
}

for _, tag := range tags {
if tag == proposedTag {
// If this tag is older than a tag we've already decided is a candidate, skip it.
if semver.Compare(tag, previousTag) <= 0 {
continue
}
tagMajor := semver.Major(tag)
tagMinor := semver.MajorMinor(tag)
tagPatch, tagRC, err := extractPatchAndRC(tag)
if err != nil {
continue
}

// Only bother considering tags with the same major and minor version.
if tagMajor == proposedMajor && tagMinor == proposedMinor {
// If it's a non-RC release...
if proposedRC == "0" {
// Only consider non-RC tags.
if tagRC == "0" {
if semver.Compare(tag, previousTag) > 0 {
previousTag = tag
}
// If it's a non-RC release...
if proposedRC == "0" {
if proposedPatch == "0" {
// ...and we're cutting the first patch of a new minor release series, don't consider tags in the same
// minor release series.
if semver.MajorMinor(tag) != proposedMinor {
previousTag = tag
}
} else {
if tagRC != "0" && tagPatch == proposedPatch {
if semver.Compare(tag, previousTag) > 0 {
previousTag = tag
}
} else if tagRC == "0" {
if semver.Compare(tag, previousTag) > 0 {
previousTag = tag
}
}

previousTag = tag
}
} else {
if tagRC != "0" && tagPatch == proposedPatch {
previousTag = tag
} else if tagRC == "0" {
previousTag = tag
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ func TestFindPreviousTagRules(t *testing.T) {
{"Rule 3: 1 release candidate", "v2.14.0-rc1", "v2.13.0-rc3", false},
// Rule 4: If we're releasing a non-1 release candidate, get the most recent rc tag on the current minor release series.
{"Rule 4: non-1 release candidate", "v2.13.0-rc4", "v2.13.0-rc3", false},
// Rule 5: If we're releasing a major version RC, get the most recent tag on the previous major release series.
{"Rule 5: major version RC", "v3.0.0-rc1", "v2.13.0-rc3", false},
// Rule 6: If we're releasing a major version, get the most recent tag on the previous major release series,
// even if it's an RC.
{"Rule 6: major version", "v3.0.0", "v2.13.0-rc3", false},
}

for _, test := range tests {
Expand Down
Loading