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

reduce the list of cross build target #1282

Merged
merged 3 commits into from
Sep 12, 2021
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
timeout-minutes: 10
strategy:
matrix:
platform: [ubuntu-latest, windows-latest]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
Expand Down
50 changes: 48 additions & 2 deletions ci/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build mage
//go:build mage

package main

Expand All @@ -7,13 +7,34 @@ import (
"fmt"
"os"
"path"
"sort"

"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)

func intersect(a, b []string) []string {
sort.Strings(a)
sort.Strings(b)

res := make([]string, 0, func() int {
if len(a) < len(b) {
return len(a)
}
return len(b)
}())

for _, v := range a {
idx := sort.SearchStrings(b, v)
if idx < len(b) && b[idx] == v {
res = append(res, v)
}
}
return res
}

// getBuildMatrix returns the build matrix from the current version of the go compiler
func getBuildMatrix() (map[string][]string, error) {
func getFullBuildMatrix() (map[string][]string, error) {
jsonData, err := sh.Output("go", "tool", "dist", "list", "-json")
if err != nil {
return nil, err
Expand All @@ -38,6 +59,31 @@ func getBuildMatrix() (map[string][]string, error) {
return matrix, nil
}

func getBuildMatrix() (map[string][]string, error) {
minimalMatrix := map[string][]string{
"linux": []string{"amd64"},
"darwin": []string{"amd64", "arm64"},
"freebsd": []string{"amd64"},
"js": []string{"wasm"},
"solaris": []string{"amd64"},
"windows": []string{"amd64", "arm64"},
}

fullMatrix, err := getFullBuildMatrix()
if err != nil {
return nil, err
}

for os, arches := range minimalMatrix {
if fullV, ok := fullMatrix[os]; !ok {
delete(minimalMatrix, os)
} else {
minimalMatrix[os] = intersect(arches, fullV)
}
}
return minimalMatrix, nil
}

func CrossBuild() error {
matrix, err := getBuildMatrix()
if err != nil {
Expand Down