Skip to content

Commit

Permalink
Merge pull request #1401 from paketo-buildpacks/fix-rust
Browse files Browse the repository at this point in the history
Fix Rust Updater
  • Loading branch information
dmikusa authored Dec 15, 2023
2 parents dd552a9 + eb89b62 commit de20fd6
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions actions/rust-dependency/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2020 the original author or authors.
* Copyright 2018-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,8 +20,8 @@ import (
"context"
"fmt"
"net/http"
"strings"

"github.com/Masterminds/semver/v3"
"github.com/google/go-github/v43/github"
"golang.org/x/oauth2"

Expand Down Expand Up @@ -50,27 +50,41 @@ func main() {
versions := make(actions.Versions)
sources := actions.Outputs{}

// pull latest version
release, _, err := gh.Repositories.GetLatestRelease(context.Background(), ORG, REPO)
if err != nil {
panic(fmt.Errorf("unable to list existing tags for %s/%s\n%w", ORG, REPO, err))
}
// pull latest version tag
opt := &github.ListOptions{PerPage: 100}
for {
tags, rsp, err := gh.Repositories.ListTags(context.Background(), ORG, REPO, opt)
if err != nil {
panic(fmt.Errorf("unable to list existing tags for %s/%s\n%w", ORG, REPO, err))
}

originalVersion, err := semver.NewVersion(*release.TagName)
if err != nil {
panic(fmt.Errorf("unable to parse %s as semver\n%w", *release.TagName, err))
for _, t := range tags {
normalVersion, err := actions.NormalizeVersion(*t.Name)
if err != nil && strings.HasPrefix(err.Error(), "unable to parse") && strings.Contains(err.Error(), "as a extended version") {
fmt.Println("Skipping unrecognized tag", *t.Name, "as it does not match the expected pattern")
continue
} else if err != nil {
panic(fmt.Errorf("unable to normalize version [%s]\n%w", *t.Name, err))
}

versions[normalVersion] = fmt.Sprintf("https://static.rust-lang.org/dist/"+"rust-%s-%s.tar.gz", *t.Name, target)
}

if rsp.NextPage == 0 {
break
}
opt.Page = rsp.NextPage
}

normalVersion, err := actions.NormalizeVersion(*release.TagName)
latestVersion, err := versions.GetLatestVersion(inputs)
if err != nil {
panic(err)
panic(fmt.Errorf("unable to get latest version\n%w", err))
}
fmt.Println("fetch latest version as:", latestVersion)

versions[normalVersion] = fmt.Sprintf("https://static.rust-lang.org/dist/"+
"rust-%s-%s.tar.gz", normalVersion, target)
sources["source"] = fmt.Sprintf("https://static.rust-lang.org/dist/rustc-%s-src.tar.gz", normalVersion)
sources["source"] = fmt.Sprintf("https://static.rust-lang.org/dist/rustc-%s-src.tar.gz", latestVersion.Original())

o, err := actions.NewOutputs(versions[normalVersion], originalVersion, sources)
o, err := actions.NewOutputs(versions[latestVersion.Original()], latestVersion, sources)
if err != nil {
panic(err)
} else {
Expand Down

0 comments on commit de20fd6

Please sign in to comment.