Skip to content

Commit

Permalink
Merge pull request #916 from paketo-buildpacks/add-rust-action
Browse files Browse the repository at this point in the history
Adds an action for fetching rust dependency updates
  • Loading branch information
dmikusa authored Nov 23, 2022
2 parents 744d77d + f9dfefb commit 5b6fa21
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ The Pipeline Builder is a collection of tools related to GitHub Actions and othe
- [Paketo Deps Dependency](#paketo-deps-dependency)
- [Aternity Dependency](#aternity-dependency)
- [Rustup Init Dependency](#rustup-init-dependency)
- [Rust Dependency](#rust-dependency)
- [Skywalking Dependency](#skywalking-dependency)
- [Spring Generations](#spring-generations)
- [Tomcat Dependency](#tomcat-dependency)
Expand Down Expand Up @@ -631,6 +632,16 @@ with:
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
```

### Rust Dependency
The Rust Dependency queries the [Rust Github Project](https://github.com/rust-lang/rust) for the latest version. The `target` specifies the target triple to download.

```yaml
uses: docker://ghcr.io/paketo-buildpacks/actions/rust-dependency:main
with:
target: x86_64-unknown-linux-gnu
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
```

### Skywalking Dependency
The Skywalking Dependency watches the [Apache Skywalking Download Page](https://downloads.apache.org/skywalking) for new versions.

Expand Down
71 changes: 71 additions & 0 deletions actions/rust-dependency/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2018-2020 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package main

import (
"context"
"fmt"
"net/http"
"os"

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

"github.com/paketo-buildpacks/pipeline-builder/actions"
)

const (
ORG = "rust-lang"
REPO = "rust"
)

func main() {
inputs := actions.NewInputs()

target, ok := inputs["target"]
if !ok {
panic(fmt.Errorf("target must be specified"))
}

var c *http.Client
if s, ok := inputs["token"]; ok {
c = oauth2.NewClient(context.Background(), oauth2.StaticTokenSource(&oauth2.Token{AccessToken: s}))
}
gh := github.NewClient(c)

versions := make(actions.Versions)

// 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))
}

normalVersion, err := actions.NormalizeVersion(*release.TagName)
if err != nil {
panic(err)
}

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

if o, err := versions.GetLatest(inputs); err != nil {
panic(err)
} else {
o.Write(os.Stdout)
}
}

0 comments on commit 5b6fa21

Please sign in to comment.