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 eec918e
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 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 Down Expand Up @@ -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 eec918e

Please sign in to comment.