-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from gdams/announce_sort
publish-announcement: sort versions to be decreasing order
- Loading branch information
Showing
5 changed files
with
172 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
cmd/releasego/testdata/publish-announcement/2024-06-04-note.golden.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
post_title: Go 1.22.4-1, 1.22.4-1-fips, 1.21.11-1, and 1.21.11-1-fips Microsoft builds now available | ||
author1: Test Author | ||
post_slug: go-1-22-4-1--1-22-4-1-fips-1-21-11-1-and-1-21-11-1-fips-microsoft-builds-now-available | ||
categories: Microsoft for Go Developers | ||
tags: go, release | ||
featured_image: | ||
summary: The Microsoft builds of the Go security patches released today, are now available for download. | ||
--- | ||
|
||
A new set of Microsoft Go builds is now [available for download](https://github.com/microsoft/go#download-and-install). | ||
For more information about this release and the changes included, see the table below: | ||
|
||
| Microsoft Release | Upstream Tag | | ||
|-------------------|--------------| | ||
| [v1.22.4-1](https://github.com/microsoft/go/releases/tag/v1.22.4-1) | go1.22.4 [release notes](https://go.dev/doc/devel/release#go1.22.4) | | ||
| [v1.22.4-1-fips](https://github.com/microsoft/go/releases/tag/v1.22.4-1-fips) | go1.22.4 [release notes](https://go.dev/doc/devel/release#go1.22.4) | | ||
| [v1.21.11-1](https://github.com/microsoft/go/releases/tag/v1.21.11-1) | go1.21.11 [release notes](https://go.dev/doc/devel/release#go1.21.11) | | ||
| [v1.21.11-1-fips](https://github.com/microsoft/go/releases/tag/v1.21.11-1-fips) | go1.21.11 [release notes](https://go.dev/doc/devel/release#go1.21.11) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package infrasort | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/microsoft/go-infra/goversion" | ||
) | ||
|
||
// GoVersions implements [sort.Interface] and sorts versions in descending order. | ||
// If Major, Minor, Patch, or Revision of any GoVersion in the slice can't be parsed by | ||
// [strconv.Atoi], the result of using this type is undefined. | ||
type GoVersions []*goversion.GoVersion | ||
|
||
func (versions GoVersions) Len() int { return len(versions) } | ||
func (versions GoVersions) Swap(i, j int) { versions[i], versions[j] = versions[j], versions[i] } | ||
func (versions GoVersions) Less(i, j int) bool { | ||
less := func(a, b string) bool { | ||
intA, err := strconv.Atoi(a) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
intB, err := strconv.Atoi(b) | ||
if err != nil { | ||
return false | ||
} | ||
return intA > intB | ||
} | ||
|
||
current, next := versions[i], versions[j] | ||
|
||
if current.Major != next.Major { | ||
return less(current.Major, next.Major) | ||
} | ||
if current.Minor != next.Minor { | ||
return less(current.Minor, next.Minor) | ||
} | ||
if current.Patch != next.Patch { | ||
return less(current.Patch, next.Patch) | ||
} | ||
if current.Revision != next.Revision { | ||
return less(current.Revision, next.Revision) | ||
} | ||
if current.Prerelease != next.Prerelease { | ||
return current.Prerelease < next.Prerelease | ||
} | ||
if current.Note != next.Note { | ||
return current.Note < next.Note | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package infrasort | ||
|
||
import ( | ||
"sort" | ||
"testing" | ||
|
||
"github.com/microsoft/go-infra/goversion" | ||
) | ||
|
||
func TestGoVersions_Sort(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
versions GoVersions | ||
expected GoVersions | ||
}{ | ||
{ | ||
name: "basic version sorting", | ||
versions: GoVersions{ | ||
goversion.New("1.2.3"), | ||
goversion.New("1.2.1"), | ||
goversion.New("1.3.0"), | ||
goversion.New("1.2.3-2"), | ||
goversion.New("1.2.3-1"), | ||
}, | ||
expected: GoVersions{ | ||
goversion.New("1.3.0"), | ||
goversion.New("1.2.3-2"), | ||
goversion.New("1.2.3"), | ||
goversion.New("1.2.3-1"), | ||
goversion.New("1.2.1"), | ||
}, | ||
}, | ||
{ | ||
name: "version with prerelease and note", | ||
versions: GoVersions{ | ||
goversion.New("1.2.3-beta"), | ||
goversion.New("1.2.3-rc1"), | ||
goversion.New("1.2.3-1-fips"), | ||
goversion.New("1.2.3"), | ||
goversion.New("1.2.3-2"), | ||
}, | ||
expected: GoVersions{ | ||
goversion.New("1.2.3-2"), | ||
goversion.New("1.2.3"), | ||
goversion.New("1.2.3-beta"), | ||
goversion.New("1.2.3-1-fips"), | ||
goversion.New("1.2.3-rc1"), | ||
}, | ||
}, | ||
{ | ||
name: "sorting with major and minor versions", | ||
versions: GoVersions{ | ||
goversion.New("2.0.0"), | ||
goversion.New("1.10.0"), | ||
goversion.New("1.2.3"), | ||
goversion.New("1.2.0"), | ||
goversion.New("1.3.0"), | ||
}, | ||
expected: GoVersions{ | ||
goversion.New("2.0.0"), | ||
goversion.New("1.10.0"), | ||
goversion.New("1.3.0"), | ||
goversion.New("1.2.3"), | ||
goversion.New("1.2.0"), | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
// Sort the versions | ||
sort.Sort(tt.versions) | ||
for i, v := range tt.versions { | ||
if *v != *tt.expected[i] { | ||
t.Errorf("expected %v at index %d, got %v", tt.expected[i].Original, i, v.Original) | ||
} | ||
} | ||
}) | ||
} | ||
} |