Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds an action for fetching rust dependency updates #916

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}