diff --git a/carton/buildpack_dependency.go b/carton/buildpack_dependency.go index b2ef05b..f165e2b 100644 --- a/carton/buildpack_dependency.go +++ b/carton/buildpack_dependency.go @@ -35,6 +35,7 @@ const ( type BuildpackDependency struct { BuildpackPath string ID string + Arch string SHA256 string URI string Version string @@ -58,6 +59,7 @@ func (b BuildpackDependency) Update(options ...Option) { logger := bard.NewLogger(os.Stdout) _, _ = fmt.Fprintf(logger.TitleWriter(), "\n%s\n", bard.FormatIdentity(b.ID, b.VersionPattern)) + logger.Headerf("Arch: %s", b.Arch) logger.Headerf("Version: %s", b.Version) logger.Headerf("PURL: %s", b.PURL) logger.Headerf("CPEs: %s", b.CPE) @@ -141,7 +143,21 @@ func (b BuildpackDependency) Update(options ...Option) { continue } - if depId == b.ID { + // extract the arch from the PURL, it's the only place it lives consistently at the moment + var depArch string + purlUnwrapped, found := dep["purl"] + if found { + purl, ok := purlUnwrapped.(string) + if ok { + purlArchExp := regexp.MustCompile(`arch=(.*)`) + purlArchMatches := purlArchExp.FindStringSubmatch(purl) + if len(purlArchMatches) == 2 { + depArch = purlArchMatches[1] + } + } + } + + if depId == b.ID && depArch == b.Arch { depVersionUnwrapped, found := dep["version"] if !found { continue @@ -151,6 +167,7 @@ func (b BuildpackDependency) Update(options ...Option) { if !ok { continue } + if versionExp.MatchString(depVersion) { dep["version"] = b.Version dep["uri"] = b.URI diff --git a/cmd/update-buildpack-dependency/main.go b/cmd/update-buildpack-dependency/main.go index 4fcabe5..4645c5b 100644 --- a/cmd/update-buildpack-dependency/main.go +++ b/cmd/update-buildpack-dependency/main.go @@ -32,6 +32,7 @@ func main() { flagSet := pflag.NewFlagSet("Update Buildpack Dependency", pflag.ExitOnError) flagSet.StringVar(&b.BuildpackPath, "buildpack-toml", "", "path to buildpack.toml") flagSet.StringVar(&b.ID, "id", "", "the id of the dependency") + flagSet.StringVar(&b.Arch, "arch", "", "the arch of the dependency") flagSet.StringVar(&b.SHA256, "sha256", "", "the new sha256 of the dependency") flagSet.StringVar(&b.URI, "uri", "", "the new uri of the dependency") flagSet.StringVar(&b.Version, "version", "", "the new version of the dependency") @@ -55,6 +56,10 @@ func main() { log.Fatal("id must be set") } + if b.Arch == "" { + b.Arch = "amd64" + } + if b.SHA256 == "" { log.Fatal("sha256 must be set") }