Skip to content

Commit

Permalink
fix(release): ensure the Docker image exists
Browse files Browse the repository at this point in the history
  • Loading branch information
zoncoen committed Apr 14, 2024
1 parent 4125e57 commit 3ca18f6
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions scripts/cross-build/cross-build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"os/exec"
"runtime"
"slices"
"strings"

"github.com/Masterminds/semver"
Expand All @@ -23,7 +24,7 @@ var (
ver = os.Getenv("GO_VERSION")
rootDir = os.Getenv("PJ_ROOT")
errImageNotFound = errors.New("image not found")
go1_21_0 = semver.MustParse("1.21.0")
go1_22_2 = semver.MustParse("1.22.2")
)

func main() {
Expand All @@ -47,8 +48,8 @@ func release() error {
if err != nil {
return fmt.Errorf("failed to parse version: %w", err)
}
cc := "aarch64-apple-darwin21.4-clang"
if v.GreaterThan(go1_21_0) {
cc := "aarch64-apple-darwin23-clang"
if v.LessThan(go1_22_2) {
cc = "aarch64-apple-darwin22-clang"
}

Expand All @@ -75,21 +76,36 @@ func imageTag(ver, token string) (string, error) {
}
return "", fmt.Errorf("unhandled error: %s", err.Error())
}

v := fmt.Sprintf("v%s", ver)
prefix := fmt.Sprintf("%s-", v)
var sv *semver.Version
tags := []*semver.Version{}
for _, node := range getTags.Repository.Refs.Nodes {
if node.Name == v || strings.HasPrefix(node.Name, prefix) {
return node.Name, nil
if node.Name == v {
sv = semver.MustParse(node.Name)
}
if strings.HasPrefix(node.Name, prefix) {
tags = append(tags, semver.MustParse(node.Name))
}
}
if strings.Count(v, ".") == 1 {
v := fmt.Sprintf("v%s.0", ver)
prefix := fmt.Sprintf("%s-", v)
for _, node := range getTags.Repository.Refs.Nodes {
if node.Name == v || strings.HasPrefix(node.Name, prefix) {
return node.Name, nil
}
slices.SortFunc(tags, func(a, b *semver.Version) int {
return -a.Compare(b)
})
if sv != nil {
tags = append(tags, sv)
}

for _, tag := range tags {
v := tag.Original()
if err := exec.Command(
"docker", "manifest", "inspect",
fmt.Sprintf("ghcr.io/gythialy/golang-cross:%s", v),
).Run(); err != nil {
fmt.Println(v, "not found")
continue
}
return v, nil
}

return "", errImageNotFound
Expand Down

0 comments on commit 3ca18f6

Please sign in to comment.