Skip to content

Commit

Permalink
fix: limit the amount of minor to build
Browse files Browse the repository at this point in the history
Since we are limited to 256 job per run in a github workflow, we can't
keep building all the minor versions for every major.
This limit the amount of minor version to build to the 5 most recent
ones.
  • Loading branch information
eliecharra committed Nov 22, 2024
1 parent 4598802 commit d60053d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
7 changes: 6 additions & 1 deletion build-matrix/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
const (
// Define the oldest major version we care about, we do not want to build image starting ansible 1.0
minSupportedMajor = 7
// Numbed of latest minor release to keep building
maxSupportedMinor = 5
)

type ReleaseResponse struct {
Expand All @@ -38,6 +40,7 @@ type Matrix []matrixVersion
// - 10.1
// - 10.3
// - 10.4, additional_tags: 10
// We also only keep the latest 5 minor versions because we are limited to 256 jobs per workflow run
// Check main_test.go for a quick overview of the expected behavior.
func main() {
resp, err := http.Get("https://pypi.org/pypi/ansible/json")
Expand Down Expand Up @@ -87,7 +90,9 @@ func GenerateBuildMatrix(reader io.Reader, minSupportedMajor uint64) Matrix {
if _, exists := versionGroupedByMajor[major]; !exists {
majorVersions = append(majorVersions, major)
}
versionGroupedByMajor[major] = append(versionGroupedByMajor[major], version)
if len(versionGroupedByMajor[major]) < maxSupportedMinor {
versionGroupedByMajor[major] = append(versionGroupedByMajor[major], version)
}
}

sort.Sort(sort.Reverse(sort.IntSlice(majorVersions)))
Expand Down
20 changes: 18 additions & 2 deletions build-matrix/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func TestGenerateBuildMatrix(t *testing.T) {
"3.1.0": struct{}{},
"3.1.1": struct{}{},
"3.2.0": struct{}{},
"3.3.0": struct{}{},
"3.4.0": struct{}{},
"3.5.0": struct{}{},
"3.6.0": struct{}{},
},
}

Expand All @@ -29,11 +33,23 @@ func TestGenerateBuildMatrix(t *testing.T) {
matrix := GenerateBuildMatrix(bytes.NewReader(fakeJsonResponse), 2)
expectedMatrix := Matrix{
{
Ansible: "3.2",
Ansible: "3.6",
AdditionalTags: []string{"3"},
},
{
Ansible: "3.1",
Ansible: "3.5",
AdditionalTags: []string{},
},
{
Ansible: "3.4",
AdditionalTags: []string{},
},
{
Ansible: "3.3",
AdditionalTags: []string{},
},
{
Ansible: "3.2",
AdditionalTags: []string{},
},
{
Expand Down

0 comments on commit d60053d

Please sign in to comment.